11 #define PROCESS_PRIVATE
85 process_win32_t *win32_process;
104 tor_assert_unreached();
122 tor_assert_unreached();
146 process_win32_init();
156 process_win32_deinit();
185 process = tor_malloc_zero(
sizeof(
process_t));
207 process->win32_process = process_win32_new();
242 process_win32_free(process->win32_process);
267 status = process_win32_exec(process);
274 log_warn(
LD_PROCESS,
"Failed to start process: %s",
297 return process_win32_terminate(process);
310 return process_win32_get_pid(process);
322 process_read_callback_t callback)
337 process_read_callback_t callback)
348 process_exit_callback_t callback)
388 process->
data = data;
398 return process->
data;
447 char *filename = process->
command;
449 const size_t size = smartlist_len(arguments);
452 argv = tor_malloc_zero(
sizeof(
char *) * (size + 2));
461 argv[arg_val_sl_idx + 1] = arg_val;
462 } SMARTLIST_FOREACH_END(arg_val);
519 process_get_win32_process(
const process_t *process)
523 return process->win32_process;
531 const uint8_t *data,
size_t size)
544 const char *format, va_list args)
562 const char *format, ...)
568 va_start(ap, format);
628 "Process terminated with exit code: %"PRIu64, exit_code);
635 bool free_process_handle =
false;
639 free_process_handle = process->
exit_callback(process, exit_code);
641 if (free_process_handle)
642 process_free(process);
656 return process_win32_read_stdout(process, buffer);
671 return process_win32_read_stderr(process, buffer);
686 process_win32_write(process, buffer);
697 process_read_callback_t callback)
711 tor_assert_unreached();
724 process_read_callback_t callback)
732 char *data = tor_malloc_zero(size + 1);
735 log_debug(
LD_PROCESS,
"Read data from process");
738 callback(process, data, size);
751 process_read_callback_t callback)
757 size_t line_size = 0;
758 char *data = tor_malloc_zero(size);
770 if (line_size >= 1 && data[line_size - 1] ==
'\n') {
771 data[line_size - 1] =
'\0';
776 if (line_size >= 1 && data[line_size - 1] ==
'\r') {
777 data[line_size - 1] =
'\0';
782 log_debug(
LD_PROCESS,
"Read line from process: \"%s\"", data);
785 callback(process, data, line_size);
793 tor_assert_nonfatal(ret == 0);
int buf_add(buf_t *buf, const char *string, size_t string_len)
size_t buf_datalen(const buf_t *buf)
int buf_get_line(buf_t *buf, char *data_out, size_t *data_len)
int buf_get_bytes(buf_t *buf, char *string, size_t string_len)
Header file for buffers.c.
Header file for buffers_net.c.
tor_cmdline_mode_t command
process_environment_t * process_environment_make(struct smartlist_t *env_vars)
int tor_vasprintf(char **strp, const char *fmt, va_list args)
void process_set_stderr_read_callback(process_t *process, process_read_callback_t callback)
void process_notify_event_stdout(process_t *process)
void process_set_data(process_t *process, void *data)
void process_write(process_t *process, const uint8_t *data, size_t size)
STATIC void process_read_data(process_t *process, buf_t *buffer, process_read_callback_t callback)
static smartlist_t * processes
void process_notify_event_exit(process_t *process, process_exit_code_t exit_code)
const smartlist_t * process_get_all_processes(void)
void process_notify_event_stderr(process_t *process)
void process_free_(process_t *process)
void process_set_status(process_t *process, process_status_t status)
const char * process_status_to_string(process_status_t status)
void process_set_environment(process_t *process, const char *key, const char *value)
void process_append_argument(process_t *process, const char *argument)
STATIC void process_write_stdin(process_t *process, buf_t *buffer)
void process_set_exit_callback(process_t *process, process_exit_callback_t callback)
void * process_get_data(const process_t *process)
const char * process_get_command(const process_t *process)
process_t * process_new(const char *command)
process_environment_t * process_get_environment(const process_t *process)
void process_vprintf(process_t *process, const char *format, va_list args)
STATIC void process_read_lines(process_t *process, buf_t *buffer, process_read_callback_t callback)
const smartlist_t * process_get_arguments(const process_t *process)
void process_free_all(void)
process_protocol_t process_get_protocol(const process_t *process)
STATIC void process_read_buffer(process_t *process, buf_t *buffer, process_read_callback_t callback)
static int may_spawn_background_process
void tor_disable_spawning_background_processes(void)
void process_reset_environment(process_t *process, const smartlist_t *env)
const char * process_protocol_to_string(process_protocol_t protocol)
process_status_t process_get_status(const process_t *process)
void process_set_stdout_read_callback(process_t *process, process_read_callback_t callback)
STATIC int process_read_stdout(process_t *process, buf_t *buffer)
process_unix_t * process_get_unix_process(const process_t *process)
char ** process_get_argv(const process_t *process)
bool process_terminate(process_t *process)
void process_notify_event_stdin(process_t *process)
void process_printf(process_t *process, const char *format,...)
process_status_t process_exec(process_t *process)
process_pid_t process_get_pid(process_t *process)
STATIC int process_read_stderr(process_t *process, buf_t *buffer)
@ PROCESS_STATUS_NOT_RUNNING
int process_unix_write(process_t *process, buf_t *buffer)
bool process_unix_terminate(process_t *process)
int process_unix_read_stderr(process_t *process, buf_t *buffer)
process_pid_t process_unix_get_pid(process_t *process)
int process_unix_read_stdout(process_t *process, buf_t *buffer)
process_unix_t * process_unix_new(void)
process_status_t process_unix_exec(process_t *process)
Header for process_unix.c.
Header for process_win32.c.
void smartlist_add_asprintf(struct smartlist_t *sl, const char *pattern,...)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_remove(smartlist_t *sl, const void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
process_exit_callback_t exit_callback
process_read_callback_t stdout_read_callback
process_exit_code_t exit_code
process_unix_t * unix_process
smartlist_t * environment
process_protocol_t protocol
process_read_callback_t stderr_read_callback
#define MOCK_IMPL(rv, funcname, arglist)
Macros to manage assertions, fatal and non-fatal.