Crinit -- Configurable Rootfs Init
|
Implementation of the Process Dispatcher. More...
#include "procdip.h"
#include <spawn.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "envset.h"
#include "logio.h"
Classes | |
struct | crinitDispThrArgs_t |
Macros | |
#define | crinitGettid() ((pid_t)syscall(SYS_gettid)) |
Typedefs | |
typedef struct crinitDispThrArgs_t | crinitDispThrArgs_t |
Functions | |
static void * | crinitDispatchThreadFunc (void *args) |
static int | crinitBlockOnWaitInhibit (void) |
static int | crinitReapPid (pid_t pid) |
static int | crinitPosixSpawnAddIOFileAction (posix_spawn_file_actions_t *fileact, const crinitIoRedir_t *ior) |
static int | crinitEnsureFifo (const char *path, mode_t mode) |
int | crinitProcDispatchSpawnFunc (crinitTaskDB_t *ctx, const crinitTask_t *t) |
int | crinitSetInhibitWait (bool inh) |
Variables | |
static pthread_mutex_t | crinitWaitInhibitLock = PTHREAD_MUTEX_INITIALIZER |
static pthread_cond_t | crinitWaitInhibitCond = PTHREAD_COND_INITIALIZER |
static bool | crinitWaitInhibit = false |
Implementation of the Process Dispatcher.
#define crinitGettid | ( | ) | ((pid_t)syscall(SYS_gettid)) |
Macro wrapper for the gettid syscall in case glibc is not new enough to contain one itself
typedef struct crinitDispThrArgs_t crinitDispThrArgs_t |
Struct wrapper for arguments to dispatchThreadFunc
|
static |
Block calling thread until crinitWaitInhibit becomes false.
Called by dispatcher threads to delay reaping of zombie processes if needed.
|
static |
Function to be started as a pthread from crinitProcDispatchThread().
Takes care of process spawning/waiting and crinitTaskDB_t status updates.
args | See crinitDispThrArgs_t. |
|
static |
Ensures the given path is a FIFO special file (named pipe).
If the file exists it will be checked wie stat() and the function will return an error if the file is anything else than a FIFO. If the file does not yet exist, it will be created with the given mode. Existing FIFOs will be left as is.
path | The path where the FIFO shall exist. |
mode | The mode of a FIFO if it is newly created. |
|
static |
Adds an action to a posix_spawn_file_actions_t instance as defined by an crinitIoRedir_t instance.
The file action will either be a call to open() including an IO redirection for an crinitIoRedir_t which contains a non-NULL crinitIoRedir_t::path, or a single redirection via dup2() if crinitIoRedir_t::oldfd is positive. If both cases are true, the crinitIoRedir_t::path takes precedence and crinitIoRedir_r::oldfd is ignored.
crinitIoRedir_t::oflags is respected for files and crinitIoRedir_t::mode is respected for files that are overwritten or newly created.
fileact | The posix_spawn_file_actions_t to be modified, must have been initialized. |
ior | The crinitIoRedir_t defining the file action to be added. |
int crinitProcDispatchSpawnFunc | ( | crinitTaskDB_t * | ctx, |
const crinitTask_t * | t | ||
) |
Process dispatcher function to spawn a task that is ready.
Will create a new thread to handle process spawning of task t and status updates of ctx. The function will return successfully if the thread has been created without error. The thread is created in a detached state so no further management action is necessary.
|
static |
Reap a zombie process.
Will call blockOnWaitInhibit() internally.
pid | The PID of the process to wait for. |
int crinitSetInhibitWait | ( | bool | inh | ) |
Turn waiting for child processes on or off.
If inh is set to true, the process dispatch threads will block before waiting for a child process until waiting is reactivated, leaving terminated child processes as zombies for the time being.
inh | Set true to inhibit waiting or false to reactivate waiting. |
|
static |
If true, all terminated child processes will be kept around as zombies (see crinitBlockOnWaitInhibit()).
|
static |
Condition variable to signal threads waiting for crinitWaitInhibit to become false
.
|
static |
Mutex to guard crinitWaitInhibit