diff options
author | Alexander Færøy <ahf@torproject.org> | 2018-12-18 15:18:22 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-18 13:35:29 -0500 |
commit | ca7a2ecc512145589964577f2f2ff6133ab146f5 (patch) | |
tree | cf61c8df2321c1e8a1e5b25d246acc55f3b1372f /src/test/test_process_slow.c | |
parent | 8a01f0eaabe8d5975b12328a745d2a6e921ef868 (diff) | |
download | tor-ca7a2ecc512145589964577f2f2ff6133ab146f5.tar.gz tor-ca7a2ecc512145589964577f2f2ff6133ab146f5.zip |
Avoid breaking the event loop prematurely.
This patch makes sure that we terminate the event loop from the event
loop timer instead of directly in the process' exit handler. This allows
us to run the event loop an additional time to ensure that the SleepEx()
call on Windows is called and the data from stdout/stderr is delivered
to us.
Additionally we ensure that we don't try to read or write data from a
Unix process that have been terminated in the main loop, since its file
descriptors are closed at that time.
See: https://bugs.torproject.org/28179
Diffstat (limited to 'src/test/test_process_slow.c')
-rw-r--r-- | src/test/test_process_slow.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/test/test_process_slow.c b/src/test/test_process_slow.c index cc7e8c5a9c..a1f99bff0f 100644 --- a/src/test/test_process_slow.c +++ b/src/test/test_process_slow.c @@ -36,6 +36,7 @@ struct process_data_t { smartlist_t *stderr_data; smartlist_t *stdin_data; process_exit_code_t exit_code; + bool did_exit; }; typedef struct process_data_t process_data_t; @@ -97,13 +98,17 @@ process_stderr_callback(process_t *process, const char *data, size_t size) static bool process_exit_callback(process_t *process, process_exit_code_t exit_code) { + process_status_t status; + tt_ptr_op(process, OP_NE, NULL); process_data_t *process_data = process_get_data(process); process_data->exit_code = exit_code; + process_data->did_exit = true; - /* Our process died. Let's check the values it returned. */ - tor_shutdown_event_loop_and_exit(0); + /* Check if our process is still running? */ + status = process_get_status(process); + tt_int_op(status, OP_EQ, PROCESS_STATUS_NOT_RUNNING); done: /* Do not free up our process_t. */ @@ -137,9 +142,16 @@ main_loop_timeout_cb(periodic_timer_t *timer, void *data) { /* Sanity check. */ tt_ptr_op(timer, OP_EQ, main_loop_timeout_timer); - tt_ptr_op(data, OP_EQ, NULL); + tt_ptr_op(data, OP_NE, NULL); + + /* Our process data. */ + process_data_t *process_data = data; + + /* Our process did exit. */ + if (process_data->did_exit) + tor_shutdown_event_loop_and_exit(0); - /* Have we been called 10 times we exit. */ + /* Have we been called 10 times we exit the main loop. */ timer_tick_count++; tt_int_op(timer_tick_count, OP_LT, 10); @@ -156,7 +168,7 @@ main_loop_timeout_cb(periodic_timer_t *timer, void *data) } static void -run_main_loop(void) +run_main_loop(process_data_t *process_data) { int ret; @@ -167,7 +179,7 @@ run_main_loop(void) main_loop_timeout_timer = periodic_timer_new(tor_libevent_get_base(), &interval, main_loop_timeout_cb, - NULL); + process_data); /* Run our main loop. */ ret = run_main_loop_until_done(); @@ -225,11 +237,7 @@ test_callbacks(void *arg) process_printf(process, " lines?\r\n"); /* Start our main loop. */ - run_main_loop(); - - /* Check if our process is still running? */ - status = process_get_status(process); - tt_int_op(status, OP_EQ, PROCESS_STATUS_NOT_RUNNING); + run_main_loop(process_data); /* We returned. Let's see what our event loop said. */ tt_int_op(smartlist_len(process_data->stdout_data), OP_EQ, 12); @@ -310,14 +318,16 @@ test_callbacks_terminate(void *arg) tt_int_op(status, OP_EQ, PROCESS_STATUS_RUNNING); /* Zap our process. */ - process_terminate(process); + bool success; + + success = process_terminate(process); + tt_assert(success); /* Start our main loop. */ - run_main_loop(); + run_main_loop(process_data); - /* Check if our process is still running? */ - status = process_get_status(process); - tt_int_op(status, OP_EQ, PROCESS_STATUS_NOT_RUNNING); + /* Check if we did exit. */ + tt_assert(process_data->did_exit); done: process_data_free(process_data); |