Crinit -- Configurable Rootfs Init
task.h File Reference

(2023-08-28, commit: 9682b5c)

Header defining the data structures belonging to a single task and related functions. More...

#include "confparse.h"
#include "crinit-sdefs.h"
#include "envset.h"
#include "ioredir.h"
Include dependency graph for task.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  crinitTaskCmd_t
 
struct  crinitTaskDep_t
 
struct  crinitTaskPrv_t
 
struct  crinitTask_t
 

Macros

#define CRINIT_TASK_OPT_RESPAWN   (1 << 0)
 RESPAWN task option bitmask. More...
 
#define CRINIT_TASK_OPT_RESPAWN_DEFAULT   false
 Default value for RESPAWN option. More...
 
#define CRINIT_TASK_EVENT_RUNNING   "spawn"
 Dependency event that fires when a task reaches the RUNNING state. More...
 
#define CRINIT_TASK_EVENT_DONE   "wait"
 Dependency event that fires when a task reaches the DONE state. More...
 
#define CRINIT_TASK_EVENT_FAILED   "fail"
 Dependency event that fires when a task reaches the FAILED state. More...
 
#define CRINIT_TASK_EVENT_NOTIFY_SUFFIX    "-notified"
 Dependency event suffix to indicate the event needs to be generated by sd-notify. More...
 
#define crinitTaskForEachDep(task, dep)   for ((dep) = (task)->deps; (dep) != (task)->deps + (task)->depsSize; (dep)++)
 

Typedefs

typedef unsigned long crinitTaskOpts_t
 Type to store Task option bitmask. More...
 
typedef enum crinitTaskType_t crinitTaskType_t
 
typedef struct crinitTaskCmd_t crinitTaskCmd_t
 
typedef struct crinitTaskDep_t crinitTaskDep_t
 
typedef struct crinitTaskPrv_t crinitTaskPrv_t
 
typedef struct crinitTask_t crinitTask_t
 

Enumerations

enum  crinitTaskType_t { CRINIT_TASK_TYPE_STANDARD , CRINIT_TASK_TYPE_INCLUDE }
 

Functions

int crinitTaskCreateFromConfKvList (crinitTask_t **out, const crinitConfKvList_t *in)
 
void crinitFreeTask (crinitTask_t *t)
 
void crinitDestroyTask (crinitTask_t *t)
 
int crinitTaskDup (crinitTask_t **out, const crinitTask_t *orig)
 
int crinitTaskCopy (crinitTask_t *out, const crinitTask_t *orig)
 
int crinitTaskMergeInclude (crinitTask_t *tgt, const char *src, char *importList)
 

Detailed Description

Header defining the data structures belonging to a single task and related functions.

Macro Definition Documentation

◆ CRINIT_TASK_EVENT_DONE

#define CRINIT_TASK_EVENT_DONE   "wait"

Dependency event that fires when a task reaches the DONE state.

◆ CRINIT_TASK_EVENT_FAILED

#define CRINIT_TASK_EVENT_FAILED   "fail"

Dependency event that fires when a task reaches the FAILED state.

◆ CRINIT_TASK_EVENT_NOTIFY_SUFFIX

#define CRINIT_TASK_EVENT_NOTIFY_SUFFIX    "-notified"

Dependency event suffix to indicate the event needs to be generated by sd-notify.

◆ CRINIT_TASK_EVENT_RUNNING

#define CRINIT_TASK_EVENT_RUNNING   "spawn"

Dependency event that fires when a task reaches the RUNNING state.

◆ CRINIT_TASK_OPT_RESPAWN

#define CRINIT_TASK_OPT_RESPAWN   (1 << 0)

RESPAWN task option bitmask.

◆ CRINIT_TASK_OPT_RESPAWN_DEFAULT

#define CRINIT_TASK_OPT_RESPAWN_DEFAULT   false

Default value for RESPAWN option.

◆ crinitTaskForEachDep

#define crinitTaskForEachDep (   task,
  dep 
)    for ((dep) = (task)->deps; (dep) != (task)->deps + (task)->depsSize; (dep)++)

Given a crinitTask_t, iterate over all dependencies of this task.

Parameters
taskPointer to the task.
depPointer to the current dependency.

Typedef Documentation

◆ crinitTask_t

typedef struct crinitTask_t crinitTask_t

Type to store a single task.

◆ crinitTaskCmd_t

Type to store a single command within a task.

◆ crinitTaskDep_t

Type to store a single dependency within a task.

◆ crinitTaskOpts_t

typedef unsigned long crinitTaskOpts_t

Type to store Task option bitmask.

◆ crinitTaskPrv_t

Type to store a single provided feature within a task.

◆ crinitTaskType_t

Enumeration Type Documentation

◆ crinitTaskType_t

Enumerator
CRINIT_TASK_TYPE_STANDARD 
CRINIT_TASK_TYPE_INCLUDE 

Function Documentation

◆ crinitDestroyTask()

void crinitDestroyTask ( crinitTask_t t)

Frees memory for internal members of an crinitTask_t.

Parameters
tThe task whose members shall be freed.

◆ crinitFreeTask()

void crinitFreeTask ( crinitTask_t t)

Frees memory associated with an crinitTask created by crinitTaskCreateFromConfKvList() or crinitTaskDup().

Uses crinitDestroyTask() internally and then frees the given pointer.

Parameters
tPointer to the crinitTask to free.

◆ crinitTaskCopy()

int crinitTaskCopy ( crinitTask_t out,
const crinitTask_t orig 
)

Copies the conents from one task to another.

Parameters
outPointer to copy of orig.
origThe original task to copy.
Returns
0 on success, -1 on error

◆ crinitTaskCreateFromConfKvList()

int crinitTaskCreateFromConfKvList ( crinitTask_t **  out,
const crinitConfKvList_t in 
)

Given an crinitConfKvList_t created from a task config, build an equivalent crinitTask.

The crinitTask returned via out is dynamically allocated and should be freed using crinitFreeTask if no longer needed.

Parameters
outThe return pointer for the newly created task.
inThe crinitConfKvList_t from which to build the task.
Returns
0 on success, -1 on error

◆ crinitTaskDup()

int crinitTaskDup ( crinitTask_t **  out,
const crinitTask_t orig 
)

Duplicates an crinitTask.

The copy returned via out is dynamically allocated and should be freed using crinitFreeTask() if no longer needed.

Parameters
outDouble pointer to return a dynamically allocated copy of orig.
origThe original task to copy.
Returns
0 on success, -1 on error

◆ crinitTaskMergeInclude()

int crinitTaskMergeInclude ( crinitTask_t tgt,
const char *  src,
char *  importList 
)

Merges the options set in a given include file into the target crinitTask_t.

Uses the same parser handlers as regular task files but will fail if configuration options are encountered where crinitConfigMapping_t::includeSafe is false. Optionally a comma-separated importList can be specified. If given, only the configuration options in the list will be merged. If not given, everything in the include file will be imported.

Parameters
tgtThe target crinitTask_t which will be modified.
srcName of the include file to parse/merge (filename without leading path and ending).
importListA comma-separated list which configs to merge from the include file. NULL means everything.
Returns
0 on success, -1 on failure