Crinit -- Configurable Rootfs Init
confparse.h File Reference

(2023-08-28, commit: c9b21e6)

Header related to the Config Parser. More...

#include <stdbool.h>
#include <sys/types.h>
#include "fseries.h"
Include dependency graph for confparse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  crinitConfKvList_t
 

Macros

#define CRINIT_CONFIG_KEYSTR_TASKS   "TASKS"
 Config key for the list of task file names. More...
 
#define CRINIT_CONFIG_KEYSTR_INCLUDES   "INCLUDES"
 Config key for the list of task file names. More...
 
#define CRINIT_CONFIG_KEYSTR_TASKDIR_SYMLINKS    "TASKDIR_FOLLOW_SYMLINKS"
 configurations. More...
 
#define CRINIT_CONFIG_KEYSTR_DEBUG   "DEBUG"
 Config file key for DEBUG global option. More...
 
#define CRINIT_CONFIG_KEYSTR_TASKDIR   "TASKDIR"
 Config file key for TASKDIR global option. More...
 
#define CRINIT_CONFIG_KEYSTR_INCLDIR   "INCLUDEDIR"
 Config file key for INCLUDEDIR global option. More...
 
#define CRINIT_CONFIG_KEYSTR_SHDGRACEP    "SHUTDOWN_GRACE_PERIOD_US"
 Config file key for SHUTDOWN_GRACE_PERIOD_US global option. More...
 
#define CRINIT_CONFIG_KEYSTR_USE_SYSLOG   "USE_SYSLOG"
 Config file key for USE_SYSLOG global option. More...
 
#define CRINIT_CONFIG_KEYSTR_USE_ELOS   "USE_ELOS"
 Config file key for USE_ELOS global option. More...
 
#define CRINIT_CONFIG_KEYSTR_ELOS_SERVER   "ELOS_SERVER"
 Config file key for ELOS_SERVER global option. More...
 
#define CRINIT_CONFIG_KEYSTR_ELOS_PORT   "ELOS_PORT"
 Config file key for ELOS_PORT global option. More...
 
#define CRINIT_CONFIG_KEYSTR_INCL_SUFFIX   "INCLUDE_SUFFIX"
 Config file key for INCLUDE_SUFFIX global option. More...
 
#define CRINIT_CONFIG_KEYSTR_TASK_FILE_SUFFIX    "TASK_FILE_SUFFIX"
 Config key for the task file extension in dynamic configurations. More...
 
#define CRINIT_CONFIG_KEYSTR_COMMAND   "COMMAND"
 Config key to add a command to the task. More...
 
#define CRINIT_CONFIG_KEYSTR_DEPENDS   "DEPENDS"
 Config key to add dependencies to the task. More...
 
#define CRINIT_CONFIG_KEYSTR_ENV_SET   "ENV_SET"
 Config key to set an environment variable with. More...
 
#define CRINIT_CONFIG_KEYSTR_FILTER_DEFINE   "FILTER_DEFINE"
 Config key to define an elos filter. More...
 
#define CRINIT_CONFIG_KEYSTR_INCLUDE   "INCLUDE"
 Config key for file include directives. More...
 
#define CRINIT_CONFIG_KEYSTR_IOREDIR   "IO_REDIRECT"
 Config key for IO redirections. More...
 
#define CRINIT_CONFIG_KEYSTR_NAME   "NAME"
 Config key for the task name. More...
 
#define CRINIT_CONFIG_KEYSTR_PROVIDES   "PROVIDES"
 Config key for provided features. More...
 
#define CRINIT_CONFIG_KEYSTR_RESPAWN   "RESPAWN"
 Config key to set a task to be respawning. More...
 
#define CRINIT_CONFIG_KEYSTR_RESPAWN_RETRIES    "RESPAWN_RETRIES"
 Config key to set how often a task is allowed to respawn on failure. More...
 
#define CRINIT_CONFIG_DEFAULT_TASK_FILE_SUFFIX   ".crinit"
 Default filename extension of task files. More...
 
