Crinit -- Configurable Rootfs Init
task.c File Reference

(2023-08-28, commit: c9b21e6)

Implementation of functions related to a single task. More...

#include "task.h"
#include <stdlib.h>
#include "common.h"
#include "confmap.h"
#include "globopt.h"
#include "logio.h"
Include dependency graph for task.c:

Functions

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

Detailed Description

Implementation of functions related to a single task.

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

◆ crinitTaskSetFromConfKvList()

static int crinitTaskSetFromConfKvList ( crinitTask_t tgt,
const crinitConfKvList_t src,
crinitTaskType_t  type,
char *  importList 
)
inlinestatic

Helper function to go through an crinitConfKvList_t and apply all contained settings to a target task.

Will call appropriate config handlers (see confhdl.h).

Parameters
tgtThe target task to be modified.
srcThe list of config parameters from a task config file.
typeThe crinitTaskType_t of the source task configuration file, i.e. if it is a regular task or an include file. Relevant for checking include safety of options and for importList behavior.
importListA comma-separated list of option names to be used from src. If NULL, all are used. Only relevant if type == CRINIT_TASK_TYPE_INCLUDE.
Returns
0 on success, -1 on error