Crinit -- Configurable Rootfs Init
|
Implementation of global option storage. More...
#include "globopt.h"
#include <pthread.h>
#include <stdlib.h>
#include "common.h"
#include "logio.h"
Macros | |
#define | crinitGlobOptSetErrPrint(keyStr) crinitErrPrint("Could not set default value for global option '%s'.", (keyStr)) |
#define | crinitGlobOptCommonLock() |
#define | crinitGlobOptCommonUnlock() |
Functions | |
int | crinitGlobOptInitDefault (void) |
int | crinitGlobOptSetString (size_t memberOffset, const char *val) |
int | crinitGlobOptGetString (size_t memberOffset, char **val) |
int | crinitGlobOptSetBoolean (size_t memberOffset, bool val) |
int | crinitGlobOptGetBoolean (size_t memberOffset, bool *val) |
int | crinitGlobOptSetInteger (size_t memberOffset, int val) |
int | crinitGlobOptGetInteger (size_t memberOffset, int *val) |
int | crinitGlobOptSetUnsignedLL (size_t memberOffset, unsigned long long val) |
int | crinitGlobOptGetUnsignedLL (size_t memberOffset, unsigned long long *val) |
int | crinitGlobOptSetEnvSet (size_t memberOffset, const crinitEnvSet_t *val) |
int | crinitGlobOptGetEnvSet (size_t memberOffset, crinitEnvSet_t *val) |
crinitGlobOptStore_t * | crinitGlobOptBorrow (void) |
int | crinitGlobOptRemit (void) |
void | crinitGlobOptDestroy (void) |
Variables | |
static crinitGlobOptStore_t | crinitGlobOpts |
static pthread_mutex_t | crinitOptLock = PTHREAD_MUTEX_INITIALIZER |
Implementation of global option storage.
#define crinitGlobOptCommonLock | ( | ) |
Common boilerplate to acquire a lock on the global option storage.
#define crinitGlobOptCommonUnlock | ( | ) |
Common boilerplate to release a lock on the global option storage.
#define crinitGlobOptSetErrPrint | ( | keyStr | ) | crinitErrPrint("Could not set default value for global option '%s'.", (keyStr)) |
Common error message for crinitGlobOptInitDefault().
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().
void crinitGlobOptDestroy | ( | void | ) |
Deletes all set global options from storage.
Any allocated memory is freed. The function uses mutexes internally and is thread-safe.
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.
memberOffset | The global option to set. |
val | Return pointer for the retrieved boolean value. |
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.
memberOffset | The global option to set. |
val | Pointer to the crinitEnvSet_t instance to which the global one will be duplicated. |
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.
memberOffset | The global option to set. |
val | Return pointer for the retrieved integer value. |
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.
memberOffset | The offset of the member of the global option struct to set. |
val | Return pointer for the retrieved string. Memory will be allocated. |
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.
memberOffset | The global option to set. |
val | Return pointer for the unsigned long long integer value. |
int crinitGlobOptInitDefault | ( | void | ) |
Sets global options to their default values.
Uses crinitGlobOptSet() and is therefore thread-safe.
int crinitGlobOptRemit | ( | void | ) |
Release the lock on the global option storage acquired via crinitGlobOptBorrow().
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.
memberOffset | The global option to set. |
val | The boolean value to store. |
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.
memberOffset | The global option to set. |
val | Pointer to the crinitEnvSet_t which shall be stored. |
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.
memberOffset | The global option to set. |
val | The boolean value to store. |
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.
memberOffset | The offset of the member of the global option struct to set. |
val | The string value to store, must be null-terminated. |
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.
memberOffset | The global option to set. |
val | The unsigned long long integer value to store. |
|
static |
Central global option storage.
|
static |
Mutex to synchronize access to globOptArr