00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <iostream>
00023 #include <dlfcn.h>
00024 #include <OPENR/OSyslog.h>
00025 #include "helper.h"
00026
00027 using namespace std;
00028
00029 void* module_executor(void *arg)
00030 {
00031 BLOCK_SIGNALS()
00032 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
00033
00034 executorArg* args = (executorArg*)arg;
00035
00036 if (pthread_setspecific(perThreadKey, args->threadData)) {
00037 OSYSLOG1((osyslogERROR, "pthread_setspecific() failed"));
00038 return (void*)2;
00039 }
00040
00041 void* (*function)(void);
00042
00043
00044 {
00045 const int dlopen_flags = RTLD_LAZY
00046 #ifdef RTLD_LOCAL
00047 | RTLD_LOCAL
00048 #endif
00049 #ifdef RTLD_DEEPBIND
00050 | RTLD_DEEPBIND
00051 #endif
00052 ;
00053
00054 void *handle = dlopen(args->mod_name.c_str(), dlopen_flags);
00055
00056
00057
00058 if (!handle) {
00059 cerr << "error loading " << dlerror() << endl;
00060 exit(0x50);
00061 }
00062
00063 function = (void* (*)(void))dlsym(handle, "__start_module");
00064 if (!function) {
00065 cerr << "Critical error: Couldn't locate the entry point of " << args->mod_name << endl;
00066 dlclose(handle);
00067 exit(0x51);
00068 }
00069 }
00070
00071 delete args;
00072
00073 return function();
00074 }