#define CRINIT_CONFIG_KEYSTR_INCL_FILE_SUFFIX    "INCL_FILE_SUFFIX"
 Config key for the task include file extension in dynamic configurations. More...
 
#define CRINIT_CONFIG_DEFAULT_INCL_FILE_SUFFIX   ".crincl"
 Default filename extension of task include files. More...
 
#define CRINIT_CONFIG_DEFAULT_DEBUG   false
 Default value for DEBUG global option. More...
 
#define CRINIT_CONFIG_DEFAULT_TASKDIR   "/etc/crinit"
 Default value for TASKDIR global option. More...
 
#define CRINIT_CONFIG_DEFAULT_TASKDIR_SYMLINKS   true
 
#define CRINIT_CONFIG_DEFAULT_INCLDIR   "/etc/crinit"
 Default value for INCLUDEDIR global option. More...
 
#define CRINIT_CONFIG_DEFAULT_SHDGRACEP   100000uLL
 Default value for SHUTDOWN_GRACE_PERIOD_US global option. More...
 
#define CRINIT_CONFIG_DEFAULT_USE_SYSLOG   false
 Default value for USE_SYSLOG global option. More...
 
#define CRINIT_CONFIG_DEFAULT_USE_ELOS   false
 Default value for USE_ELOS global option. More...
 
#define CRINIT_CONFIG_DEFAULT_ELOS_SERVER   "127.0.0.1"
 Default value for ELOS_SERVER global option. More...
 
#define CRINIT_CONFIG_DEFAULT_ELOS_PORT   54321
 Default value for ELOS_SERVER global option. More...
 
#define CRINIT_CONFIG_DEFAULT_INCL_SUFFIX   ".crincl"
 Default filename extension of include files. More...
 
#define CRINIT_CONFIG_STDOUT_NAME   "STDOUT"
 What stdout is called in task configs. More...
 
#define CRINIT_CONFIG_STDERR_NAME   "STDERR"
 What stderr is called in task configs. More...
 
#define CRINIT_CONFIG_STDIN_NAME   "STDIN"
 What stdin is called in task configs. More...
 

Typedefs

typedef enum crinitConfigs_t crinitConfigs_t
 
typedef enum crinitConfigType_t crinitConfigType_t
 
typedef struct crinitConfKvList_t crinitConfKvList_t
 

Enumerations

enum  crinitConfigs_t {
  CRINIT_CONFIG_COMMAND = 0 , CRINIT_CONFIG_DEBUG , CRINIT_CONFIG_DEPENDS , CRINIT_CONFIG_ELOS_PORT ,
  CRINIT_CONFIG_ELOS_SERVER , CRINIT_CONFIG_ENV_SET , CRINIT_CONFIG_FILTER_DEFINE , CRINIT_CONFIG_INCLUDE ,
  CRINIT_CONFIG_INCLUDE_SUFFIX , CRINIT_CONFIG_INCLUDEDIR , CRINIT_CONFIG_IOREDIR , CRINIT_CONFIG_NAME ,
  CRINIT_CONFIG_PROVIDES , CRINIT_CONFIG_RESPAWN , CRINIT_CONFIG_RESPAWN_RETRIES , CRINIT_CONFIG_SHDGRACEP ,
  CRINIT_CONFIG_TASK_FILE_SUFFIX , CRINIT_CONFIG_TASKDIR , CRINIT_CONFIG_TASKDIR_FOLLOW_SYMLINKS , CRINIT_CONFIG_TASKS ,
  CRINIT_CONFIG_USE_SYSLOG , CRINIT_CONFIG_USE_ELOS , CRINIT_CONFIGS_SIZE
}
 
enum  crinitConfigType_t { CRINIT_CONFIG_TYPE_SERIES , CRINIT_CONFIG_TYPE_TASK }
 

Functions

int crinitParseConf (crinitConfKvList_t **confList, const char *filename)
 
void crinitFreeConfList (crinitConfKvList_t *confList)
 
void crinitFreeArgvArray (char **inArgv)
 
