Crinit -- Configurable Rootfs Init
|
Implementation of runtime commands to be triggered by the notification/service interface. More...
#include "rtimcmd.h"
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/reboot.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "common.h"
#include "fseries.h"
#include "globopt.h"
#include "logio.h"
#include "procdip.h"
#include "version.h"
Classes | |
struct | crinitShdnThrArgs_t |
struct | crinitUnMountList_t |
Typedefs | |
typedef struct crinitShdnThrArgs_t | crinitShdnThrArgs_t |
typedef struct crinitUnMountList_t | crinitUnMountList_t |
Implementation of runtime commands to be triggered by the notification/service interface.
typedef struct crinitShdnThrArgs_t crinitShdnThrArgs_t |
Argument structure for shdnThread().
typedef struct crinitUnMountList_t crinitUnMountList_t |
A linked list to organize mount points that need to be handled before shutdown/reboot.
int crinitBuildRtimCmd | ( | crinitRtimCmd_t * | c, |
crinitRtimOp_t | op, | ||
size_t | argc, | ||
... | |||
) |
Create an crinitRtimCmd_t from an opcode and an argument list.
Will allocate memory for the argument string array which should be freed using crinitDestroyRtimCmd() when no longer needed.
c | The crinitRtimCmd_t to build. |
op | The opcode of the command or response. |
argc | The number of arguments to the command/response. |
... | List of argc arguments of type const char* . |
int crinitBuildRtimCmdArray | ( | crinitRtimCmd_t * | c, |
crinitRtimOp_t | op, | ||
int | argc, | ||
const char * | args[] | ||
) |
int crinitDestroyRtimCmd | ( | crinitRtimCmd_t * | c | ) |
Free memory in an crinitRtimCmd_t allocated by crinitBuildRtimCmd() or crinitParseRtimCmd().
Will free the memory for the argument array in the structure.
c | The crinitRtimCmd_t from which the memory should be freed. |
int crinitExecRtimCmd | ( | crinitTaskDB_t * | ctx, |
crinitRtimCmd_t * | res, | ||
const crinitRtimCmd_t * | cmd | ||
) |
Executes an crinitRtimCmd_t if it contains a valid command.
For the implementations of the different possible commands see rtimcmd.c.
ctx | Pointer to the crinitTaskDB_t the command shall be executed on. |
res | Result/response output. |
cmd | The command to execute. |
|
static |
Internal implementation of the "addseries" command on an crinitTaskDB.
For documentation on the command itself, see crinitClientSeriesAdd().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "addtask" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientTaskAdd().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "disable" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientTaskDisable().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "enable" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientTaskEnable().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the version query from the client library to crinit.
For documentation on the command itself, see crinitClientGetVersion().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "kill" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientTaskKill().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "notify" command on an crinitTaskDB_t.
For documentation on the command itself, see sd_notify() and sd_notifyf().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "restart" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientTaskRestart().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "shutdown" command.
For documentation on the command itself, see crinitClientShutdown().
ctx | The currently running crinitTaskDB, needed to inhibit spawning of new processes during shutdown. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd to execute, used to pass the argument list. |
|
static |
Internal implementation of the "status" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientTaskGetStatus().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "stop" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientTaskStop().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
static |
Internal implementation of the "list" command on an crinitTaskDB_t.
For documentation on the command itself, see crinitClientGetTaskList().
ctx | The crinitTaskDB_t to operate on. |
res | Return pointer for response/result. |
cmd | The crinitRtimCmd_t to execute, used to pass the argument list. |
|
inlinestatic |
Frees memory allocated for an crinitUnMountList_t by crinitGenUnMountList()
um | The crinitUnMountList_t to free. |
|
inlinestatic |
Prepares mounted filesystems for shutdown.
Performs MNT_DETACH if the file systems are not the root mount. The root mount is remounted read-only if it was writable before.
|
inlinestatic |
Generates a list of mount points that should be unmounted before shutdown/reboot.
The resulting list will include all entries from /proc/mounts
whose source is not none
and which are not the root node. The list will be ordered newest mount first. Memory for the list elements will be allocated and needs to be freed using crinitFreeUnMountList() when no longer in use.
Additionally, crinitGenUnMountList() checks if the root mount entry is read-only, setting rootfsIsRo to true in that case.
um | Return pointer for the UnMountList. |
rootfsIsRo | Return pointer indicating if we are on a read-only rootfs. |
|
inlinestatic |
Wait function using nanosleep for the shutdown grace period.
micros | Number of microseconds to wait. |
int crinitParseRtimCmd | ( | crinitRtimCmd_t * | out, |
const char * | cmdStr | ||
) |
Parses a string into an crinitRtimCmd_t.
The string must be of the form <OPCODE_STRING>\nARG1\n...\nARGn
. The mapping of an opcode to a string representation is done in rtimopmap.h. crinitRtimCmdToMsgStr() can be used to obtain such a string from an crinitRtimCmd_t.
Will allocate memory for the argument array inside the output command which should be freed using crinitDestroyRtimCmd().
out | The crinitRtimCmd_t to create. |
cmdStr | The string to parse. |
int crinitRtimCmdToMsgStr | ( | char ** | out, |
size_t * | outLen, | ||
const crinitRtimCmd_t * | cmd | ||
) |
Generates a string representation of an crinitRtimCmd_t.
The generated string will be in a format parse-able by crinitParseRtimCmd(). Memory for the string will be allocated using malloc() and should be freed using free() once no longer used.
out | Pointer to the output string. |
outLen | Size of the output string including the terminating zero. |
cmd | The crinitRtimCmd_t to generate the string from. |
|
static |
Shutdown thread function.
Run as a pthread, so that crinitExecRtimCmdShutdown() may return before the actual shutdown syscall is issued and the requesting process is not blocked.
args | Argument pointer, see ShdnThrArgs. |