Crinit -- Configurable Rootfs Init
globopt.h File Reference

(2023-11-21, commit: e767693)

Header related to global option storage. More...

#include <stdbool.h>
#include <string.h>
#include "envset.h"
Include dependency graph for globopt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  crinitGlobOptStore_t
 

Macros

#define CRINIT_GLOBOPT_DEBUG   debug
 DEBUG global option. More...
 
#define CRINIT_GLOBOPT_USE_SYSLOG   useSyslog
 USE_SYSLOG global option. More...
 
#define CRINIT_GLOBOPT_USE_ELOS   useElos
 USE_ELOS global option. More...
 
#define CRINIT_GLOBOPT_ELOS_PORT   elosPort
 ELOS_PORT global option. More...
 
#define CRINIT_GLOBOPT_ELOS_SERVER   elosServer
 ELOS_SERVER global option. More...
 
#define CRINIT_GLOBOPT_INCLDIR   inclDir
 INCLUDEDIR global option. More...
 
#define CRINIT_GLOBOPT_INCL_SUFFIX   inclSuffix
 INCLUDE_SUFFIX global option. More...
 
#define CRINIT_GLOBOPT_SHDGRACEP   shdGraceP
 SHUTDOWN_GRACE_PERIOD_US global option. More...
 
#define CRINIT_GLOBOPT_ENV   globEnv
 Reference to the global task environment. More...
 
#define CRINIT_GLOBOPT_FILTERS   globFilters
 Reference to the global task filters. More...
 
#define crinitGlobOptGet(globOptMember, retPtr)
 
#define crinitGlobOptSet(globOptMember, val)
 

Typedefs

typedef struct crinitGlobOptStore_t crinitGlobOptStore_t
 

Functions

static crinitGlobOptStore_t crinitGenericGlobOptHelper __attribute__ ((unused))
 
int crinitGlobOptInitDefault (void)
 
void crinitGlobOptDestroy (void)
 
crinitGlobOptStore_tcrinitGlobOptBorrow (void)
 
int crinitGlobOptRemit (void)
 
int crinitGlobOptSetString (size_t memberOffset, const char *val)
 
int crinitGlobOptSetBoolean (size_t memberOffset, bool val)
 
int crinitGlobOptSetInteger (size_t memberOffset, int val)
 
int crinitGlobOptSetUnsignedLL (size_t memberOffset, unsigned long long val)
 
int crinitGlobOptSetEnvSet (size_t memberOffset, const crinitEnvSet_t *val)
 
int crinitGlobOptGetString (size_t memberOffset, char **val)
 
int crinitGlobOptGetBoolean (size_t memberOffset, bool *val)
 
int crinitGlobOptGetInteger (size_t memberOffset, int *val)
 
int crinitGlobOptGetUnsignedLL (size_t memberOffset, unsigned long long *val)
 
int crinitGlobOptGetEnvSet (size_t memberOffset, crinitEnvSet_t *val)
 

Detailed Description

Header related to global option storage.

Macro Definition Documentation

◆ CRINIT_GLOBOPT_DEBUG

#define CRINIT_GLOBOPT_DEBUG   debug

DEBUG global option.

◆ CRINIT_GLOBOPT_ELOS_PORT

#define CRINIT_GLOBOPT_ELOS_PORT   elosPort

ELOS_PORT global option.

◆ CRINIT_GLOBOPT_ELOS_SERVER

#define CRINIT_GLOBOPT_ELOS_SERVER   elosServer

ELOS_SERVER global option.

◆ CRINIT_GLOBOPT_ENV

#define CRINIT_GLOBOPT_ENV   globEnv

Reference to the global task environment.

◆ CRINIT_GLOBOPT_FILTERS

#define CRINIT_GLOBOPT_FILTERS   globFilters

Reference to the global task filters.

◆ CRINIT_GLOBOPT_INCL_SUFFIX

#define CRINIT_GLOBOPT_INCL_SUFFIX   inclSuffix

INCLUDE_SUFFIX global option.

◆ CRINIT_GLOBOPT_INCLDIR

#define CRINIT_GLOBOPT_INCLDIR   inclDir

INCLUDEDIR global option.