int crinitLoadSeriesConf (crinitFileSeries_t *series, const char *filename)
 

Detailed Description

Header related to the Config Parser.

Macro Definition Documentation

◆ CRINIT_CONFIG_DEFAULT_DEBUG

#define CRINIT_CONFIG_DEFAULT_DEBUG   false

Default value for DEBUG global option.

◆ CRINIT_CONFIG_DEFAULT_ELOS_PORT

#define CRINIT_CONFIG_DEFAULT_ELOS_PORT   54321

Default value for ELOS_SERVER global option.

◆ CRINIT_CONFIG_DEFAULT_ELOS_SERVER

#define CRINIT_CONFIG_DEFAULT_ELOS_SERVER   "127.0.0.1"

Default value for ELOS_SERVER global option.

◆ CRINIT_CONFIG_DEFAULT_INCL_FILE_SUFFIX

#define CRINIT_CONFIG_DEFAULT_INCL_FILE_SUFFIX   ".crincl"

Default filename extension of task include files.

◆ CRINIT_CONFIG_DEFAULT_INCL_SUFFIX

#define CRINIT_CONFIG_DEFAULT_INCL_SUFFIX   ".crincl"

Default filename extension of include files.

◆ CRINIT_CONFIG_DEFAULT_INCLDIR

#define CRINIT_CONFIG_DEFAULT_INCLDIR   "/etc/crinit"

Default value for INCLUDEDIR global option.

◆ CRINIT_CONFIG_DEFAULT_SHDGRACEP

#define CRINIT_CONFIG_DEFAULT_SHDGRACEP   100000uLL

Default value for SHUTDOWN_GRACE_PERIOD_US global option.

◆ CRINIT_CONFIG_DEFAULT_TASK_FILE_SUFFIX

#define CRINIT_CONFIG_DEFAULT_TASK_FILE_SUFFIX   ".crinit"

Default filename extension of task files.

◆ CRINIT_CONFIG_DEFAULT_TASKDIR

#define CRINIT_CONFIG_DEFAULT_TASKDIR   "/etc/crinit"

Default value for TASKDIR global option.

◆ CRINIT_CONFIG_DEFAULT_TASKDIR_SYMLINKS

#define CRINIT_CONFIG_DEFAULT_TASKDIR_SYMLINKS   true

◆ CRINIT_CONFIG_DEFAULT_USE_ELOS

#define CRINIT_CONFIG_DEFAULT_USE_ELOS   false

Default value for USE_ELOS global option.

◆ CRINIT_CONFIG_DEFAULT_USE_SYSLOG

#define CRINIT_CONFIG_DEFAULT_USE_SYSLOG   false

Default value for USE_SYSLOG global option.

◆ CRINIT_CONFIG_KEYSTR_COMMAND

#define CRINIT_CONFIG_KEYSTR_COMMAND   "COMMAND"

Config key to add a command to the task.

◆ CRINIT_CONFIG_KEYSTR_DEBUG

#define CRINIT_CONFIG_KEYSTR_DEBUG   "DEBUG"

Config file key for DEBUG global option.

◆ CRINIT_CONFIG_KEYSTR_DEPENDS

#define CRINIT_CONFIG_KEYSTR_DEPENDS   "DEPENDS"

Config key to add dependencies to the task.

◆ CRINIT_CONFIG_KEYSTR_ELOS_PORT

#define CRINIT_CONFIG_KEYSTR_ELOS_PORT   "ELOS_PORT"

Config file key for ELOS_PORT global option.

◆ CRINIT_CONFIG_KEYSTR_ELOS_SERVER

#define CRINIT_CONFIG_KEYSTR_ELOS_SERVER   "ELOS_SERVER"

Config file key for ELOS_SERVER global option.

◆ CRINIT_CONFIG_KEYSTR_ENV_SET

#define CRINIT_CONFIG_KEYSTR_ENV_SET   "ENV_SET"

Config key to set an environment variable with.

◆ CRINIT_CONFIG_KEYSTR_FILTER_DEFINE

