Tor  0.4.7.0-alpha-dev
Macros | Typedefs | Enumerations | Functions
process.h File Reference

Header for process.c. More...

#include "orconfig.h"
#include "lib/malloc/malloc.h"
#include "lib/string/printf.h"
#include <stdbool.h>

Go to the source code of this file.

Macros

#define PROCESS_MAX_WRITE   (1024)
 
#define PROCESS_MAX_READ   (1024)
 
#define process_free(s)   FREE_AND_NULL(process_t, process_free_, (s))
 

Typedefs

typedef uint64_t process_exit_code_t
 
typedef uint64_t process_pid_t
 
typedef void(* process_read_callback_t) (process_t *, const char *, size_t)
 
typedef bool(* process_exit_callback_t) (process_t *, process_exit_code_t)
 

Enumerations

enum  process_status_t { PROCESS_STATUS_NOT_RUNNING , PROCESS_STATUS_RUNNING , PROCESS_STATUS_ERROR }
 
enum  process_protocol_t { PROCESS_PROTOCOL_LINE , PROCESS_PROTOCOL_RAW }
 

Functions

const char * process_status_to_string (process_status_t status)
 
const char * process_protocol_to_string (process_protocol_t protocol)
 
void tor_disable_spawning_background_processes (void)
 
void process_init (void)
 
void process_free_all (void)
 
const struct smartlist_tprocess_get_all_processes (void)
 
process_tprocess_new (const char *command)
 
void process_free_ (process_t *process)
 
process_status_t process_exec (process_t *process)
 
bool process_terminate (process_t *process)
 
process_pid_t process_get_pid (process_t *process)
 
void process_set_stdout_read_callback (process_t *, process_read_callback_t)
 
void process_set_stderr_read_callback (process_t *, process_read_callback_t)
 
void process_set_exit_callback (process_t *, process_exit_callback_t)
 
const char * process_get_command (const process_t *process)
 
void process_append_argument (process_t *process, const char *argument)
 
const struct smartlist_tprocess_get_arguments (const process_t *process)
 
char ** process_get_argv (const process_t *process)
 
void process_reset_environment (process_t *process, const struct smartlist_t *env)
 
void process_set_environment (process_t *process, const char *key, const char *value)
 
struct process_environment_tprocess_get_environment (const process_t *)
 
void process_set_protocol (process_t *process, process_protocol_t protocol)
 
process_protocol_t process_get_protocol (const process_t *process)
 
void process_set_data (process_t *process, void *data)
 
void * process_get_data (const process_t *process)
 
void process_set_status (process_t *process, process_status_t status)
 
process_status_t process_get_status (const process_t *process)
 
struct process_unix_tprocess_get_unix_process (const process_t *process)
 
void process_write (process_t *process, const uint8_t *data, size_t size)
 
void process_vprintf (process_t *process, const char *format, va_list args)
 
void process_printf (process_t *process, const char *format,...)
 
void process_notify_event_stdout (process_t *process)
 
void process_notify_event_stderr (process_t *process)
 
void process_notify_event_stdin (process_t *process)
 
void process_notify_event_exit (process_t *process, process_exit_code_t)
 

Detailed Description

Header for process.c.

Definition in file process.h.

Macro Definition Documentation

◆ PROCESS_MAX_READ

#define PROCESS_MAX_READ   (1024)

Maximum number of bytes to read from a process' stdout/stderr.

Definition at line 24 of file process.h.

◆ PROCESS_MAX_WRITE

#define PROCESS_MAX_WRITE   (1024)

Maximum number of bytes to write to a process' stdin.

Definition at line 21 of file process.h.

Enumeration Type Documentation

◆ process_protocol_t

Enumerator
PROCESS_PROTOCOL_LINE 

Pass complete newline-terminated lines to the callback (with the LF or CRLF removed).

PROCESS_PROTOCOL_RAW 

Pass the raw response from read() to the callback.

Definition at line 39 of file process.h.

◆ process_status_t

Enumerator
PROCESS_STATUS_NOT_RUNNING 

The process is not running.

PROCESS_STATUS_RUNNING 

The process is running.

PROCESS_STATUS_ERROR 

The process is in an erroneous state.

Definition at line 26 of file process.h.

Function Documentation

◆ process_append_argument()

void process_append_argument ( process_t process,
const char *  argument 
)

Append an argument to the list of arguments in the given process.

Definition at line 419 of file process.c.

◆ process_exec()

process_status_t process_exec ( process_t process)

Execute the given process. This function executes the given process as a subprocess of Tor. Returns PROCESS_STATUS_RUNNING upon success.

Definition at line 253 of file process.c.

◆ process_free_()

void process_free_ ( process_t process)

Deallocate the given process in process.

Definition at line 217 of file process.c.

◆ process_free_all()

void process_free_all ( void  )

Free up all resources that is handled by the Process subsystem. Note that this call does not terminate already running processes.

Definition at line 153 of file process.c.

◆ process_get_all_processes()

const struct smartlist_t* process_get_all_processes ( void  )

Get a list of all processes. This function returns a smartlist of process_t containing all the currently allocated processes.

Definition at line 166 of file process.c.

◆ process_get_arguments()

const struct smartlist_t* process_get_arguments ( const process_t process)

Returns a list of arguments (excluding the command itself) from the given process.

Definition at line 430 of file process.c.

◆ process_get_argv()

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.

Definition at line 439 of file process.c.

◆ process_get_command()

const char* process_get_command ( const process_t process)

Get the current command of the given process.

Definition at line 356 of file process.c.

◆ process_get_data()

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_get_environment()

struct 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.

Definition at line 501 of file process.c.

◆ process_get_pid()

process_pid_t process_get_pid ( process_t process)

Returns the unique process identifier for the given process.

Definition at line 303 of file process.c.

◆ process_get_protocol()

process_protocol_t process_get_protocol ( const process_t process)

Get the currently used protocol of the given process.

Definition at line 371 of file process.c.

◆ process_get_status()

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_get_unix_process()

struct 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().

◆ process_init()

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.

Definition at line 141 of file process.c.

◆ process_new()

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.

Definition at line 180 of file process.c.

◆ process_notify_event_exit()

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.

Definition at line 623 of file process.c.

◆ process_notify_event_stderr()

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().

◆ process_notify_event_stdin()

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().

◆ process_notify_event_stdout()

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().

◆ process_printf()

void process_printf ( process_t process,
const char *  format,
  ... 
)

As tor_snprintf(), but write the data to the given process's standard input.

Definition at line 561 of file process.c.

◆ process_protocol_to_string()

const char* process_protocol_to_string ( process_protocol_t  protocol)

Convert a given process protocol in protocol to its string representation.

Definition at line 112 of file process.c.

◆ process_set_data()

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().

◆ process_set_environment()

void process_set_environment ( process_t process,
const char *  key,
const char *  value 
)

Set the given key/value pair as environment variable in the given process.

Definition at line 487 of file process.c.

◆ process_set_exit_callback()

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().

◆ process_set_status()

void process_set_status ( process_t process,
process_status_t  status 
)

Set the status of a given process.

Definition at line 403 of file process.c.

◆ process_set_stderr_read_callback()

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().

◆ process_set_stdout_read_callback()

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().

◆ process_status_to_string()

const char* process_status_to_string ( process_status_t  status)

Convert a given process status in status to its string representation.

Definition at line 92 of file process.c.

◆ process_terminate()

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().

◆ process_vprintf()

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().

◆ process_write()

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().

◆ tor_disable_spawning_background_processes()

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().