module.c File Reference

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <strutil.h>
#include <configfile.h>
#include <hooks.h>
#include <log.h>

Include dependency graph for module.c:

Go to the source code of this file.

Data Structures

struct  _moditem

Typedefs

typedef int(* modfn_t )(void *, int, char **)
typedef _moditem moditem_t

Functions

int loadModule (char *aptr, char *ebuf, size_t ebsiz)

Variables

moditem_t ** mods = NULL
int modcnt = 0
void * moddata [] = {config,writeLog,inform,addLogHook,addLoopHook,NULL}


Typedef Documentation

typedef int(* modfn_t)(void *, int, char **)
 

Definition at line 19 of file module.c.

typedef struct _moditem moditem_t
 


Function Documentation

int loadModule char *  aptr,
char *  ebuf,
size_t  ebsiz
 

loadModule loads a shared object as a module for secwatch. the char ptr aptr is broken into an array of strings the first element of which is the name of the shared object.

Definition at line 42 of file module.c.

References count(), _moditem::entry, _moditem::modargs, modcnt, moddata, _moditem::modhand, _moditem::modname, mods, and split().

Referenced by readConfig().

00042                                                      {
00043      void *handle;
00044      modfn_t modfunc;
00045      char **argv, * modpath, *module, *error;
00046      int argc, mp;
00047      moditem_t x;
00048      
00049      if((argv = split(" ",aptr)) == NULL) 
00050           return -1;
00051      argc = count(argv);
00052      module = argv[0];
00053      if((handle = dlopen(module,RTLD_LAZY)) == NULL) {
00054           snprintf(ebuf,ebsiz,"module=%s, dlerror: %s",module,dlerror());
00055           return -1;
00056      }
00057      dlerror();
00058      *(void **)(&modfunc) = dlsym(handle,"secwmodinit");
00059      if((error = dlerror()) != NULL) {
00060           snprintf(ebuf,ebsiz,"module=%s, dlerror: %s",module,dlerror());
00061           return -1;
00062      }
00063      x.modname = module;
00064      x.modargs = argv;
00065      x.modhand = handle;
00066      x.entry = modfunc;
00067 
00068      mp = modcnt++;
00069      if((mods = realloc(mods,(sizeof(moditem_t *)*modcnt))) == NULL) {
00070           snprintf(ebuf,ebsiz,"Cannot load module %s: No space for module table",module);
00071           return -1;
00072      }
00073      if((mods[mp] = (moditem_t *) calloc(sizeof(moditem_t),1)) == NULL) {
00074           snprintf(ebuf,ebsiz,"Cannot load module %s: No space for module table entry",module);
00075           return -1;
00076      }
00077      *mods[mp] = x;
00078 
00079      modfunc(moddata,argc,argv);
00080      return 0;
00081 }

Here is the call graph for this function:


Variable Documentation

int modcnt = 0
 

Definition at line 29 of file module.c.

Referenced by loadModule().

void* moddata[] = {config,writeLog,inform,addLogHook,addLoopHook,NULL}
 

moddata is a vector array of pointers to config and functions to be passed to a loaded module on initialization

Definition at line 35 of file module.c.

Referenced by loadModule().

moditem_t** mods = NULL
 

Definition at line 28 of file module.c.

Referenced by loadModule().


Generated on Tue Oct 31 10:17:36 2006 for secwatch by  doxygen 1.4.6