aboutsummaryrefslogtreecommitdiff
path: root/src/lib/process/process_unix.c
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2018-12-18 15:18:22 +0100
committerNick Mathewson <nickm@torproject.org>2018-12-18 13:35:29 -0500
commitca7a2ecc512145589964577f2f2ff6133ab146f5 (patch)
treecf61c8df2321c1e8a1e5b25d246acc55f3b1372f /src/lib/process/process_unix.c
parent8a01f0eaabe8d5975b12328a745d2a6e921ef868 (diff)
downloadtor-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/lib/process/process_unix.c')
-rw-r--r--src/lib/process/process_unix.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/lib/process/process_unix.c b/src/lib/process/process_unix.c
index 4fc1b7a519..57ca69a768 100644
--- a/src/lib/process/process_unix.c
+++ b/src/lib/process/process_unix.c
@@ -112,16 +112,6 @@ process_unix_free_(process_unix_t *unix_process)
/* FIXME(ahf): Refactor waitpid code? */
unix_process->waitpid = NULL;
- /* Cleanup our events. */
- if (! unix_process->stdout_handle.reached_eof)
- process_unix_stop_reading(&unix_process->stdout_handle);
-
- if (! unix_process->stderr_handle.reached_eof)
- process_unix_stop_reading(&unix_process->stderr_handle);
-
- if (unix_process->stdin_handle.is_writing)
- process_unix_stop_writing(&unix_process->stdin_handle);
-
/* Close all our file descriptors. */
process_unix_close_file_descriptors(unix_process);
@@ -668,6 +658,17 @@ process_unix_close_file_descriptors(process_unix_t *unix_process)
int ret;
bool success = true;
+ /* Stop reading and writing before we close() our
+ * file descriptors. */
+ if (! unix_process->stdout_handle.reached_eof)
+ process_unix_stop_reading(&unix_process->stdout_handle);
+
+ if (! unix_process->stderr_handle.reached_eof)
+ process_unix_stop_reading(&unix_process->stderr_handle);
+
+ if (unix_process->stdin_handle.is_writing)
+ process_unix_stop_writing(&unix_process->stdin_handle);
+
if (unix_process->stdin_handle.fd != -1) {
ret = close(unix_process->stdin_handle.fd);
if (ret == -1) {