Crinit -- Configurable Rootfs Init
globopt.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
7 #ifndef __GLOBOPT_H__
8 #define __GLOBOPT_H__
9 
10 #include <stdbool.h>
11 #include <string.h>
12 
13 #include "envset.h"
14 
18 typedef struct crinitGlobOptStore_t {
19  bool debug;
20  bool useSyslog;
21  bool useElos;
22  int elosPort;
23  char *elosServer;
24  char *inclDir;
25  char *inclSuffix;
26  unsigned long long shdGraceP;
30 
31 #define CRINIT_GLOBOPT_DEBUG debug
32 #define CRINIT_GLOBOPT_USE_SYSLOG useSyslog
33 #define CRINIT_GLOBOPT_USE_ELOS useElos
34 #define CRINIT_GLOBOPT_ELOS_PORT elosPort
35 #define CRINIT_GLOBOPT_ELOS_SERVER elosServer
36 #define CRINIT_GLOBOPT_INCLDIR inclDir
37 #define CRINIT_GLOBOPT_INCL_SUFFIX inclSuffix
38 #define CRINIT_GLOBOPT_SHDGRACEP shdGraceP
39 #define CRINIT_GLOBOPT_ENV globEnv
40 #define CRINIT_GLOBOPT_FILTERS globFilters
41 
43 static crinitGlobOptStore_t crinitGenericGlobOptHelper __attribute__((unused));
44 
45 // clang-format off
46 // Rationale: Used version of clang-format does not format _Generic macros correctly. This is a known bug and has been
47 // fixed very recently. We may remove this exemption once we are on the new clang version as standard.
48 // See: https://github.com/llvm/llvm-project/issues/18080
61 #define crinitGlobOptGet(globOptMember, retPtr) \
62  _Generic((crinitGenericGlobOptHelper.globOptMember), \
63  char * : crinitGlobOptGetString, \
64  bool : crinitGlobOptGetBoolean, \
65  int : crinitGlobOptGetInteger, \
66  unsigned long long : crinitGlobOptGetUnsignedLL, \
67  crinitEnvSet_t : crinitGlobOptGetEnvSet) \
68  ((offsetof(crinitGlobOptStore_t, globOptMember)), (retPtr))
80 #define crinitGlobOptSet(globOptMember, val) \
81  _Generic((crinitGenericGlobOptHelper.globOptMember), \
82  char * : crinitGlobOptSetString, \
83  const char * : crinitGlobOptSetString, \
84  bool : crinitGlobOptSetBoolean, \
85  int : crinitGlobOptSetInteger, \
86  unsigned long long : crinitGlobOptSetUnsignedLL, \
87  crinitEnvSet_t : crinitGlobOptSetEnvSet) \
88  ((offsetof(crinitGlobOptStore_t, globOptMember)), (val))
89 // clang-format on
90 
98 int crinitGlobOptInitDefault(void);
99 
105 void crinitGlobOptDestroy(void);
106 
122 int crinitGlobOptRemit(void);
123 
135 int crinitGlobOptSetString(size_t memberOffset, const char *val);
147 int crinitGlobOptSetBoolean(size_t memberOffset, bool val);
159 int crinitGlobOptSetInteger(size_t memberOffset, int val);
171 int crinitGlobOptSetUnsignedLL(size_t memberOffset, unsigned long long val);
183 int crinitGlobOptSetEnvSet(size_t memberOffset, const crinitEnvSet_t *val);
184 
199 int crinitGlobOptGetString(size_t memberOffset, char **val);
211 int crinitGlobOptGetBoolean(size_t memberOffset, bool *val);
223 int crinitGlobOptGetInteger(size_t memberOffset, int *val);
235 int crinitGlobOptGetUnsignedLL(size_t memberOffset, unsigned long long *val);
247 int crinitGlobOptGetEnvSet(size_t memberOffset, crinitEnvSet_t *val);
248 
249 #endif /* __GLOBOPT_H__ */
Header defining data types and functions to work with sets of environment variables.
int crinitGlobOptGetBoolean(size_t memberOffset, bool *val)
Definition: globopt.c:136
int crinitGlobOptGetInteger(size_t memberOffset, int *val)
Definition: globopt.c:158
int crinitGlobOptRemit(void)
Definition: globopt.c:238
int crinitGlobOptSetString(size_t memberOffset, const char *val)
Definition: globopt.c:84
crinitGlobOptStore_t * crinitGlobOptBorrow(void)
Definition: globopt.c:230
struct crinitGlobOptStore_t crinitGlobOptStore_t
int crinitGlobOptInitDefault(void)
Definition: globopt.c:40
int crinitGlobOptSetEnvSet(size_t memberOffset, const crinitEnvSet_t *val)
Definition: globopt.c:191
int crinitGlobOptGetString(size_t memberOffset, char **val)
Definition: globopt.c:103
int crinitGlobOptGetEnvSet(size_t memberOffset, crinitEnvSet_t *val)
Definition: globopt.c:213
int crinitGlobOptSetBoolean(size_t memberOffset, bool val)
Definition: globopt.c:125
int crinitGlobOptGetUnsignedLL(size_t memberOffset, unsigned long long *val)
Definition: globopt.c:180
void crinitGlobOptDestroy(void)
Definition: globopt.c:249
int crinitGlobOptSetInteger(size_t memberOffset, int val)
Definition: globopt.c:147
static crinitGlobOptStore_t crinitGenericGlobOptHelper __attribute__((unused))
int crinitGlobOptSetUnsignedLL(size_t memberOffset, unsigned long long val)
Definition: globopt.c:169
Definition: envset.h:25
Definition: globopt.h:18
int elosPort
Value for the ELOS_PORT global option.
Definition: globopt.h:22
crinitEnvSet_t globFilters
Storage for global task filter variables.
Definition: globopt.h:28
char * inclDir
Value for the INCLUDEDIR global option.
Definition: globopt.h:24
unsigned long long shdGraceP
Value for the SHUTDOWN_GRACE_PERIOD_US global option.
Definition: globopt.h:26
char * elosServer
Value for the ELOS_SERVER global option.
Definition: globopt.h:23
bool debug
Value for the DEBUG global option.
Definition: globopt.h:19
bool useElos
Value for the USE_ELOS global option.
Definition: globopt.h:21
crinitEnvSet_t globEnv
Storage for global task environment variables.
Definition: globopt.h:27
char * inclSuffix
Value for the INCLUDE_SUFFIX global option.
Definition: globopt.h:25
bool useSyslog
Value for the USE_SYSLOG global option.
Definition: globopt.h:20