#define CRINIT_CONFIG_KEYSTR_FILTER_DEFINE   "FILTER_DEFINE"

Config key to define an elos filter.

◆ CRINIT_CONFIG_KEYSTR_INCL_FILE_SUFFIX

#define CRINIT_CONFIG_KEYSTR_INCL_FILE_SUFFIX    "INCL_FILE_SUFFIX"

Config key for the task include file extension in dynamic configurations.

◆ CRINIT_CONFIG_KEYSTR_INCL_SUFFIX

#define CRINIT_CONFIG_KEYSTR_INCL_SUFFIX   "INCLUDE_SUFFIX"

Config file key for INCLUDE_SUFFIX global option.

◆ CRINIT_CONFIG_KEYSTR_INCLDIR

#define CRINIT_CONFIG_KEYSTR_INCLDIR   "INCLUDEDIR"

Config file key for INCLUDEDIR global option.

◆ CRINIT_CONFIG_KEYSTR_INCLUDE

#define CRINIT_CONFIG_KEYSTR_INCLUDE   "INCLUDE"

Config key for file include directives.

◆ CRINIT_CONFIG_KEYSTR_INCLUDES

#define CRINIT_CONFIG_KEYSTR_INCLUDES   "INCLUDES"

Config key for the list of task file names.

◆ CRINIT_CONFIG_KEYSTR_IOREDIR

#define CRINIT_CONFIG_KEYSTR_IOREDIR   "IO_REDIRECT"

Config key for IO redirections.

◆ CRINIT_CONFIG_KEYSTR_NAME

#define CRINIT_CONFIG_KEYSTR_NAME   "NAME"

Config key for the task name.

◆ CRINIT_CONFIG_KEYSTR_PROVIDES

#define CRINIT_CONFIG_KEYSTR_PROVIDES   "PROVIDES"

Config key for provided features.

◆ CRINIT_CONFIG_KEYSTR_RESPAWN

#define CRINIT_CONFIG_KEYSTR_RESPAWN   "RESPAWN"

Config key to set a task to be respawning.

◆ CRINIT_CONFIG_KEYSTR_RESPAWN_RETRIES

#define CRINIT_CONFIG_KEYSTR_RESPAWN_RETRIES    "RESPAWN_RETRIES"

Config key to set how often a task is allowed to respawn on failure.

◆ CRINIT_CONFIG_KEYSTR_SHDGRACEP

#define CRINIT_CONFIG_KEYSTR_SHDGRACEP    "SHUTDOWN_GRACE_PERIOD_US"

Config file key for SHUTDOWN_GRACE_PERIOD_US global option.

◆ CRINIT_CONFIG_KEYSTR_TASK_FILE_SUFFIX

#define CRINIT_CONFIG_KEYSTR_TASK_FILE_SUFFIX    "TASK_FILE_SUFFIX"

Config key for the task file extension in dynamic configurations.

◆ CRINIT_CONFIG_KEYSTR_TASKDIR

#define CRINIT_CONFIG_KEYSTR_TASKDIR   "TASKDIR"

Config file key for TASKDIR global option.

◆ CRINIT_CONFIG_KEYSTR_TASKDIR_SYMLINKS

#define CRINIT_CONFIG_KEYSTR_TASKDIR_SYMLINKS    "TASKDIR_FOLLOW_SYMLINKS"

configurations.

Config key for the option to follow symbolic links from TASKDIR in dynamic

◆ CRINIT_CONFIG_KEYSTR_TASKS

#define CRINIT_CONFIG_KEYSTR_TASKS   "TASKS"

Config key for the list of task file names.

◆ CRINIT_CONFIG_KEYSTR_USE_ELOS

#define CRINIT_CONFIG_KEYSTR_USE_ELOS   "USE_ELOS"

Config file key for USE_ELOS global option.

◆ CRINIT_CONFIG_KEYSTR_USE_SYSLOG

#define CRINIT_CONFIG_KEYSTR_USE_SYSLOG   "USE_SYSLOG"

Config file key for USE_SYSLOG global option.

◆ CRINIT_CONFIG_STDERR_NAME

