diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | changes/ticket28847 | 3 | ||||
-rw-r--r-- | configure.ac | 38 | ||||
-rw-r--r-- | src/app/main/main.c | 5 | ||||
-rw-r--r-- | src/app/main/subsystem_list.c | 7 | ||||
-rw-r--r-- | src/core/or/ocirc_event.c | 2 | ||||
-rw-r--r-- | src/core/or/orconn_event.c | 2 | ||||
-rw-r--r-- | src/lib/process/include.am | 2 | ||||
-rw-r--r-- | src/lib/process/process.h | 9 | ||||
-rw-r--r-- | src/lib/process/process_sys.c | 33 | ||||
-rw-r--r-- | src/lib/process/process_sys.h | 14 | ||||
-rw-r--r-- | src/lib/time/time_sys.h | 2 | ||||
-rw-r--r-- | src/test/test_process.c | 27 | ||||
-rw-r--r-- | src/test/test_process_slow.c | 8 | ||||
-rw-r--r-- | src/test/test_pt.c | 9 | ||||
-rw-r--r-- | warning_flags.in | 1 |
16 files changed, 99 insertions, 66 deletions
diff --git a/.gitignore b/.gitignore index b73c5b9ab5..6a49285b8a 100644 --- a/.gitignore +++ b/.gitignore @@ -72,9 +72,12 @@ uptime-*.json /mkinstalldirs /Tor*Bundle.dmg /tor-*-win32.exe +/warning_flags + /coverage_html/ /callgraph/ + # /contrib/ /contrib/dist/tor.sh /contrib/dist/torctl diff --git a/changes/ticket28847 b/changes/ticket28847 new file mode 100644 index 0000000000..63100c5813 --- /dev/null +++ b/changes/ticket28847 @@ -0,0 +1,3 @@ + o Minor features (process): + - Use the subsystem module to initialize and shut down the process module. + Closes ticket 28847. diff --git a/configure.ac b/configure.ac index 7f0d375440..76fc12be50 100644 --- a/configure.ac +++ b/configure.ac @@ -2129,6 +2129,8 @@ case "$host_os" in LDFLAGS="$LDFLAGS -dead_strip" ;; esac +TOR_WARNING_FLAGS="" + # Add some more warnings which we use in development but not in the # released versions. (Some relevant gcc versions can't handle these.) # @@ -2146,6 +2148,8 @@ if test "x$enable_gcc_warnings_advisory" != "xno"; then CFLAGS="$CFLAGS -Wno-system-headers" ;; esac + CFLAGS_NOWARNINGS="$CFLAGS" + # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users # have it work better. # CFLAGS="$CFLAGS -Wstrict-overflow=1" @@ -2361,7 +2365,9 @@ if test "x$enable_gcc_warnings_advisory" != "xno"; then -Wvisibility -Wvla-extension -Wzero-length-array - ], [ TOR_CHECK_CFLAGS([warning_flag]) ]) + ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [], + [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true) + ]) dnl We should re-enable this in some later version. Clang doesn't dnl mind, but it causes trouble with GCC. @@ -2375,16 +2381,19 @@ dnl -Wthread-safety-attributes dnl -Wthread-safety-beta dnl -Wthread-safety-precise - CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith" - CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings" - CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2" - CFLAGS="$CFLAGS -Wwrite-strings" - CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum" - CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused" - CFLAGS="$CFLAGS -Wunused-parameter " + W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith" + W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings" + W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2" + W_FLAGS="$W_FLAGS -Wwrite-strings" + W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum" + W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused" + W_FLAGS="$W_FLAGS -Wunused-parameter " # These interfere with building main() { return 0; }, which autoconf # likes to use as its default program. - CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-declarations" + W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations" + + TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS" + CFLAGS="$CFLAGS $W_FLAGS" if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference]) @@ -2396,6 +2405,8 @@ dnl -Wthread-safety-precise AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable]) fi + CFLAGS="$CFLAGS_NOWARNINGS" + if test "x$enable_fatal_warnings" = "xyes"; then # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the # default autoconf programs are full of errors. @@ -2404,6 +2415,14 @@ dnl -Wthread-safety-precise fi +AC_SUBST(TOR_WARNING_FLAGS) + +echo "$TOR_WARNING_FLAGS">warning_flags + +TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [], + CFLAGS="$CFLAGS @warning_flags", + CFLAGS="$CFLAGS $TOR_WARNING_FLAGS") + if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then case "$host_os" in darwin*) @@ -2426,6 +2445,7 @@ AC_CONFIG_FILES([ src/config/torrc.minimal src/rust/.cargo/config scripts/maint/checkOptionDocs.pl + warning_flags ]) if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then diff --git a/src/app/main/main.c b/src/app/main/main.c index aa322046fe..d71e43ec30 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -74,7 +74,6 @@ #include "lib/net/resolve.h" #include "lib/process/waitpid.h" -#include "lib/process/process.h" #include "lib/meminfo/meminfo.h" #include "lib/osinfo/uname.h" @@ -560,9 +559,6 @@ tor_init(int argc, char *argv[]) addressmap_init(); /* Init the client dns cache. Do it always, since it's * cheap. */ - /* Initialize Process subsystem. */ - process_init(); - /* Initialize the HS subsystem. */ hs_init(); @@ -790,7 +786,6 @@ tor_free_all(int postfork) circuitmux_ewma_free_all(); accounting_free_all(); protover_summary_cache_free_all(); - process_free_all(); if (!postfork) { config_free_all(); diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c index 2f2586ac15..9f9bf10866 100644 --- a/src/app/main/subsystem_list.c +++ b/src/app/main/subsystem_list.c @@ -21,6 +21,7 @@ #include "lib/time/time_sys.h" #include "lib/tls/tortls_sys.h" #include "lib/wallclock/wallclock_sys.h" +#include "lib/process/process_sys.h" #include <stddef.h> @@ -38,8 +39,10 @@ const subsys_fns_t *tor_subsystems[] = { &sys_compress, /* -70 */ &sys_crypto, /* -60 */ &sys_tortls, /* -50 */ - &sys_orconn_event, /* -40 */ - &sys_ocirc_event, /* -39 */ + &sys_process, /* -35 */ + + &sys_orconn_event, /* -33 */ + &sys_ocirc_event, /* -32 */ &sys_btrack, /* -30 */ }; diff --git a/src/core/or/ocirc_event.c b/src/core/or/ocirc_event.c index f9f8af279f..b400022bb7 100644 --- a/src/core/or/ocirc_event.c +++ b/src/core/or/ocirc_event.c @@ -78,7 +78,7 @@ ocirc_event_publish(const ocirc_event_msg_t *msg) const subsys_fns_t sys_ocirc_event = { .name = "ocirc_event", .supported = true, - .level = -39, + .level = -32, .initialize = ocirc_event_init, .shutdown = ocirc_event_fini, }; diff --git a/src/core/or/orconn_event.c b/src/core/or/orconn_event.c index 11f5ed9662..d81f7b5a0c 100644 --- a/src/core/or/orconn_event.c +++ b/src/core/or/orconn_event.c @@ -75,7 +75,7 @@ orconn_event_publish(const orconn_event_msg_t *msg) const subsys_fns_t sys_orconn_event = { .name = "orconn_event", .supported = true, - .level = -40, + .level = -33, .initialize = orconn_event_init, .shutdown = orconn_event_fini, }; diff --git a/src/lib/process/include.am b/src/lib/process/include.am index a2d54b6238..83b67bf029 100644 --- a/src/lib/process/include.am +++ b/src/lib/process/include.am @@ -10,6 +10,7 @@ src_lib_libtor_process_a_SOURCES = \ src/lib/process/env.c \ src/lib/process/pidfile.c \ src/lib/process/process.c \ + src/lib/process/process_sys.c \ src/lib/process/process_unix.c \ src/lib/process/process_win32.c \ src/lib/process/restrict.c \ @@ -27,6 +28,7 @@ noinst_HEADERS += \ src/lib/process/env.h \ src/lib/process/pidfile.h \ src/lib/process/process.h \ + src/lib/process/process_sys.h \ src/lib/process/process_unix.h \ src/lib/process/process_win32.h \ src/lib/process/restrict.h \ diff --git a/src/lib/process/process.h b/src/lib/process/process.h index 179db19aeb..956d34ab29 100644 --- a/src/lib/process/process.h +++ b/src/lib/process/process.h @@ -47,6 +47,8 @@ const char *process_protocol_to_string(process_protocol_t protocol); void tor_disable_spawning_background_processes(void); +struct smartlist_t; + struct process_t; typedef struct process_t process_t; @@ -61,7 +63,7 @@ typedef bool void process_init(void); void process_free_all(void); -const smartlist_t *process_get_all_processes(void); +const struct smartlist_t *process_get_all_processes(void); process_t *process_new(const char *command); void process_free_(process_t *process); @@ -82,10 +84,11 @@ void process_set_exit_callback(process_t *, const char *process_get_command(const process_t *process); void process_append_argument(process_t *process, const char *argument); -const smartlist_t *process_get_arguments(const process_t *process); +const struct smartlist_t *process_get_arguments(const process_t *process); char **process_get_argv(const process_t *process); -void process_reset_environment(process_t *process, const smartlist_t *env); +void process_reset_environment(process_t *process, + const struct smartlist_t *env); void process_set_environment(process_t *process, const char *key, const char *value); diff --git a/src/lib/process/process_sys.c b/src/lib/process/process_sys.c new file mode 100644 index 0000000000..d0a94f35f7 --- /dev/null +++ b/src/lib/process/process_sys.c @@ -0,0 +1,33 @@ +/* Copyright (c) 2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file process_sys.c + * \brief Subsystem object for process setup. + **/ + +#include "orconfig.h" +#include "lib/subsys/subsys.h" +#include "lib/process/process_sys.h" +#include "lib/process/process.h" + +static int +subsys_process_initialize(void) +{ + process_init(); + return 0; +} + +static void +subsys_process_shutdown(void) +{ + process_free_all(); +} + +const subsys_fns_t sys_process = { + .name = "process", + .level = -35, + .supported = true, + .initialize = subsys_process_initialize, + .shutdown = subsys_process_shutdown +}; diff --git a/src/lib/process/process_sys.h b/src/lib/process/process_sys.h new file mode 100644 index 0000000000..b299334b6b --- /dev/null +++ b/src/lib/process/process_sys.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2018, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file process_sys.h + * \brief Declare subsystem object for the process module. + **/ + +#ifndef TOR_PROCESS_SYS_H +#define TOR_PROCESS_SYS_H + +extern const struct subsys_fns_t sys_process; + +#endif /* !defined(TOR_PROCESS_SYS_H) */ diff --git a/src/lib/time/time_sys.h b/src/lib/time/time_sys.h index 0f1aebc268..5f5982a33b 100644 --- a/src/lib/time/time_sys.h +++ b/src/lib/time/time_sys.h @@ -2,7 +2,7 @@ /* See LICENSE for licensing information */ /** - * \file log_time.h + * \file time_sys.h * \brief Declare subsystem object for the time module. **/ diff --git a/src/test/test_process.c b/src/test/test_process.c index 9b62862f04..27c9935e0d 100644 --- a/src/test/test_process.c +++ b/src/test/test_process.c @@ -142,8 +142,6 @@ static void test_default_values(void *arg) { (void)arg; - process_init(); - process_t *process = process_new("/path/to/nothing"); /* We are not running by default. */ @@ -171,14 +169,12 @@ test_default_values(void *arg) done: process_free(process); - process_free_all(); } static void test_environment(void *arg) { (void)arg; - process_init(); process_t *process = process_new(""); process_environment_t *env = NULL; @@ -221,7 +217,6 @@ test_environment(void *arg) done: process_environment_free(env); process_free(process); - process_free_all(); } static void @@ -249,7 +244,6 @@ static void test_line_protocol_simple(void *arg) { (void)arg; - process_init(); process_data_t *process_data = process_data_new(); @@ -289,7 +283,6 @@ test_line_protocol_simple(void *arg) done: process_data_free(process_data); process_free(process); - process_free_all(); UNMOCK(process_read_stdout); UNMOCK(process_read_stderr); @@ -299,7 +292,6 @@ static void test_line_protocol_multi(void *arg) { (void)arg; - process_init(); process_data_t *process_data = process_data_new(); @@ -349,7 +341,6 @@ test_line_protocol_multi(void *arg) done: process_data_free(process_data); process_free(process); - process_free_all(); UNMOCK(process_read_stdout); UNMOCK(process_read_stderr); @@ -359,7 +350,6 @@ static void test_line_protocol_partial(void *arg) { (void)arg; - process_init(); process_data_t *process_data = process_data_new(); @@ -431,7 +421,6 @@ test_line_protocol_partial(void *arg) done: process_data_free(process_data); process_free(process); - process_free_all(); UNMOCK(process_read_stdout); UNMOCK(process_read_stderr); @@ -441,7 +430,6 @@ static void test_raw_protocol_simple(void *arg) { (void)arg; - process_init(); process_data_t *process_data = process_data_new(); @@ -499,7 +487,6 @@ test_raw_protocol_simple(void *arg) done: process_data_free(process_data); process_free(process); - process_free_all(); UNMOCK(process_read_stdout); UNMOCK(process_read_stderr); @@ -510,8 +497,6 @@ test_write_simple(void *arg) { (void)arg; - process_init(); - process_data_t *process_data = process_data_new(); process_t *process = process_new(""); @@ -530,7 +515,6 @@ test_write_simple(void *arg) done: process_data_free(process_data); process_free(process); - process_free_all(); UNMOCK(process_write_stdin); } @@ -540,8 +524,6 @@ test_exit_simple(void *arg) { (void)arg; - process_init(); - process_data_t *process_data = process_data_new(); process_t *process = process_new(""); @@ -566,14 +548,12 @@ test_exit_simple(void *arg) process_set_data(process, process_data); process_data_free(process_data); process_free(process); - process_free_all(); } static void test_argv_simple(void *arg) { (void)arg; - process_init(); process_t *process = process_new("/bin/cat"); char **argv = NULL; @@ -600,7 +580,6 @@ test_argv_simple(void *arg) done: tor_free(argv); process_free(process); - process_free_all(); } static void @@ -608,8 +587,6 @@ test_unix(void *arg) { (void)arg; #ifndef _WIN32 - process_init(); - process_t *process = process_new(""); /* On Unix all processes should have a Unix process handle. */ @@ -617,7 +594,6 @@ test_unix(void *arg) done: process_free(process); - process_free_all(); #endif } @@ -626,8 +602,6 @@ test_win32(void *arg) { (void)arg; #ifdef _WIN32 - process_init(); - process_t *process = process_new(""); char *joined_argv = NULL; @@ -675,7 +649,6 @@ test_win32(void *arg) done: tor_free(joined_argv); process_free(process); - process_free_all(); #endif } diff --git a/src/test/test_process_slow.c b/src/test/test_process_slow.c index 3f8c07f312..c28ade033c 100644 --- a/src/test/test_process_slow.c +++ b/src/test/test_process_slow.c @@ -203,9 +203,6 @@ test_callbacks(void *arg) filename = TEST_PROCESS; #endif - /* Initialize Process subsystem. */ - process_init(); - /* Process callback data. */ process_data_t *process_data = process_data_new(); @@ -286,7 +283,6 @@ test_callbacks(void *arg) done: process_data_free(process_data); process_free(process); - process_free_all(); } static void @@ -301,9 +297,6 @@ test_callbacks_terminate(void *arg) filename = TEST_PROCESS; #endif - /* Initialize Process subsystem. */ - process_init(); - /* Process callback data. */ process_data_t *process_data = process_data_new(); @@ -333,7 +326,6 @@ test_callbacks_terminate(void *arg) done: process_data_free(process_data); process_free(process); - process_free_all(); } struct testcase_t slow_process_tests[] = { diff --git a/src/test/test_pt.c b/src/test/test_pt.c index 8de687c866..60a044aeca 100644 --- a/src/test/test_pt.c +++ b/src/test/test_pt.c @@ -151,8 +151,6 @@ test_pt_get_transport_options(void *arg) config_line_t *cl = NULL; (void)arg; - process_init(); - execve_args = tor_malloc(sizeof(char*)*2); execve_args[0] = tor_strdup("cheeseshop"); execve_args[1] = NULL; @@ -192,7 +190,6 @@ test_pt_get_transport_options(void *arg) config_free_lines(cl); managed_proxy_destroy(mp, 0); smartlist_free(transport_list); - process_free_all(); } static void @@ -256,8 +253,6 @@ test_pt_get_extrainfo_string(void *arg) char *s = NULL; (void) arg; - process_init(); - argv1 = tor_malloc_zero(sizeof(char*)*3); argv1[0] = tor_strdup("ewige"); argv1[1] = tor_strdup("Blumenkraft"); @@ -291,7 +286,6 @@ test_pt_get_extrainfo_string(void *arg) smartlist_free(t1); smartlist_free(t2); tor_free(s); - process_free_all(); } static int @@ -355,8 +349,6 @@ test_pt_configure_proxy(void *arg) managed_proxy_t *mp = NULL; (void) arg; - process_init(); - dummy_state = tor_malloc_zero(sizeof(or_state_t)); MOCK(process_read_stdout, process_read_stdout_replacement); @@ -501,7 +493,6 @@ test_pt_configure_proxy(void *arg) tor_free(mp->argv[0]); tor_free(mp->argv); tor_free(mp); - process_free_all(); } /* Test the get_pt_proxy_uri() function. */ diff --git a/warning_flags.in b/warning_flags.in new file mode 100644 index 0000000000..e8ebe6e9a4 --- /dev/null +++ b/warning_flags.in @@ -0,0 +1 @@ +@TOR_WARNING_FLAGS@
\ No newline at end of file |