Tor
0.4.7.0-alpha-dev
|
Module for working with other processes. More...
#include "lib/buf/buffers.h"
#include "lib/net/buffers_net.h"
#include "lib/container/smartlist.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/process/process.h"
#include "lib/process/process_unix.h"
#include "lib/process/process_win32.h"
#include "lib/process/env.h"
Go to the source code of this file.
Data Structures | |
struct | process_t |
Variables | |
static smartlist_t * | processes |
static int | may_spawn_background_process = 1 |
Module for working with other processes.
Definition in file process.c.
void process_append_argument | ( | process_t * | process, |
const char * | argument | ||
) |
process_status_t process_exec | ( | process_t * | process | ) |
void process_free_ | ( | process_t * | process | ) |
void process_free_all | ( | void | ) |
const smartlist_t* process_get_all_processes | ( | void | ) |
const smartlist_t* process_get_arguments | ( | const process_t * | process | ) |
char** process_get_argv | ( | const process_t * | process | ) |
Returns a newly allocated Unix style argument vector. Use tor_free() to deallocate it after use.
Generate a Unix style process argument vector from our process's arguments smartlist_t.
const char* process_get_command | ( | const process_t * | process | ) |
void* process_get_data | ( | const process_t * | process | ) |
Get the opaque pointer to callback data from the given process. This function allows you get the data you stored with process_set_data() in the different callback functions.
Definition at line 395 of file process.c.
Referenced by managed_proxy_stderr_callback(), and managed_proxy_stdout_callback().
process_environment_t* process_get_environment | ( | const process_t * | process | ) |
Returns a newly allocated process_environment_t containing the environment variables for the given process.
process_pid_t process_get_pid | ( | process_t * | process | ) |
process_protocol_t process_get_protocol | ( | const process_t * | process | ) |
process_status_t process_get_status | ( | const process_t * | process | ) |
Get the status of the given process.
Definition at line 411 of file process.c.
Referenced by process_terminate().
process_unix_t* process_get_unix_process | ( | const process_t * | process | ) |
Get the internal handle for the Unix backend.
Definition at line 510 of file process.c.
Referenced by process_unix_exec(), process_unix_get_pid(), process_unix_read_stderr(), process_unix_read_stdout(), process_unix_terminate(), and process_unix_write().
void process_init | ( | void | ) |
Initialize the Process subsystem. This function initializes the Process subsystem's global state. For cleaning up, process_free_all() should be called.
process_t* process_new | ( | const char * | command | ) |
Allocate and initialize a new process. This function returns a newly allocated and initialized process data, which can be used to configure and later run a subprocess of Tor. Use the various process_set_*() methods to configure it and run the process using process_exec(). Use command to specify the path to the command to run. You can either specify an absolute path to the command or relative where Tor will use the underlying operating system's functionality for finding the command to run.
void process_notify_event_exit | ( | process_t * | process, |
process_exit_code_t | exit_code | ||
) |
This function is called by the Process backend when a given process have terminated. The exit status code is passed in exit_code. We mark the process as no longer running and calls the exit_callback with information about the process termination. The given process is free'd iff the exit_callback returns true.
void process_notify_event_stderr | ( | process_t * | process | ) |
This function is called by the Process backend when a given process have data that is ready to be read from the child process's standard error handle.
Definition at line 594 of file process.c.
Referenced by stderr_read_callback().
void process_notify_event_stdin | ( | process_t * | process | ) |
This function is called by the Process backend when a given process is allowed to begin writing data to the standard input of the child process.
Definition at line 610 of file process.c.
Referenced by stdin_write_callback().
void process_notify_event_stdout | ( | process_t * | process | ) |
This function is called by the Process backend when a given process have data that is ready to be read from the child process's standard output handle.
Definition at line 577 of file process.c.
Referenced by stdout_read_callback().
void process_printf | ( | process_t * | process, |
const char * | format, | ||
... | |||
) |
As tor_snprintf(), but write the data to the given process's standard input.
const char* process_protocol_to_string | ( | process_protocol_t | protocol | ) |
STATIC void process_read_data | ( | process_t * | process, |
buf_t * | buffer, | ||
process_read_callback_t | callback | ||
) |
This function calls the protocol handlers based on the value of process_get_protocol(process). Currently we call process_read_buffer() for PROCESS_PROTOCOL_RAW and process_read_lines() for PROCESS_PROTOCOL_LINE.
Definition at line 695 of file process.c.
Referenced by process_notify_event_stderr(), and process_notify_event_stdout().
STATIC void process_read_lines | ( | process_t * | process, |
buf_t * | buffer, | ||
process_read_callback_t | callback | ||
) |
This function tries to extract complete lines from the given buffer and calls the given callback function whenever it has a complete line. Before calling callback we remove the trailing "\n" or "\r\n" from the line. If we are unable to extract a complete line we leave the data in the buffer for next call.
This function is called whenever the Process backend have notified us that there is data to be read from its standard error handle. Returns the number of bytes that have been put into the given buffer.
Definition at line 663 of file process.c.
Referenced by process_notify_event_stderr().
This function is called whenever the Process backend have notified us that there is data to be read from its standard out handle. Returns the number of bytes that have been put into the given buffer.
Definition at line 648 of file process.c.
Referenced by process_notify_event_stdout().
void process_reset_environment | ( | process_t * | process, |
const smartlist_t * | env | ||
) |
void process_set_data | ( | process_t * | process, |
void * | data | ||
) |
Set opaque pointer to data. This function allows you to store a pointer to your own data in the given process. Use process_get_data() in the various callback functions to retrieve the data again.
Note that the given process does NOT take ownership of the data and you are responsible for freeing up any resources allocated by the given data.
Definition at line 385 of file process.c.
Referenced by launch_managed_proxy(), and proxy_prepare_for_restart().
void process_set_environment | ( | process_t * | process, |
const char * | key, | ||
const char * | value | ||
) |
void process_set_exit_callback | ( | process_t * | process, |
process_exit_callback_t | callback | ||
) |
Set the callback function for process exit notification. The callback function will be called every time your child process have terminated.
Definition at line 347 of file process.c.
Referenced by launch_managed_proxy().
void process_set_status | ( | process_t * | process, |
process_status_t | status | ||
) |
void process_set_stderr_read_callback | ( | process_t * | process, |
process_read_callback_t | callback | ||
) |
Set the callback function for output from the child process's standard error handle. This function sets the callback function which is called every time the child process have written output to its standard error file handle.
Use process_set_protocol(process, PROCESS_PROTOCOL_LINE) if you want the callback to only contain complete "\n" or "\r\n" terminated lines.
Definition at line 336 of file process.c.
Referenced by launch_managed_proxy().
void process_set_stdout_read_callback | ( | process_t * | process, |
process_read_callback_t | callback | ||
) |
Set the callback function for output from the child process's standard out handle. This function sets the callback function which is called every time the child process have written output to its standard out file handle.
Use process_set_protocol(process, PROCESS_PROTOCOL_LINE) if you want the callback to only contain complete "\n" or "\r\n" terminated lines.
Definition at line 321 of file process.c.
Referenced by launch_managed_proxy().
const char* process_status_to_string | ( | process_status_t | status | ) |
bool process_terminate | ( | process_t * | process | ) |
Terminate the given process. Returns true on success, otherwise false.
Definition at line 284 of file process.c.
Referenced by proxy_prepare_for_restart().
void process_vprintf | ( | process_t * | process, |
const char * | format, | ||
va_list | args | ||
) |
As tor_vsnprintf(), but write the data to the given process's standard input.
Definition at line 543 of file process.c.
Referenced by process_printf().
void process_write | ( | process_t * | process, |
const uint8_t * | data, | ||
size_t | size | ||
) |
Write size bytes of data to the given process's standard input.
Definition at line 530 of file process.c.
Referenced by process_vprintf().
This function calls the backend function for the given process whenever there is data to be written to the backends' file handles.
Definition at line 678 of file process.c.
Referenced by process_notify_event_stdin(), and process_write().
void tor_disable_spawning_background_processes | ( | void | ) |
Turn off may_spawn_background_process, so that all future calls to tor_spawn_background are guaranteed to fail.
Definition at line 132 of file process.c.
Referenced by options_act().
|
static |
Boolean. If true, then Tor may call execve or CreateProcess via tor_spawn_background.
Definition at line 33 of file process.c.
Referenced by tor_disable_spawning_background_processes().
|
static |
A list of all process_t instances currently allocated.
Definition at line 27 of file process.c.
Referenced by process_free_all(), process_get_all_processes(), and process_init().