Crinit -- Configurable Rootfs Init
confhdl.c File Reference

(2023-09-05, commit: 379c4eb)

Implementation of type- and target-specific handler functions for configuration parsing. More...

#include "confhdl.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "common.h"
#include "confconv.h"
#include "globopt.h"
#include "lexers.h"
#include "logio.h"
Include dependency graph for confhdl.c:

Macros

#define crinitCfgHandlerTypeCheck(t)
 

Functions

static int crinitCfgHandlerSetTaskOptFromStr (crinitTaskOpts_t *tgt, crinitTaskOpts_t opt, const char *val)
 
static void * crinitCfgHandlerManageArrayMem (void *dynArr, size_t elementSize, size_t curSize, size_t reqSize)
 
static bool crinitDirExists (const char *path)
 
int crinitCfgCmdHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgDepHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgPrvHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgEnvHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgFilterHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgIoRedirHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgNameHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgRespHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgRespRetHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitTaskIncludeHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgDebugHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgInclSuffixHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgInclDirHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgShdGpHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgTaskSuffixHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgTaskDirHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgTaskDirSlHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgTasksHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgSyslogHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgElosHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgElosServerHandler (void *tgt, const char *val, crinitConfigType_t type)
 
int crinitCfgElosPortHandler (void *tgt, const char *val, crinitConfigType_t type)
 

Detailed Description

Implementation of type- and target-specific handler functions for configuration parsing.

Macro Definition Documentation

◆ crinitCfgHandlerTypeCheck

#define crinitCfgHandlerTypeCheck (   t)
Value:
do { \
if ((t) != type) { \
crinitErrPrint("This function is not capable of dealing with the configuration type %s", #t); \
return -1; \
} \
} while (0)

Macro to assert that the given crinitConfigType_t in a crinitConfigHandler_t has a specific value.

Parameters
tThe target value of the parameter type. If unequal to the value given to the encompassing function, the function will print an error and return -1.

Function Documentation

◆ crinitCfgCmdHandler()

int crinitCfgCmdHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for COMMAND config directives. See crinitConfigHandler_t.

◆ crinitCfgDebugHandler()

int crinitCfgDebugHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for DEBUG config directives. See crinitConfigHandler_t.

◆ crinitCfgDepHandler()

int crinitCfgDepHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for DEPENDS config directives. See crinitConfigHandler_t.

◆ crinitCfgElosHandler()

int crinitCfgElosHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for USE_ELOS config directives. See crinitConfigHandler_t.

◆ crinitCfgElosPortHandler()

int crinitCfgElosPortHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for ELOS_PORT config directives. See crinitConfigHandler_t.

◆ crinitCfgElosServerHandler()

int crinitCfgElosServerHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for ELOS_SERVER config directives. See crinitConfigHandler_t.

◆ crinitCfgEnvHandler()

int crinitCfgEnvHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for ENV_SET config directives. See crinitConfigHandler_t.

◆ crinitCfgFilterHandler()

int crinitCfgFilterHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for FILTER_DEFINE config directives. See crinitConfigHandler_t.

◆ crinitCfgHandlerManageArrayMem()

static void * crinitCfgHandlerManageArrayMem ( void *  dynArr,
size_t  elementSize,
size_t  curSize,
size_t  reqSize 
)
inlinestatic

(Re-)allocate memory for generic arrays.

Given current size of an array and required size, the function will allocate/grow the array. Shrinking is unsupported and will lead to an error being returned. Initializes newly allocated memory to 0.

Parameters
dynArrThe array to reallocate or NULL if we want a new array.
elementSizeSize of a single element in the array.
curSizeCurrent number of elements in the array.
reqSizeRequired number of elements in the array.
Returns
The new address of the array on success, NULL on failure.

◆ crinitCfgHandlerSetTaskOptFromStr()

static int crinitCfgHandlerSetTaskOptFromStr ( crinitTaskOpts_t tgt,
crinitTaskOpts_t  opt,
const char *  val 
)
inlinestatic

Helper function to set a bitmask value in crinitTask_t::opts.

Parameters
tgtDirect pointer to the crinitTaskOpts_t inside an crinitTask_t which shall be modified.
optBitmask of the task option to be set, one of CRINIT_TASK_OPT_*
valThe string value indicating if the bit should be set or unset. Uses crinitConfConvToBool().
Returns
0 on success, -1 on error

◆ crinitCfgInclDirHandler()

int crinitCfgInclDirHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for INCLUDEDIR config directives. See crinitConfigHandler_t.

◆ crinitCfgInclSuffixHandler()

int crinitCfgInclSuffixHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for INCLUDE_SUFFIX config directives. See crinitConfigHandler_t.

◆ crinitCfgIoRedirHandler()

int crinitCfgIoRedirHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for IO_REDIRECT config directives. See crinitConfigHandler_t.

◆ crinitCfgNameHandler()

int crinitCfgNameHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for NAME config directives. See crinitConfigHandler_t.

◆ crinitCfgPrvHandler()

int crinitCfgPrvHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for PROVIDES config directives. See crinitConfigHandler_t.

◆ crinitCfgRespHandler()

int crinitCfgRespHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for RESPAWN config directives. See crinitConfigHandler_t.

◆ crinitCfgRespRetHandler()

int crinitCfgRespRetHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for RESPAWN_RETRIES config directives. See crinitConfigHandler_t.

◆ crinitCfgShdGpHandler()

int crinitCfgShdGpHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for SHUTDOWN_GRACE_PERIOD_US config directives. See crinitConfigHandler_t.

◆ crinitCfgSyslogHandler()

int crinitCfgSyslogHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for USE_SYSLOG config directives. See crinitConfigHandler_t.

◆ crinitCfgTaskDirHandler()

int crinitCfgTaskDirHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for TASKDIR config directives. See crinitConfigHandler_t.

◆ crinitCfgTaskDirSlHandler()

int crinitCfgTaskDirSlHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for TASKDIR_FOLLOW_SYMLINKS config directives. See crinitConfigHandler_t.

◆ crinitCfgTasksHandler()

int crinitCfgTasksHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for TASKS config directives. See crinitConfigHandler_t.

◆ crinitCfgTaskSuffixHandler()

int crinitCfgTaskSuffixHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for TASK_SUFFIX config directives. See crinitConfigHandler_t.

◆ crinitDirExists()

static bool crinitDirExists ( const char *  path)
static

Check if a path exists, is accessible, and a directory.

Uses stat() with S_ISDIR().

Parameters
pathThe path to check.
Returns
true if path refers to an accessible directory, false otherwise.

◆ crinitTaskIncludeHandler()

int crinitTaskIncludeHandler ( void *  tgt,
const char *  val,
crinitConfigType_t  type 
)

Handler for INCLUDE config directives. See crinitConfigHandler_t.