fix plugin loading

This commit is contained in:
Andreas Öman 2007-12-02 13:49:03 +00:00
parent 6f7d557ea1
commit d998138226
4 changed files with 59 additions and 1 deletions

View file

@ -27,7 +27,7 @@ CFLAGS += -I$(INCLUDES_INSTALL_BASE) $(HTS_CFLAGS)
CFLAGS += -Wno-deprecated-declarations
CFLAGS += -D_LARGEFILE64_SOURCE
CFLAGS += -DENABLE_INPUT_IPTV -DENABLE_INPUT_DVB -DENABLE_INPUT_V4L
LDFLAGS += -L$(LIBS_INSTALL_BASE)
LDFLAGS += -L$(LIBS_INSTALL_BASE) -rdynamic
SLIBS += ${LIBHTS_SLIBS}
DLIBS += ${LIBHTS_DLIBS}

3
main.c
View file

@ -54,6 +54,7 @@
#include "buffer.h"
#include "htmlui.h"
#include "avgen.h"
#include "plugin.h"
int running;
int xmltvreload;
@ -196,6 +197,8 @@ main(int argc, char **argv)
avgen_init();
plugin_init();
running = 1;
while(running) {

View file

@ -21,6 +21,8 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <dirent.h>
#include "tvhead.h"
#include "plugin.h"
@ -88,3 +90,54 @@ plugin_alloc(const char *name, void *opaque, size_t minsiz)
return p;
}
/**
*
*/
void
plugin_init(void)
{
const char *path;
char file[400];
DIR *dir;
struct dirent *d;
char *c;
void *h;
void (*ini)(void);
if((path = config_get_str("plugins", NULL)) == NULL)
return;
if((dir = opendir(path)) == NULL)
return;
while((d = readdir(dir)) != NULL) {
if(d->d_name[0] == '.')
continue;
if((c = strrchr(d->d_name, '.')) == NULL)
continue;
if(strcmp(c, ".so"))
continue;
snprintf(file, sizeof(file), "%s/%s", path, d->d_name);
h = dlopen(file, RTLD_NOW | RTLD_LOCAL);
if(h == NULL) {
syslog(LOG_ERR, "%s", dlerror());
continue;
}
ini = dlsym(h, "plugin_init");
if(ini == NULL) {
syslog(LOG_ERR, "Plugin \"%s\" lacks init function", file);
continue;
}
ini();
closedir(dir);
}
}

View file

@ -58,4 +58,6 @@ void plugin_aux_destroy(void *pa);
th_plugin_t *plugin_alloc(const char *name, void *opaque, size_t minsiz);
void plugin_init(void);
#endif /* PLUGIN_H_ */