◆ CRINIT_GLOBOPT_SHDGRACEP

#define CRINIT_GLOBOPT_SHDGRACEP   shdGraceP

SHUTDOWN_GRACE_PERIOD_US global option.

◆ CRINIT_GLOBOPT_USE_ELOS

#define CRINIT_GLOBOPT_USE_ELOS   useElos

USE_ELOS global option.

◆ CRINIT_GLOBOPT_USE_SYSLOG

#define CRINIT_GLOBOPT_USE_SYSLOG   useSyslog

USE_SYSLOG global option.

◆ crinitGlobOptGet

#define crinitGlobOptGet (   globOptMember,
  retPtr 
)
Value:
_Generic((crinitGenericGlobOptHelper.globOptMember), \
unsigned long long : crinitGlobOptGetUnsignedLL, \
((offsetof(crinitGlobOptStore_t, globOptMember)), (retPtr))
int crinitGlobOptGetBoolean(size_t memberOffset, bool *val)
Definition: globopt.c:136
int crinitGlobOptGetInteger(size_t memberOffset, int *val)
Definition: globopt.c:158
int crinitGlobOptGetString(size_t memberOffset, char **val)
Definition: globopt.c:103
int crinitGlobOptGetEnvSet(size_t memberOffset, crinitEnvSet_t *val)
Definition: globopt.c:213
int crinitGlobOptGetUnsignedLL(size_t memberOffset, unsigned long long *val)
Definition: globopt.c:180
Definition: envset.h:25
Definition: globopt.h:18

Type-generic macro to get the value of a given global option.

Thread-safe as all mapped function are thread-safe.

Parameters
globOptMemberOne of the member names of crinitGlobOptStore_t (or one of the CRINIT_GLOBOPT_* constants).
retPtrReturn pointer for value. Type depends on the chosen member of crinitGlobOptStore_t and is always &(member_type). In case of char ** (for a string) and crinitEnvSet_t * memory will be allocated.
Returns
0 on success, -1 otherwise

◆ crinitGlobOptSet

#define crinitGlobOptSet (   globOptMember,
  val 
)
Value:
_Generic((crinitGenericGlobOptHelper.globOptMember), \
const char * : crinitGlobOptSetString, \
unsigned long long : crinitGlobOptSetUnsignedLL, \
((offsetof(crinitGlobOptStore_t, globOptMember)), (val))
int crinitGlobOptSetString(size_t memberOffset, const char *val)
Definition: globopt.c:84
int crinitGlobOptSetEnvSet(size_t memberOffset, const crinitEnvSet_t *val)
Definition: globopt.c:191
int crinitGlobOptSetBoolean(size_t memberOffset, bool val)
Definition: globopt.c:125
int crinitGlobOptSetInteger(size_t memberOffset, int val)
Definition: globopt.c:147
int crinitGlobOptSetUnsignedLL(size_t memberOffset, unsigned long long val)
Definition: globopt.c:169

Type-generic macro to get the value of a given global option.

Thread-safe as all mapped function are thread-safe.

Parameters
globOptMemberOne of the member names of crinitGlobOptStore_t (or one of the CRINIT_GLOBOPT_* constants).
valValue to store. Type depends on the chosen member of crinitGlobOptStore_t. See function signatures of crinitGlobOptGet*().
Returns
0 on success, -1 otherwise

Typedef Documentation

◆ crinitGlobOptStore_t

Structure definition for the global option storage.

Function Documentation

◆ __attribute__()

static crinitGlobOptStore_t crinitGenericGlobOptHelper __attribute__ ( (unused)  )
static

Dummy instance for Generic Selection of members to work (see type-generic macros below).

◆ crinitGlobOptBorrow()

crinitGlobOptStore_t* crinitGlobOptBorrow ( void  )

Provide direct thread-safe access to the central global option storage.

Calling thread will hold an exclusive lock on the central instance of crinitGlobOptStore_t. After the calling thread has finished its operations on the global option storage, it must release the lock using crinitGlobOptRemit().

Returns
A pointer to the central instance of crinitGlobOptStore_t on success, a NULL pointer if the lock could not be acquired.

◆ crinitGlobOptDestroy()

void crinitGlobOptDestroy ( void  )

Deletes all set global options from storage.

Any allocated memory is freed. The function uses mutexes internally and is thread-safe.

◆ crinitGlobOptGetBoolean()

int crinitGlobOptGetBoolean ( size_t  memberOffset,
bool *  val 
)

Retrieves a boolean value from a global option.

Consider using the type-generic macro crinitGlobOptGet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valReturn pointer for the retrieved boolean value.
Returns
0 on success, -1 on error

◆ crinitGlobOptGetEnvSet()

int crinitGlobOptGetEnvSet ( size_t  memberOffset,
crinitEnvSet_t val 
)

Retrieves a crinitEnvSet_t value from a global option.

Consider using the type-generic macro crinitGlobOptGet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valPointer to the crinitEnvSet_t instance to which the global one will be duplicated.
Returns
0 on success, -1 on error

◆ crinitGlobOptGetInteger()

int crinitGlobOptGetInteger ( size_t  memberOffset,
int *  val 
)

Retrieves an integer value from a global option.

Consider using the type-generic macro crinitGlobOptGet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valReturn pointer for the retrieved integer value.
Returns
0 on success, -1 on error

◆ crinitGlobOptGetString()

int crinitGlobOptGetString ( size_t  memberOffset,
char **  val 
)

Retrieves a string value from a global option.

Consider using the type-generic macro crinitGlobOptGet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Will allocate memory for the returned string. When no longer in use, free() should be called on the returned pointer to free the memory.

Parameters
memberOffsetThe offset of the member of the global option struct to set.
valReturn pointer for the retrieved string. Memory will be allocated.
Returns
0 on success, -1 on error

◆ crinitGlobOptGetUnsignedLL()

int crinitGlobOptGetUnsignedLL ( size_t  memberOffset,
unsigned long long *  val 
)

Retrieves an unsigned long long value from a global option.

Consider using the type-generic macro crinitGlobOptGet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valReturn pointer for the unsigned long long integer value.
Returns
0 on success, -1 on error

◆ crinitGlobOptInitDefault()

int crinitGlobOptInitDefault ( void  )

Sets global options to their default values.

Uses crinitGlobOptSet() and is therefore thread-safe.

Returns
0 on success, -1 otherwise

◆ crinitGlobOptRemit()

int crinitGlobOptRemit ( void  )

Release the lock on the global option storage acquired via crinitGlobOptBorrow().

Returns
0 on success, -1 if the lock could not be released.

◆ crinitGlobOptSetBoolean()

int crinitGlobOptSetBoolean ( size_t  memberOffset,
bool  val 
)

Stores a boolean value for a global option.

Consider using the type-generic macro crinitGlobOptSet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valThe boolean value to store.
Returns
0 on success, -1 on error

◆ crinitGlobOptSetEnvSet()

int crinitGlobOptSetEnvSet ( size_t  memberOffset,
const crinitEnvSet_t val 
)

Stores a crinitEnvSet_t value for a global option.

Consider using the type-generic macro crinitGlobOptSet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valPointer to the crinitEnvSet_t which shall be stored.
Returns
0 on success, -1 on error

◆ crinitGlobOptSetInteger()

int crinitGlobOptSetInteger ( size_t  memberOffset,
int  val 
)

Stores an integer value for a global option.

Consider using the type-generic macro crinitGlobOptSet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valThe boolean value to store.
Returns
0 on success, -1 on error

◆ crinitGlobOptSetString()

int crinitGlobOptSetString ( size_t  memberOffset,
const char *  val 
)

Stores a string value for a global option.

Consider using the type-generic macro crinitGlobOptSet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe offset of the member of the global option struct to set.
valThe string value to store, must be null-terminated.
Returns
0 on success, -1 on error

◆ crinitGlobOptSetUnsignedLL()

int crinitGlobOptSetUnsignedLL ( size_t  memberOffset,
unsigned long long  val 
)

Stores an unsigned long long value for a global option.

Consider using the type-generic macro crinitGlobOptSet() which can be used with member names instead of offsets. Will lock the global option storage as long as needed and is thread-safe.

Parameters
memberOffsetThe global option to set.
valThe unsigned long long integer value to store.
Returns
0 on success, -1 on error