|
solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
|
Implementation of the process management API. More...
#include "../include/process.h"#include "../include/file.h"#include <errno.h>#include <stddef.h>#include <unistd.h>Go to the source code of this file.
Functions | |
| bool | pipe_read_closed (PipeHandle *handle) |
| bool | pipe_write_closed (PipeHandle *handle) |
| PipeFd | pipe_read_fd (PipeHandle *handle) |
| PipeFd | pipe_write_fd (PipeHandle *handle) |
| const char * | process_error_string (ProcessError error) |
| Get a string description of a process error. | |
| ProcessError | pipe_create (PipeHandle **pipeHandle) |
| Create a new pipe for IPC. | |
| ProcessError | pipe_set_nonblocking (PipeHandle *pipe, bool nonblocking) |
| Set non-blocking mode on a pipe. | |
| ProcessError | pipe_read (PipeHandle *pipe, void *buffer, size_t size, size_t *bytes_read, int timeout_ms) |
| Read data from a pipe. | |
| ProcessError | pipe_write (PipeHandle *pipe, const void *buffer, size_t size, size_t *bytes_written, int timeout_ms) |
| Write data to a pipe. | |
| void | pipe_close (PipeHandle *pipe) |
| Close a pipe. | |
| ProcessError | process_create (ProcessHandle **handle, const char *command, const char *const argv[], const ProcessOptions *options) |
| Create a new process When custom environment is provided, command must be an absolute path or relative path (containing '/'), as execve() does not search PATH. | |
| void | process_free (ProcessHandle *handle) |
| Free resources associated with a process handle. | |
| ProcessError | process_wait (ProcessHandle *handle, ProcessResult *result, int timeout_ms) |
| Wait for a process to complete. | |
| ProcessError | process_terminate (ProcessHandle *handle, bool force) |
| Terminate a running process. | |
| ProcessError | process_run_and_capture (const char *command, const char *const argv[], ProcessOptions *options, int *exit_code) |
| Run a command and capture its output. | |
| ProcessError | process_redirect_to_file (FileRedirection **redirection, const char *filepath, int flags, unsigned int mode) |
| Create a new file redirection for a process. | |
| ProcessError | process_redirect_to_fd (FileRedirection **redirection, int fd, bool close_on_exec) |
| Create a file redirection from an existing file descriptor. | |
| void | process_close_redirection (FileRedirection *redirection) |
| Close and free a file redirection. | |
| ProcessError | process_create_with_redirection (ProcessHandle **handle, const char *command, const char *const argv[], const ExtProcessOptions *options) |
| Create a process with extended redirection options. | |
| ProcessError | process_run_with_multiwriter (ProcessResult *result, const char *cmd, const char *args[], int output_fds[], int error_fds[]) |
| Run the command in a process that duplicates output to multiple destinations. | |
| ProcessError | process_run_with_file_redirection (ProcessHandle **handle, const char *command, const char *const argv[], const char *stdout_file, const char *stderr_file, bool append) |
| Helper function to set up redirection to a file. | |
Implementation of the process management API.
Definition in file process.c.
| void pipe_close | ( | PipeHandle * | pipe | ) |
| ProcessError pipe_create | ( | PipeHandle ** | pipe | ) |
| ProcessError pipe_read | ( | PipeHandle * | pipe, |
| void * | buffer, | ||
| size_t | size, | ||
| size_t * | bytes_read, | ||
| int | timeout_ms | ||
| ) |
Read data from a pipe.
| [in] | pipe | Pipe handle |
| [out] | buffer | Buffer to receive the data |
| [in] | size | Buffer size |
| [out] | bytes_read | Pointer to receive the number of bytes read (can be NULL) |
| [in] | timeout_ms | Timeout in milliseconds (-1 = wait indefinitely) |
| bool pipe_read_closed | ( | PipeHandle * | handle | ) |
| PipeFd pipe_read_fd | ( | PipeHandle * | handle | ) |
| ProcessError pipe_set_nonblocking | ( | PipeHandle * | pipe, |
| bool | nonblocking | ||
| ) |
| ProcessError pipe_write | ( | PipeHandle * | pipe, |
| const void * | buffer, | ||
| size_t | size, | ||
| size_t * | bytes_written, | ||
| int | timeout_ms | ||
| ) |
Write data to a pipe.
| [in] | pipe | Pipe handle |
| [in] | buffer | Data to write |
| [in] | size | Number of bytes to write |
| [out] | bytes_written | Pointer to receive the number of bytes written (can be NULL) |
| [in] | timeout_ms | Timeout in milliseconds (-1 = wait indefinitely) |
| bool pipe_write_closed | ( | PipeHandle * | handle | ) |
| PipeFd pipe_write_fd | ( | PipeHandle * | handle | ) |
| void process_close_redirection | ( | FileRedirection * | redirection | ) |
Close and free a file redirection.
| redirection | The redirection to close |
Definition at line 1117 of file process.c.
Referenced by process_run_with_file_redirection().
| ProcessError process_create | ( | ProcessHandle ** | handle, |
| const char * | command, | ||
| const char *const | argv[], | ||
| const ProcessOptions * | options | ||
| ) |
Create a new process When custom environment is provided, command must be an absolute path or relative path (containing '/'), as execve() does not search PATH.
| [out] | handle | Pointer to receive the process handle |
| [in] | command | Path to executable |
| [in] | argv | NULL-terminated array of arguments (argv[0] should be command name) |
| [in] | options | Process creation options (NULL for defaults) |
Definition at line 843 of file process.c.
Referenced by process_run_and_capture().
| ProcessError process_create_with_redirection | ( | ProcessHandle ** | handle, |
| const char * | command, | ||
| const char *const | argv[], | ||
| const ExtProcessOptions * | options | ||
| ) |
Create a process with extended redirection options.
| [out] | handle | Pointer to store the process handle |
| [in] | command | Command to execute |
| [in] | argv | Arguments for the command (NULL-terminated) |
| [in] | options | Process options with extended IO |
Definition at line 1139 of file process.c.
Referenced by process_run_with_file_redirection().
| const char * process_error_string | ( | ProcessError | error | ) |
| void process_free | ( | ProcessHandle * | handle | ) |
Free resources associated with a process handle.
| [in] | handle | Process handle to free |
Definition at line 869 of file process.c.
Referenced by process_run_and_capture().
| ProcessError process_redirect_to_fd | ( | FileRedirection ** | redirection, |
| int | fd, | ||
| bool | close_on_exec | ||
| ) |
| ProcessError process_redirect_to_file | ( | FileRedirection ** | redirection, |
| const char * | filepath, | ||
| int | flags, | ||
| unsigned int | mode | ||
| ) |
Create a new file redirection for a process.
| [out] | redirection | Pointer to store the created redirection |
| [in] | filepath | Path to the file |
| [in] | flags | File open flags (O_RDONLY, O_WRONLY, O_RDWR, etc.) |
| [in] | mode | File mode for creation (if O_CREAT is used) |
Definition at line 1063 of file process.c.
Referenced by process_run_with_file_redirection().
| ProcessError process_run_and_capture | ( | const char * | command, |
| const char *const | argv[], | ||
| ProcessOptions * | options, | ||
| int * | exit_code | ||
| ) |
Run a command and capture its output.
Convenience function that creates a process, captures its output, waits for completion, and cleans up resources.
| [in] | command | Path to executable |
| [in] | argv | NULL-terminated array of arguments |
| [in] | options | Process creation options (NULL for defaults) |
| [out] | exit_code | Pointer to receive the exit code (can be NULL) |
Definition at line 1025 of file process.c.
References process_create(), process_free(), and process_wait().
| ProcessError process_run_with_file_redirection | ( | ProcessHandle ** | handle, |
| const char * | command, | ||
| const char *const | argv[], | ||
| const char * | stdout_file, | ||
| const char * | stderr_file, | ||
| bool | append | ||
| ) |
Helper function to set up redirection to a file.
Create a process that redirects its output from stdout and/or stderr to files.
| [in] | command | Command to run |
| [in] | argv | Command arguments |
| [in] | stdout_file | File to redirect stdout to, or NULL |
| [in] | stderr_file | File to redirect stderr to, or NULL |
| [in] | append | Whether to append to files (true) or overwrite (false) |
Definition at line 1431 of file process.c.
References process_close_redirection(), process_create_with_redirection(), and process_redirect_to_file().
| ProcessError process_run_with_multiwriter | ( | ProcessResult * | result, |
| const char * | cmd, | ||
| const char * | args[], | ||
| int | output_fds[], | ||
| int | error_fds[] | ||
| ) |
Run the command in a process that duplicates output to multiple destinations.
This function sets up a process whose output is duplicated to multiple files/pipes
| [out] | result | Will hold process exit information. |
| [in] | cmd | Command to execute |
| [in] | argv | Arguments (NULL-terminated) |
| [in] | output_fds | Array of file descriptors to duplicate output to (NULL-terminated) |
| [in] | error_fds | Array of file descriptors to duplicate errors to (NULL-terminated) |
| ProcessError process_terminate | ( | ProcessHandle * | handle, |
| bool | force | ||
| ) |
| ProcessError process_wait | ( | ProcessHandle * | handle, |
| ProcessResult * | result, | ||
| int | timeout_ms | ||
| ) |
Wait for a process to complete.
| [in] | handle | Process handle |
| [out] | result | Pointer to receive exit information (can be NULL) |
| [in] | timeout_ms | Timeout in milliseconds (-1 = wait indefinitely) |
Definition at line 906 of file process.c.
Referenced by process_run_and_capture().