Methods to set process priority. More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_OS_Process |
struct | GNUNET_OS_CommandHandle |
Handle to a command. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__) |
#define | LOG_STRERROR(kind, syscall) GNUNET_log_from_strerror (kind, "util-os-priority", syscall) |
#define | LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename) |
#define | GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE" |
Functions | |
static void | shutdown_pch (void *cls) |
This handler is called on shutdown to remove the pch. More... | |
static void | parent_control_handler (void *cls) |
This handler is called when there are control data to be read on the pipe. More... | |
void | GNUNET_OS_install_parent_control_handler (void *cls) |
Connects this process to its parent via pipe; essentially, the parent control handler will read signal numbers from the GNUNET_OS_CONTROL_PIPE (as given in an environment variable) and raise those signals. More... | |
struct GNUNET_OS_Process * | GNUNET_OS_process_current () |
Get process structure for current process. More... | |
int | GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) |
Sends a signal to the process. More... | |
pid_t | GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc) |
Get the pid of the process in question. More... | |
void | GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc) |
Cleans up process structure contents (OS-dependent) and deallocates it. More... | |
static void | open_dev_null (int target_fd, int flags) |
Open '/dev/null' and make the result the given file descriptor. More... | |
static struct GNUNET_OS_Process * | start_process (enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const int *lsocks, const char *filename, char *const argv[]) |
Start a process. More... | |
struct GNUNET_OS_Process * | GNUNET_OS_start_process_vap (enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[]) |
Start a process. More... | |
struct GNUNET_OS_Process * | GNUNET_OS_start_process_va (enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, va_list va) |
Start a process. More... | |
struct GNUNET_OS_Process * | GNUNET_OS_start_process (enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...) |
Start a process. More... | |
struct GNUNET_OS_Process * | GNUNET_OS_start_process_v (enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename, char *const argv[]) |
Start a process. More... | |
struct GNUNET_OS_Process * | GNUNET_OS_start_process_s (enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...) |
Start a process. More... | |
static enum GNUNET_GenericReturnValue | process_status (struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code, int options) |
Retrieve the status of a process, waiting on it if dead. More... | |
enum GNUNET_GenericReturnValue | GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code) |
Retrieve the status of a process. More... | |
enum GNUNET_GenericReturnValue | GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code) |
Retrieve the status of a process, waiting on it if dead. More... | |
enum GNUNET_GenericReturnValue | GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc) |
Wait for a process to terminate. More... | |
void | GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd) |
Stop/kill a command. More... | |
static void | cmd_read (void *cls) |
Read from the process and call the line processor. More... | |
struct GNUNET_OS_CommandHandle * | GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, struct GNUNET_TIME_Relative timeout, const char *binary,...) |
Run the given command line and call the given function for each line of the output. More... | |
Variables | |
static struct GNUNET_OS_Process | current_process |
Handle for 'this' process. More... | |
static struct GNUNET_SCHEDULER_Task * | pch |
Handle for the parent_control_handler() Task. More... | |
static struct GNUNET_SCHEDULER_Task * | spch |
Handle for the shutdown_pch() Task. More... | |
Methods to set process priority.
Definition in file os_priority.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__) |
Definition at line 33 of file os_priority.c.
#define LOG_STRERROR | ( | kind, | |
syscall | |||
) | GNUNET_log_from_strerror (kind, "util-os-priority", syscall) |
Definition at line 35 of file os_priority.c.
#define LOG_STRERROR_FILE | ( | kind, | |
syscall, | |||
filename | |||
) | GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename) |
Definition at line 38 of file os_priority.c.
#define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE" |
Definition at line 41 of file os_priority.c.
|
static |
This handler is called on shutdown to remove the pch.
cls | the struct GNUNET_DISK_FileHandle of the control pipe |
Definition at line 81 of file os_priority.c.
References GNUNET_DISK_file_close(), GNUNET_SCHEDULER_cancel(), and pch.
Referenced by GNUNET_OS_install_parent_control_handler().
|
static |
This handler is called when there are control data to be read on the pipe.
cls | the struct GNUNET_DISK_FileHandle of the control pipe |
Definition at line 98 of file os_priority.c.
References getenv(), GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_OS_CONTROL_PIPE, GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_cancel(), GNUNET_SIGNAL_raise(), GNUNET_TIME_UNIT_FOREVER_REL, LOG, LOG_STRERROR, parent_control_handler(), pch, ret, and spch.
Referenced by GNUNET_OS_install_parent_control_handler(), and parent_control_handler().
|
static |
Open '/dev/null' and make the result the given file descriptor.
target_fd | desired FD to point to /dev/null |
flags | open flags (O_RDONLY, O_WRONLY) |
Definition at line 277 of file os_priority.c.
References GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror, and GNUNET_log_strerror_file.
Referenced by start_process().
|
static |
Start a process.
std_inheritance | a set of GNUNET_OS_INHERIT_STD_* flags controlling which std handles of the parent are inherited by the child. pipe_stdin and pipe_stdout take priority over std_inheritance (when they are non-NULL). |
pipe_stdin | pipe to use to send input to child process (or NULL) |
pipe_stdout | pipe to use to get output from child process (or NULL) |
pipe_stderr | pipe to use for stderr for child process (or NULL) |
lsocks | array of listen sockets to dup systemd-style (or NULL); must be NULL on platforms where dup is not supported |
filename | name of the binary |
argv | NULL-terminated list of arguments to the process |
Definition at line 317 of file os_priority.c.
References GNUNET_OS_Process::control_pipe, filename, GNUNET_array_append, GNUNET_array_grow, GNUNET_assert, GNUNET_break, GNUNET_DISK_file_close(), GNUNET_DISK_internal_file_handle_(), GNUNET_DISK_PF_NONE, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_DISK_pipe_detach_end(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_ERROR, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_CONTROL_PIPE, GNUNET_OS_INHERIT_STD_ERR, GNUNET_OS_INHERIT_STD_IN, GNUNET_OS_INHERIT_STD_OUT, GNUNET_OS_USE_PIPE_CONTROL, GNUNET_snprintf(), GNUNET_SYSERR, LOG_STRERROR, LOG_STRERROR_FILE, ls, open_dev_null(), GNUNET_OS_Process::pid, and ret.
Referenced by GNUNET_OS_start_process_v(), and GNUNET_OS_start_process_vap().
|
static |
Retrieve the status of a process, waiting on it if dead.
Nonblocking version.
proc | process ID |
type | status type |
code | return code/signal number |
options | WNOHANG if non-blocking is desired |
Definition at line 790 of file os_priority.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_OK, GNUNET_OS_PROCESS_EXITED, GNUNET_OS_PROCESS_RUNNING, GNUNET_OS_PROCESS_SIGNALED, GNUNET_OS_PROCESS_UNKNOWN, GNUNET_SYSERR, LOG_STRERROR, options, GNUNET_OS_Process::pid, ret, status, and type.
Referenced by GNUNET_OS_process_status(), and GNUNET_OS_process_wait_status().
|
static |
Read from the process and call the line processor.
cls | the struct GNUNET_OS_CommandHandle * |
Definition at line 962 of file os_priority.c.
References GNUNET_OS_CommandHandle::buf, cmd_read(), end, GNUNET_DISK_file_read(), GNUNET_NETWORK_fdset_handle_isset(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_get_task_context(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, GNUNET_OS_CommandHandle::off, GNUNET_OS_CommandHandle::proc, GNUNET_OS_CommandHandle::proc_cls, GNUNET_OS_CommandHandle::r, GNUNET_SCHEDULER_TaskContext::read_ready, ret, GNUNET_OS_CommandHandle::rtask, tc, and GNUNET_OS_CommandHandle::timeout.
Referenced by cmd_read(), and GNUNET_OS_command_run().
|
static |
Handle for 'this' process.
Definition at line 62 of file os_priority.c.
Referenced by GNUNET_OS_process_current().
|
static |
Handle for the parent_control_handler() Task.
Definition at line 67 of file os_priority.c.
Referenced by extract_filename(), GNUNET_OS_install_parent_control_handler(), parent_control_handler(), and shutdown_pch().
|
static |
Handle for the shutdown_pch() Task.
Definition at line 72 of file os_priority.c.
Referenced by GNUNET_OS_install_parent_control_handler(), and parent_control_handler().