mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-21 10:10:42 +01:00
janitor: add base plumbing
This commit is contained in:
parent
3805ff1712
commit
394d54987d
@ -30,12 +30,44 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "rsyslog.h"
|
||||
#include "janitor.h"
|
||||
|
||||
static struct janitorEtry *janitorRoot = NULL; /* TODO: move to runConf? */
|
||||
static pthread_mutex_t janitorMut = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
||||
rsRetVal
|
||||
janitorAddEtry(void (*cb)(void*), const char *id, void *pUsr)
|
||||
{
|
||||
struct janitorEtry *etry;
|
||||
DEFiRet;
|
||||
CHKmalloc(etry = malloc(sizeof(struct janitorEtry)));
|
||||
CHKmalloc(etry->id = strdup(id));
|
||||
etry->pUsr = pUsr;
|
||||
etry->cb = cb;
|
||||
etry->next = janitorRoot;
|
||||
pthread_mutex_lock(&janitorMut);
|
||||
janitorRoot = etry;
|
||||
pthread_mutex_unlock(&janitorMut);
|
||||
finalize_it:
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
/* run the janitor; all entries are processed */
|
||||
void
|
||||
janitorRun(void)
|
||||
{
|
||||
struct janitorEtry *curr;
|
||||
|
||||
dbgprintf("janitorRun() called\n");
|
||||
pthread_mutex_lock(&janitorMut);
|
||||
for(curr = janitorRoot ; curr != NULL ; curr = curr->next) {
|
||||
dbgprintf("janitor: processing entry %p, id '%s'\n",
|
||||
curr, curr->id);
|
||||
curr->cb(curr->pUsr);
|
||||
}
|
||||
pthread_mutex_unlock(&janitorMut);
|
||||
}
|
||||
|
||||
@ -21,7 +21,14 @@
|
||||
#ifndef INCLUDED_JANITOR_H
|
||||
#define INCLUDED_JANITOR_H
|
||||
|
||||
struct janitorEtry {
|
||||
struct janitorEtry *next;
|
||||
char *id; /* ID used to remove entry */
|
||||
void (*cb)(void *pUsr);
|
||||
void *pUsr; /* user-settable pointer (passed to callback) */
|
||||
};
|
||||
|
||||
rsRetVal janitorAddEtry(void (*cb)(void*), const char *id, void *pUsr);
|
||||
void janitorRun(void);
|
||||
|
||||
#endif /* #ifndef INCLUDED_JANITOR_H */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user