Crinit -- Configurable Rootfs Init
elosio.c File Reference

(2023-08-28, commit: ff7b45d)

Implementation of elos connection. More...

#include "elosio.h"
#include <dlfcn.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include "common.h"
#include "confparse.h"
#include "globopt.h"
#include "list.h"
#include "logio.h"
#include "task.h"
#include "taskdb.h"
#include "thrpool.h"
Include dependency graph for elosio.c:

Classes

struct  crinitElosSession
 
struct  crinitElosEventVector
 
struct  crinitElosioFilterTask
 
struct  crinitElosioFilter
 
struct  crinitElosEventThread
 

Macros

#define CRINIT_ELOS_IDENT   "crinit"
 Identification string for crinit logging to syslog. More...
 
#define CRINIT_ELOS_LIBRARY   "libelos.so.0"
 Elos shared library name. More...
 
#define CRINIT_ELOS_DEPENDENCY   "@elos"
 Elos filter dependency prefix. More...
 
#define ELOS_ID_INVALID   0
 Invalid elos event queue ID constant. More...
 
#define crinitElosioTryExec(func, err_msg, ...)
 

Typedefs

typedef enum crinitSafuResultE_t crinitSafuResultE_t
 
typedef uint32_t crinitElosEventQueueId_t
 
typedef struct crinitElosSession crinitElosSession_t
 
typedef struct crinitElosEventVector crinitElosEventVector_t
 
typedef struct crinitElosioFilterTask crinitElosioFilterTask_t
 
typedef struct crinitElosioFilter crinitElosioFilter_t
 

Enumerations

enum  crinitSafuResultE_t { SAFU_RESULT_FAILED = -1 , SAFU_RESULT_OK = 0 , SAFU_RESULT_NOT_FOUND = 1 }
 

Functions

static void crinitElosioFilterDestroy (crinitElosioFilter_t *filter)
 
static int crinitElosioFilterRegister (crinitElosioFilterTask_t *filterTask, crinitElosioFilter_t *filter)
 
static int crinitElosioFilterUnregister (crinitElosioFilterTask_t *filterTask, crinitElosioFilter_t *filter)
 
static int crinitElosioFilterListClear (crinitElosioFilterTask_t *filterTask)
 
static int crinitElosioFilterTaskDestroy (crinitElosioFilterTask_t *filterTask)
 
static int crinitElosioFilterTaskListClear ()
 
static int crinitElosioFilterFromEnvSet (const crinitTask_t *task, const char *name, crinitElosioFilter_t **filter)
 
static int crinitElosioFilterSubscribe (crinitElosioFilter_t *filter)
 
static int crinitElosioFilterListSubscribe (void)
 
static int crinitElosioFilterUnsubscribe (crinitElosioFilter_t *filter)
 
static int crinitElosioFilterListUnsubscribe (void)
 
int crinitElosioTaskAdded (crinitTask_t *task)
 
static int crinitElosioDisconnect (void)
 
static void * crinitElosioEventListener (void *arg)
 
static int crinitElosioFetchElosSymbol (void *lp, const char *symbolName, void **symbol)
 
static int crinitElosioInitThreadContext (crinitTaskDB_t *taskDb, struct crinitElosEventThread *tinfo)
 
int crinitElosioActivate (crinitTaskDB_t *taskDb, bool sl)
 

Variables

static bool crinitUseElos
 Specifies if we should use syslog calls instead of FILE streams. More...
 
static struct crinitElosEventThread crinitTinfo
 
static crinitList_t crinitFilterTasks = CRINIT_LIST_INIT(crinitFilterTasks)
 
static pthread_mutex_t crinitElosioFilterTaskLock = PTHREAD_MUTEX_INITIALIZER
 
static pthread_mutex_t crinitElosioSessionLock = PTHREAD_MUTEX_INITIALIZER
 

Detailed Description

Implementation of elos connection.

Macro Definition Documentation

◆ CRINIT_ELOS_DEPENDENCY

#define CRINIT_ELOS_DEPENDENCY   "@elos"

Elos filter dependency prefix.

◆ CRINIT_ELOS_IDENT

#define CRINIT_ELOS_IDENT   "crinit"

Identification string for crinit logging to syslog.

◆ CRINIT_ELOS_LIBRARY

#define CRINIT_ELOS_LIBRARY   "libelos.so.0"

Elos shared library name.

◆ crinitElosioTryExec

#define crinitElosioTryExec (   func,
  err_msg,
  ... 
)

Macro to simplify checking for a valid elos session.

Will print an error message and return from the calling function with an error code if the session pointer is either null or the conn.

HINT: This uses a GNU extension of gcc to define a compound statement enclosed in parentheses.

Parameters
funcElos function to be called.
err_msgError message to be returned on error.

◆ ELOS_ID_INVALID

#define ELOS_ID_INVALID   0

Invalid elos event queue ID constant.

Typedef Documentation

◆ crinitElosEventQueueId_t

typedef uint32_t crinitElosEventQueueId_t

Type defition for elos event queue IDs.

◆ crinitElosEventVector_t

Elos event vector type.

◆ crinitElosioFilter_t

Definition of a single filter related to a task.

◆ crinitElosioFilterTask_t

Task that has unfulfilled filter dependencies.

◆ crinitElosSession_t

Elos session type.

◆ crinitSafuResultE_t

Possible elos return values.

