aboutsummaryrefslogtreecommitdiff
path: root/src/lib/process
AgeCommit message (Collapse)Author
2019-10-17Ensure that the exit callback is called if CreateProcessA() fails on Windows.Alexander Færøy
This patch fixes an issue where the exit handler is not called for the given process_t in case CreateProcessA() fails. This could, for example, happen if the user tries to execute a binary that does not exist. See: https://bugs.torproject.org/31810
2019-10-17Handle errors from execve() in the Unix process backend more gracefully.Alexander Færøy
This patch removes a call to tor_assert_unreached() after execve() failed. This assertion leads to the child process emitting a stack trace on its standard output, which makes the error harder for the user to demystify, since they think it is an internal error in Tor instead of "just" being a "no such file or directory" error. The process will now instead output "Error from child process: X" where X is the stringified version of the errno value. See: https://bugs.torproject.org/31810
2019-09-30Re-run "make autostyle" with improved annotate_ifdef_directivesNick Mathewson
2019-09-26Run "make autostyle" with new "annotate_ifdef_directives"Nick Mathewson
2019-09-10Merge branch 'bug31615_040' into bug31615_041teor
Merged modified lines from bug31615_040, and unmodified lines from maint-0.4.1.
2019-09-06subsys: Make the subsystem init order match the module dependenciesteor
Fix levels for subsystems that depend on log/err * winprocess (security) doesn't use err: * call windows process security APIs as early as possible * init err after winprocess * move wallclock so it's still after err * network and time depend on log: * make sure that network and time can use logging. * init network and time after log Add comments explaining the module init order. Fixes bug 31615; bugfix on 0.4.0.1-alpha.
2019-06-05Run "make autostyle."Nick Mathewson
2019-05-02Add comments to include.am files to note where new sources goNick Mathewson
This mechanism isn't perfect, and sometimes it will guess wrong, but it will help our automation.
2019-03-25Pass NULL to lpApplicationName in CreateProcessA().Alexander Færøy
When NULL is given to lpApplicationName we enable Windows' "magical" path interpretation logic, which makes Tor 0.4.x behave in the same way as previous Tor versions did when it comes to executing binaries in different system paths. For more information about this have a look at the CreateProcessA() documentation on MSDN -- especially the string interpretation example is useful to understand this issue. This bug was introduced in commit bfb94dd2ca8. See: https://bugs.torproject.org/29874
2019-01-16Bump copyright date to 2019Nick Mathewson
2019-01-11Actually close the stdout pipe on error in process_unix_execKris Katterjohn
When cleaning up after an error in process_unix_exec, the stdin pipe was being double closed instead of closing both the stdin and stdout pipes. This occurred in two places. Signed-off-by: Kris Katterjohn <katterjohn@gmail.com>
2018-12-21Fix priority on process subsystem level: it uses "net"Nick Mathewson
2018-12-21Merge branch 'ticket28847'Nick Mathewson
2018-12-21Use the subsystem list to initialize and shutdown process module.Alexander Færøy
This patch makes the process module use the subsystem list for initializing and shutting down. See: https://bugs.torproject.org/28847
2018-12-20Forward declare smartlist_t in process.hAlexander Færøy
This allows other libraries to include process.h without including the smartlist_t headers first. See: https://bugs.torproject.org/28847
2018-12-20No need to log ordinary EOF conditions as LOG_WARN.Alexander Færøy
Let's not use log_warn() when a pipe is closed under what should be considered normal conditions. See: https://bugs.torproject.org/28179
2018-12-20Make example CancelIoEx() code use CancelIo().Alexander Færøy
This patch changes the CancelIoEx() example code to use CancelIo(), which is available for older versions of Windows too. I still think the kernel handles this nicely by sending broken pipes if either side closes the pipe while I/O operations are pending. See: https://bugs.torproject.org/28179
2018-12-20Handle ERROR_BROKEN_PIPE in completion routines.Alexander Færøy
Handle `ERROR_BROKEN_PIPE` from ReadFileEx() and WriteFileEx() in process_win32_stdin_write_done() and process_win32_handle_read_completion() instead of in the early handler. This most importantmly makes sure that `reached_eof` is set to true when these errors appears. See: https://bugs.torproject.org/28179
2018-12-20Remember to set `reached_eof` when our handles are reporting errors.Alexander Færøy
This patch adds some missing calls to set `reached_eof` of our handles when various error conditions happens or when we close our handle (which happens at `process_terminate()`. See: https://bugs.torproject.org/28179
2018-12-20Handle errors even after success from ReadFileEx() and WriteFileEx().Alexander Færøy
This patch adds some additional error checking after calls to ReadFileEx() and WriteFileEx(). I have not managed to get this code to reach the branch where `error_code` is NOT `ERROR_SUCCESS`, but MSDN says one should check for this condition so we do so just to be safe. See: https://bugs.torproject.org/28179
2018-12-20Delay checking process for termination until both stdout and stderr are closed.Alexander Færøy
This patch makes us delay checking for whether we have an exit code value (via GetExitCodeProcess()) until both stdout and stderr have been closed by the operating system either by the process itself or by process cleanup after termination. See: https://bugs.torproject.org/28179
2018-12-20Remember to close the child process' ends of the pipes.Alexander Færøy
This prevents us from leaking the HANDLE for stdout, stderr, and stdin. See: https://bugs.torproject.org/28179
2018-12-18Avoid breaking the event loop prematurely.Alexander Færøy
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
2018-12-17lib/process may include lib/buf.Nick Mathewson
2018-12-17Update location of buffers.hNick Mathewson
2018-12-17Merge branch 'ticket28179_squashed' into ticket28179_squashed_mergedNick Mathewson
2018-12-17Ensure that line_size >= 1 before trying to trim input string.Alexander Færøy
See: https://bugs.torproject.org/28179
2018-12-17Make Windows process event timer API available for dormant interface.Alexander Færøy
This patch changes the API of the Windows backend of the Process subsystem to allow the dormant interface to disable the Process event timer. See: https://bugs.torproject.org/28179
2018-12-17Document the format of process_t::arguments.Alexander Færøy
See: https://bugs.torproject.org/28179
2018-12-17Use `const char *` instead of `char *` for line parameter for process callbacks.Alexander Færøy
This patch changes the type definition of the process callbacks to use `const char *` instead of `char *`. See: https://bugs.torproject.org/28179
2018-12-17Change the Process exit_callback to return bool.Alexander Færøy
This patch changes our process_t's exit_callback to return a boolean value. If the returned value is true, the process subsystem will call process_free() on the given process_t. See: https://bugs.torproject.org/28179
2018-12-17Call close() on stdin/stdout/stderr in process_terminate().Alexander Færøy
Call close() on all process handles after we have called kill(pid, SIGTERM). See: https://bugs.torproject.org/28179
2018-12-17Move remaining code from subprocess.{h,c} to more appropriate places.Alexander Færøy
This patch moves the remaining code from subprocess.{h,c} to more appropriate places in the process.c and process_win32.c module. We also delete the now empty subprocess module files. See: https://bugs.torproject.org/28179
2018-12-17Delete old process_handle_t code.Alexander Færøy
This patch removes the old process_handle_t code. Everything should by now be using the process_t interface. See: https://bugs.torproject.org/28179
2018-12-17Add process_reset_environment() to the Process subsystem.Alexander Færøy
This patch adds a new function that allows us to reset the environment of a given process_t with a list of key/value pairs. See: https://bugs.torproject.org/28179
2018-12-17Add process_terminate().Alexander Færøy
This patch adds support for process termination to the Process subsystem. See: https://bugs.torproject.org/28179
2018-12-17Make sure we call process_notify_event_exit() as the last thing in different ↵Alexander Færøy
callbacks. This patch makes sure that we call process_notify_event_exit() after we have done any modifications we need to do to the state of a process_t. This allows application developers to call process_free() in the exit_callback of the process. See: https://bugs.torproject.org/28179
2018-12-17Add process_get_pid() to the Process subsystem.Alexander Færøy
This patch adds support for getting the unique process identifier from a given process_t. This patch implements both support for both the Unix and Microsoft Windows backend. See: https://bugs.torproject.org/28179
2018-12-17Add Windows backend for the Process subsystem.Alexander Færøy
This patch adds support for Microsoft Windows in the Process subsystem. Libevent does not support mixing different types of handles (sockets, named pipes, etc.) on Windows in its core event loop code. This have historically meant that Tor have avoided attaching any non-networking handles to the event loop. This patch uses a slightly different approach to roughly support the same features for the Process subsystem as we do with the Unix backend. In this patch we use Windows Extended I/O functions (ReadFileEx() and WriteFileEx()) which executes asynchronously in the background and executes a completion routine when the scheduled read or write operation have completed. This is much different from the Unix backend where the operating system signals to us whenever a file descriptor is "ready" to either being read from or written to. To make the Windows operating system execute the completion routines of ReadFileEx() and WriteFileEx() we must get the Tor process into what Microsoft calls an "alertable" state. To do this we execute SleepEx() with a zero millisecond sleep time from a main loop timer that ticks once a second. This moves the process into the "alertable" state and when we return from the zero millisecond timeout all the outstanding I/O completion routines will be called and we can schedule the next reads and writes. The timer loop is also responsible for detecting whether our child processes have terminated since the last timer tick. See: https://bugs.torproject.org/28179
2018-12-17Add Unix backend for the Process subsystem.Alexander Færøy
This patch adds the Unix backend for the Process subsystem. The Unix backend attaches file descriptors from the child process's standard in, out and error to Tor's libevent based main loop using traditional Unix pipes. We use the already available `waitpid` module to get events whenever the child process terminates. See: https://bugs.torproject.org/28179
2018-12-17Add new Process subsystem.Alexander Færøy
This patch adds a new Process subsystem for running external programs in the background of Tor. The design is focused around a new type named `process_t` which have an API that allows the developer to easily write code that interacts with the given child process. These interactions includes: - Easy API for writing output to the child process's standard input handle. - Receive callbacks whenever the child has output on either its standard output or standard error handles. - Receive callback when the child process terminates. We also support two different "protocols" for handling output from the child process. The default protocol is the "line" protocol where the process output callbacks will be invoked only when there is complete lines (either "\r\n" or "\n" terminated). We also support the "raw" protocol where the read callbacks will get whatever the operating system delivered to us in a single read operation. This patch does not include any operating system backends, but the Unix and Windows backends will be included in separate commits. See: https://bugs.torproject.org/28179
2018-11-14Normalize .may_include to always have paths, and paths to includeNick Mathewson
2018-11-09Rename subsystem callback functions to make them consistentNick Mathewson
2018-11-05Make the windows process parameter initialization a subsystemNick Mathewson
Also, move it from "main" into lib/process
2018-09-14Add a missing function for windowsNick Mathewson
2018-09-13Run crypto_prefork() before start_daemon().Nick Mathewson
Without this, RunAsDaemon breaks NSS. Fixes bug 27664; bug not in any released Tor.
2018-08-14Adjust windows stubs for new start/finish_daemon() return typesNick Mathewson
2018-08-08Call crypto_postfork on start_daemon() instead.Nick Mathewson
2018-08-08Make finish_daemon() return a boolean to say whether it did anything.Nick Mathewson
2018-07-10Rename torlog.[ch] to log.[ch]Nick Mathewson
Fun fact: these files used to be called log.[ch] until we ran into conflicts with systems having a log.h file. But now that we always include "lib/log/log.h", we should be fine.