#define CRINIT_CONFIG_STDERR_NAME   "STDERR"

What stderr is called in task configs.

◆ CRINIT_CONFIG_STDIN_NAME

#define CRINIT_CONFIG_STDIN_NAME   "STDIN"

What stdin is called in task configs.

◆ CRINIT_CONFIG_STDOUT_NAME

#define CRINIT_CONFIG_STDOUT_NAME   "STDOUT"

What stdout is called in task configs.

Typedef Documentation

◆ crinitConfigs_t

Enumeration of all configuration keys. Goes together with crinitTaskCfgMap and crinitSeriesCfgMap.

◆ crinitConfigType_t

◆ crinitConfKvList_t

Linked list to hold key/value pairs read from the config file.

Enumeration Type Documentation

◆ crinitConfigs_t

Enumeration of all configuration keys. Goes together with crinitTaskCfgMap and crinitSeriesCfgMap.

Enumerator
CRINIT_CONFIG_COMMAND 
CRINIT_CONFIG_DEBUG 
CRINIT_CONFIG_DEPENDS 
CRINIT_CONFIG_ELOS_PORT 
CRINIT_CONFIG_ELOS_SERVER 
CRINIT_CONFIG_ENV_SET 
CRINIT_CONFIG_FILTER_DEFINE 
CRINIT_CONFIG_INCLUDE 
CRINIT_CONFIG_INCLUDE_SUFFIX 
CRINIT_CONFIG_INCLUDEDIR 
CRINIT_CONFIG_IOREDIR 
CRINIT_CONFIG_NAME 
CRINIT_CONFIG_PROVIDES 
CRINIT_CONFIG_RESPAWN 
CRINIT_CONFIG_RESPAWN_RETRIES 
CRINIT_CONFIG_SHDGRACEP 
CRINIT_CONFIG_TASK_FILE_SUFFIX 
CRINIT_CONFIG_TASKDIR 
CRINIT_CONFIG_TASKDIR_FOLLOW_SYMLINKS 
CRINIT_CONFIG_TASKS 
CRINIT_CONFIG_USE_SYSLOG 
CRINIT_CONFIG_USE_ELOS 
CRINIT_CONFIGS_SIZE 

◆ crinitConfigType_t

Enumerator
CRINIT_CONFIG_TYPE_SERIES 
CRINIT_CONFIG_TYPE_TASK 

Function Documentation

◆ crinitFreeArgvArray()

void crinitFreeArgvArray ( char **  inArgv)

Frees a string array with a backing string.

Parameters
inArgvThe string array to free, must be a double pointer with 2 allocations, one array of pointers and a single inner array of char.

◆ crinitFreeConfList()

void crinitFreeConfList ( crinitConfKvList_t confList)

Frees memory allocated for an crinitConfKvList_t by crinitParseConf().

Parameters
confListPointer to crinitConfKvList_t allocated by crinitParseConf() and not freed before. If confList is NULL, crinitFreeConfList() will return without freeing any memory.

◆ crinitLoadSeriesConf()

int crinitLoadSeriesConf ( crinitFileSeries_t series,
const char *  filename 
)

Parse a series file.

Will return the task config and include files to be loaded in series. Will also set any global options specified in the series file.

Parameters
seriesReturns the paths to the task configs specified in the series file (or scanned from TASKDIR, if configured).
filenameThe path to the series file to load.
Returns
0 on success, -1 on failure

◆ crinitParseConf()

int crinitParseConf ( crinitConfKvList_t **  confList,
const char *  filename 
)

Parse a config file into a crinitConfKvList_t.

Parses a config file and fills confList. Items of confList are dynamically allocated (grown) and need to be freed using free_confList(). The format of the config file is expected to be KEY1=VALUE1<newline>KEY2=VALUE2<newline>... Lines beginning with '#' are considered comments.

Parameters
confListwill return a pointer to dynamically allocated memory of a ConfKvList filled with the key/value-pairs from the config file.
filenamePath to the configuration file.
Returns
0 on success, -1 on error