Enumeration Type Documentation

◆ crinitSafuResultE_t

Possible elos return values.

Enumerator
SAFU_RESULT_FAILED 
SAFU_RESULT_OK 
SAFU_RESULT_NOT_FOUND 

Function Documentation

◆ crinitElosioActivate()

int crinitElosioActivate ( struct crinitTaskDB_t taskDb,
bool  sl 
)

Specify if Elos should be used.

By default, Crinit will not connect to elos. If this is set to true, however, Crinit will connect to the elos daemon.

Parameters
taskDbTask database to be informed if event occurs.
sltrue if elos should be used, false otherwise.
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioDisconnect()

static int crinitElosioDisconnect ( void  )
inlinestatic

Disconnect from elos daemon.

Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioEventListener()

static void* crinitElosioEventListener ( void *  arg)
static

◆ crinitElosioFetchElosSymbol()

static int crinitElosioFetchElosSymbol ( void *  lp,
const char *  symbolName,
void **  symbol 
)
inlinestatic

Fetches a single symbol from the elos client shared library.

Parameters
lpPointer to the elos shared library
symbolNameName of the symbol to be fetched
symbolFunction pointer to be assigned
Returns
Returns 1 on success, 0 otherwise.

◆ crinitElosioFilterDestroy()

static void crinitElosioFilterDestroy ( crinitElosioFilter_t filter)
static

Frees the heap allocated members of the filter.

Parameters
filterFilter to be destroyed.

◆ crinitElosioFilterFromEnvSet()

static int crinitElosioFilterFromEnvSet ( const crinitTask_t task,
const char *  name,
crinitElosioFilter_t **  filter 
)
static

Create and register a new elos event filter handle from a given environment set.

Parameters
taskTask to create elos filter for.
nameName of the filter to register.
filterPointer to the created filter.
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterListClear()

static int crinitElosioFilterListClear ( crinitElosioFilterTask_t filterTask)
static

Free the complete list of subscribed filters.

Parameters
filterTaskThe task owning this filter list.
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterListSubscribe()

static int crinitElosioFilterListSubscribe ( void  )
static

Subscribes all filters currently registered with elosio.

Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterListUnsubscribe()

static int crinitElosioFilterListUnsubscribe ( void  )
static

Extracts all filter defines for each task and creates a local elos filter handle, which will be used to subscribe for this filter.

Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterRegister()

static int crinitElosioFilterRegister ( crinitElosioFilterTask_t filterTask,
crinitElosioFilter_t filter 
)
static

Inserts an elos filter into the list of filter subscriptions.

Parameters
filterTaskTask to register the filter for.
filterFilter to be registered.
Returns
Returns 0 if the filter has been inserted, -1 otherwise.

◆ crinitElosioFilterSubscribe()

static int crinitElosioFilterSubscribe ( crinitElosioFilter_t filter)
inlinestatic

Subscribes the filter with elos.

Parameters
filterThe filter to subscribe.
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterTaskDestroy()

static int crinitElosioFilterTaskDestroy ( crinitElosioFilterTask_t filterTask)
static

Frees the heap allocated members of the filter task.

Parameters
filterTaskFilter task to be destroyed.
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterTaskListClear()

static int crinitElosioFilterTaskListClear ( )
static

Free the complete list of filter tasks.

Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterUnregister()

static int crinitElosioFilterUnregister ( crinitElosioFilterTask_t filterTask,
crinitElosioFilter_t filter 
)
static

Removes the given filter from the filter list.

Parameters
filterTaskTask to remove the filter from.
filterFilter to be destroyed.
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioFilterUnsubscribe()

static int crinitElosioFilterUnsubscribe ( crinitElosioFilter_t filter)
inlinestatic

Unsubscribes the filter from elos.

Parameters
filterThe filter to unsubscribe.
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioInitThreadContext()

static int crinitElosioInitThreadContext ( crinitTaskDB_t taskDb,
struct crinitElosEventThread tinfo 
)
static

Initializes the vtable managed within the elosio thread context.

Parameters
taskDbPointer to the crinit task database
tinfoElosio thread context
Returns
Returns 0 on success, -1 otherwise.

◆ crinitElosioTaskAdded()

int crinitElosioTaskAdded ( struct crinitTask_t task)

Hook which will be invoked if a new task has been added and will register the elos filters for this task.

Parameters
taskTask that has been added to elos.
Returns
Returns 0 on success, -1 otherwise.

Variable Documentation

◆ crinitElosioFilterTaskLock

pthread_mutex_t crinitElosioFilterTaskLock = PTHREAD_MUTEX_INITIALIZER
static

Mutex synchronizing elos filter task registration

◆ crinitElosioSessionLock

pthread_mutex_t crinitElosioSessionLock = PTHREAD_MUTEX_INITIALIZER
static

Mutex synchronizing elos connection

◆ crinitFilterTasks

crinitList_t crinitFilterTasks = CRINIT_LIST_INIT(crinitFilterTasks)
static

List of tasks with elos filter dependencies

◆ crinitTinfo

struct crinitElosEventThread crinitTinfo
static

◆ crinitUseElos

bool crinitUseElos
static
Initial value:
=
#define CRINIT_CONFIG_DEFAULT_USE_ELOS
Default value for USE_ELOS global option.
Definition: confparse.h:55

Specifies if we should use syslog calls instead of FILE streams.