Tor
0.4.7.0-alpha-dev
|
Module for working with Unix processes. More...
#include "lib/intmath/cmp.h"
#include "lib/buf/buffers.h"
#include "lib/net/buffers_net.h"
#include "lib/container/smartlist.h"
#include "lib/evloop/compat_libevent.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/waitpid.h"
#include "lib/process/env.h"
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | process_unix_handle_t |
struct | process_unix_t |
Macros | |
#define | PROCESS_UNIX_PRIVATE |
#define | DEFAULT_MAX_FD 256 |
Module for working with Unix processes.
Definition in file process_unix.c.
#define DEFAULT_MAX_FD 256 |
Maximum number of file descriptors, if we cannot get it via sysconf()
Definition at line 53 of file process_unix.c.
STATIC bool process_unix_close_file_descriptors | ( | process_unix_t * | unix_process | ) |
Close the standard in, out, and error handles of the given unix_process.
Definition at line 647 of file process_unix.c.
Referenced by process_unix_free_().
process_status_t process_unix_exec | ( | process_t * | process | ) |
Executes the given process as a child process of Tor. This function is responsible for setting up the child process and run it. This includes setting up pipes for interprocess communication, initialize the waitpid callbacks, and finally run fork() followed by execve(). Returns PROCESS_STATUS_RUNNING upon success.
Cleanup standard in pipe.
Cleanup standard in pipe.
Cleanup standard out pipe.
Cleanup standard in pipe.
Cleanup standard out pipe.
Cleanup standard error pipe.
Definition at line 131 of file process_unix.c.
void process_unix_free_ | ( | process_unix_t * | unix_process | ) |
Deallocates the given unix_process.
Definition at line 104 of file process_unix.c.
process_pid_t process_unix_get_pid | ( | process_t * | process | ) |
Returns the unique process identifier for the given process.
Definition at line 380 of file process_unix.c.
Referenced by process_get_pid().
process_unix_t* process_unix_new | ( | void | ) |
Returns a newly allocated process_unix_t.
Definition at line 90 of file process_unix.c.
STATIC int process_unix_read_handle | ( | process_t * | process, |
process_unix_handle_t * | handle, | ||
buf_t * | buffer | ||
) |
This function reads data from the given handle and puts it into buffer. Returns the number of bytes read this way.
Definition at line 614 of file process_unix.c.
Referenced by process_unix_read_stderr(), and process_unix_read_stdout().
int process_unix_read_stderr | ( | process_t * | process, |
buf_t * | buffer | ||
) |
Read data from the given process's standard error and put it into buffer. Returns the number of bytes read.
Definition at line 442 of file process_unix.c.
Referenced by process_read_stderr().
int process_unix_read_stdout | ( | process_t * | process, |
buf_t * | buffer | ||
) |
Read data from the given process's standard output and put it into buffer. Returns the number of bytes read.
Definition at line 427 of file process_unix.c.
Referenced by process_read_stdout().
STATIC void process_unix_setup_handle | ( | process_t * | process, |
process_unix_handle_t * | handle, | ||
short | flags, | ||
event_callback_fn | callback | ||
) |
This function sets the file descriptor in the handle as non-blocking and configures the libevent event structure based on the given flags to ensure that callback is called whenever we have events on the given handle.
Definition at line 588 of file process_unix.c.
STATIC void process_unix_start_reading | ( | process_unix_handle_t * | handle | ) |
This function tells libevent that we are interested in receiving read events from the given handle.
Definition at line 505 of file process_unix.c.
STATIC void process_unix_start_writing | ( | process_unix_handle_t * | handle | ) |
This function tells libevent that we are interested in receiving write events from the given handle.
Definition at line 532 of file process_unix.c.
STATIC void process_unix_stop_reading | ( | process_unix_handle_t * | handle | ) |
This function tells libevent that we are no longer interested in receiving read events from the given handle.
Definition at line 517 of file process_unix.c.
Referenced by process_unix_close_file_descriptors().
STATIC void process_unix_stop_writing | ( | process_unix_handle_t * | handle | ) |
This function tells libevent that we are no longer interested in receiving write events from the given handle.
Definition at line 546 of file process_unix.c.
Referenced by process_unix_close_file_descriptors().
bool process_unix_terminate | ( | process_t * | process | ) |
Terminate the given process. Returns true on success, otherwise false.
Definition at line 348 of file process_unix.c.
STATIC void process_unix_waitpid_callback | ( | int | status, |
void * | data | ||
) |
This function is called when the waitpid system have detected that our process have terminated. We disable the waitpid system and notify the Process subsystem that we have terminated.
Definition at line 564 of file process_unix.c.
int process_unix_write | ( | process_t * | process, |
buf_t * | buffer | ||
) |
Write the given buffer as input to the given process's standard input. Returns the number of bytes written.
Definition at line 391 of file process_unix.c.
Referenced by process_write_stdin().
STATIC void stderr_read_callback | ( | evutil_socket_t | fd, |
short | event, | ||
void * | data | ||
) |
This function is called whenever libevent thinks we have data that could be read from the child process's standard error. We notify the Process subsystem, which is then responsible for calling back to us for doing the actual reading of the data.
Definition at line 475 of file process_unix.c.
STATIC void stdin_write_callback | ( | evutil_socket_t | fd, |
short | event, | ||
void * | data | ||
) |
This function is called whenever libevent thinks we have data that could be written the child process's standard input. We notify the Process subsystem, which is then responsible for calling back to us for doing the actual write of the data.
Definition at line 491 of file process_unix.c.
STATIC void stdout_read_callback | ( | evutil_socket_t | fd, |
short | event, | ||
void * | data | ||
) |
This function is called whenever libevent thinks we have data that could be read from the child process's standard output. We notify the Process subsystem, which is then responsible for calling back to us for doing the actual reading of the data.
Definition at line 459 of file process_unix.c.