Crinit -- Configurable Rootfs Init
Loading...
Searching...
No Matches
task.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#ifndef __TASK_H__
7#define __TASK_H__
8
9#include <stdint.h>
10#include <sys/types.h>
11#include <time.h>
12
13#include "confparse.h"
14#include "crinit-sdefs.h"
15#include "envset.h"
16#include "ioredir.h"
17
18#ifdef ENABLE_CGROUP
19#include "cgroup.h"
20#endif
21
23typedef unsigned long crinitTaskOpts_t;
25#define CRINIT_TASK_OPT_RESPAWN (1 << 0)
27#define CRINIT_TASK_OPT_RESPAWN_DEFAULT false
29#define CRINIT_TASK_OPT_TRIGGER_REARM (1 << 1)
31#define CRINIT_TASK_OPT_TRIGGER_REARM_DEFAULT false
32
34#define CRINIT_TASK_EVENT_RUNNING "spawn"
36#define CRINIT_TASK_EVENT_DONE "wait"
38#define CRINIT_TASK_EVENT_FAILED "fail"
40#define CRINIT_TASK_EVENT_NOTIFY_SUFFIX "-notified"
41
49
58
62typedef struct crinitTaskCmd {
63 int argc;
64 char **argv;
66
70typedef struct crinitTaskDep {
71 char *name;
72 char *event;
74
82
86typedef struct crinitTask {
87 char *name;
89 size_t cmdsSize;
91 size_t stopCmdsSize;
95 size_t depsSize;
97 size_t trigSize;
98 bool triggered;
100 size_t prvSize;
103 pid_t pid;
105 size_t redirsSize;
111 struct timespec createTime;
112 struct timespec startTime;
113 struct timespec endTime;
114 uid_t user;
115 gid_t group;
116 gid_t *supGroups;
118 char *username;
119 char *groupname;
120#ifdef ENABLE_CAPABILITIES
121 uint64_t capabilitiesSet;
122 uint64_t capabilitiesClear;
123#endif
124#ifdef ENABLE_CGROUP
125 crinitCgroup_t *cgroup;
126#endif
128
135#define crinitTaskForEachDep(task, dep) for ((dep) = (task)->deps; (dep) != (task)->deps + (task)->depsSize; (dep)++)
136
143#define crinitTaskForEachTrig(task, trg) for ((trg) = (task)->trig; (trg) != (task)->trig + (task)->trigSize; (trg)++)
144
157
166
173
185int crinitTaskDup(crinitTask_t **out, const crinitTask_t *orig);
186
195int crinitTaskCopy(crinitTask_t *out, const crinitTask_t *orig);
196
211int crinitTaskMergeInclude(crinitTask_t *tgt, const char *src, char *importList);
212
213#endif /* __TASK_H__ */
Header defining the data structures for cgroup support.
Header related to the Config Parser.
Definitions shared between crinit's public and internal APIs.
unsigned long crinitTaskState_t
Type to store Task state bitmask.
Definition crinit-sdefs.h:17
Header defining data types and functions to work with sets of environment variables.
Header related to IO redirection types and functions.
Definition confparse.h:212
Definition envset.h:25
Definition ioredir.h:14
Definition task.h:62
char ** argv
String array containing the program arguments, argv[0] contains absolute path to executable.
Definition task.h:64
int argc
Number of arguments within argv.
Definition task.h:63
Definition task.h:70
char * event
Dependency event.
Definition task.h:72
char * name
Dependency name.
Definition task.h:71
Definition task.h:78
char * name
Name of the provided feature.
Definition task.h:79
crinitTaskState_t stateReq
The task state required to be reached to provide the feature.
Definition task.h:80
Definition task.h:86
uid_t user
The user id to run the task's commands with.
Definition task.h:114
size_t stopCmdsSize
Number of commands in stopCmds array.
Definition task.h:91
struct timespec endTime
The time the task last became 'done' or 'failed.
Definition task.h:113
crinitTaskDep_t * deps
Dynamic array of dependencies, corresponds to DEPENDS in the config file.
Definition task.h:94
size_t depsSize
Number of dependencies in deps array.
Definition task.h:95
size_t trigSize
Number of trigger in trig array.
Definition task.h:97
bool triggered
Task was triggered (or no trigger where set) and can be run.
Definition task.h:98
struct timespec createTime
The time the task was created (i.e. has been loaded and parsed).
Definition task.h:111
int failCount
Definition task.h:108
size_t redirsSize
Number of IO redirections.
Definition task.h:105
gid_t * supGroups
Dynamic array of supplementary group IDs.
Definition task.h:116
pid_t pid
PID of currently running process subordinate to the task, if any.
Definition task.h:103
crinitIoRedir_t * redirs
IO redirection descriptions.
Definition task.h:104
size_t supGroupsSize
Number of supplementary group IDs in supGroups.
Definition task.h:117
char * groupname
The groupname to run the task's commands with.
Definition task.h:119
crinitTaskDep_t * trig
Dynamic array of trigger, corresponds to TRIGGER in the config file.
Definition task.h:96
gid_t group
The group id to run the task's commands with.
Definition task.h:115
crinitEnvSet_t taskEnv
Environment variables valid for each COMMAND in this task.
Definition task.h:92
size_t cmdsSize
Number of commands in cmds array.
Definition task.h:89
char * username
The username to run the task's commands with.
Definition task.h:118
int maxRetries
Definition task.h:106
crinitTaskPrv_t * prv
Dynamic array of provided features, corresponds to PROVIDES in the config file.
Definition task.h:99
crinitTaskCmd_t * stopCmds
Dynamic array of commands, corresponds to STOP_COMMAND[N] in the config file.
Definition task.h:90
bool inhibitRespawn
If task was stopped via user interaction, do not respawn it.
Definition task.h:110
struct timespec startTime
The time the task last became 'running'.
Definition task.h:112
char * name
Name of the task, corresponds to NAME in the config file.
Definition task.h:87
size_t prvSize
Number of provided features in prv array.
Definition task.h:100
crinitEnvSet_t elosFilters
Elos filter definitions valid for use in dependencies of this task.
Definition task.h:93
crinitTaskState_t state
Task state.
Definition task.h:102
crinitTaskCmd_t * cmds
Dynamic array of commands, corresponds to COMMAND[N] in the config file.
Definition task.h:88
crinitTaskOpts_t opts
Task options.
Definition task.h:101
int crinitTaskCopy(crinitTask_t *out, const crinitTask_t *orig)
Definition task.c:102
void crinitDestroyTask(crinitTask_t *t)
Definition task.c:314
struct crinitTaskCmd crinitTaskCmd_t
unsigned long crinitTaskOpts_t
Definition task.h:23
struct crinitTask crinitTask_t
void crinitFreeTask(crinitTask_t *t)
Definition task.c:306
enum crinitTaskTimestampType crinitTaskTimestampType_t
int crinitTaskCreateFromConfKvList(crinitTask_t **out, const crinitConfKvList_t *in)
Definition task.c:43
enum crinitTaskType crinitTaskType_t
struct crinitTaskPrv crinitTaskPrv_t
crinitTaskType
Definition task.h:45
@ CRINIT_TASK_TYPE_INCLUDE
An in-memory representation of an include file after parsing.
Definition task.h:47
@ CRINIT_TASK_TYPE_STANDARD
A standard in-memory representation of a task.
Definition task.h:46
int crinitTaskMergeInclude(crinitTask_t *tgt, const char *src, char *importList)
Definition task.c:374
crinitTaskTimestampType
Definition task.h:53
@ CRINIT_TASK_TS_END
End timestamp, i.e. the last time the task either failed or was completed.
Definition task.h:56
@ CRINIT_TASK_TS_CREATION
Creation timestamp, i.e. when the task was done loading/parsing.
Definition task.h:54
@ CRINIT_TASK_TS_START
Start timestamp, i.e. when the first command of the task was last started.
Definition task.h:55
int crinitTaskDup(crinitTask_t **out, const crinitTask_t *orig)
Definition task.c:289
struct crinitTaskDep crinitTaskDep_t