Update of /cvsroot/opensdk/openSDK/loader
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23151
Modified Files:
helper.cc helper.h main.cc
Log Message:
move the dlopen+dlsym code to module_executor(), so that we can initialize some thread-specific vars before loading the modules
Index: helper.cc
===================================================================
RCS file: /cvsroot/opensdk/openSDK/loader/helper.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- helper.cc 26 Jan 2007 23:12:05 -0000 1.4
+++ helper.cc 16 Jul 2007 13:09:00 -0000 1.5
@@ -19,22 +19,55 @@
* $Id$
*/
+#include <iostream>
+#include <dlfcn.h>
#include <OPENR/OSyslog.h>
#include "helper.h"
+using namespace std;
+
void* module_executor(void *arg)
{
BLOCK_SIGNALS()
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
executorArg* args = (executorArg*)arg;
- void* (*function)(void) = args->function;
if (pthread_setspecific(perThreadKey, args->threadData)) {
OSYSLOG1((osyslogERROR, "pthread_setspecific() failed"));
return (void*)2;
}
+ void* (*function)(void);
+
+ // load the module and call the entry-point function
+ {
+ const int dlopen_flags = RTLD_LAZY
+#ifdef RTLD_LOCAL
+ | RTLD_LOCAL
+#endif
+#ifdef RTLD_DEEPBIND
+ | RTLD_DEEPBIND
+#endif
+ ; // from dlopen_flags
+
+ void *handle = dlopen(args->mod_name.c_str(), dlopen_flags);
+ // compatibility with GDB: don't delete the library file because GDB reads the file multiple times
+ // unlink(args->mod_name.c_str());
+
+ if (!handle) {
+ cerr << "error loading " << dlerror() << endl;
+ exit(0x50);
+ }
+
+ function = (void* (*)(void))dlsym(handle, "__start_module");
+ if (!function) {
+ cerr << "Critical error: Couldn't locate the entry point of " << args->mod_name << endl;
+ dlclose(handle);
+ exit(0x51);
+ }
+ }
+
delete args;
return function();
Index: main.cc
===================================================================
RCS file: /cvsroot/opensdk/openSDK/loader/main.cc,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- main.cc 15 Jul 2007 15:18:25 -0000 1.55
+++ main.cc 16 Jul 2007 13:09:00 -0000 1.56
@@ -97,15 +97,6 @@
/** load a module to memory and create a thread for it */
static bool load_module(const char* name)
{
- const int dlopen_flags = RTLD_LAZY
-#ifdef RTLD_LOCAL
- | RTLD_LOCAL
-#endif
-#ifdef RTLD_DEEPBIND
- | RTLD_DEEPBIND
-#endif
- ; // from dlopen_flags
-
char *path = resolve_case_insensitive_path(name);
string tmp_mod_name = path;
@@ -125,36 +116,19 @@
tmp_mod_name = cwd + string("/") + tmp_mod_name;
}
- void *handle = dlopen(tmp_mod_name.c_str(), dlopen_flags);
- // compatibility with GDB: don't delete the library file because GDB reads the file multiple times
- //unlink(tmp_mod_name.c_str());
-
- if (!handle) {
- cerr << "error loading " << dlerror() << endl;
- return false;
- }
-
- void* function = dlsym(handle, "__start_module");
- if (!function) {
- cerr << "Critical error: Couldn't locate the boot function" << endl;
- dlclose(handle);
- return false;
- }
-
size_t id = ThreadsList.size();
perThreadStruct* data = new perThreadStruct(id); // deleted in cleanup()
- executorArg* arg = new executorArg((void* (*)(void))function, data); // deleted in helper.cc
+ executorArg* arg = new executorArg(tmp_mod_name, data); // deleted in helper.cc
if (pthread_create(&(data->threadId), NULL, module_executor, arg)) {
cerr << "Couldn't create a new thread to load the module" << endl;
- dlclose(handle);
return false;
}
cout << "Loaded module: " << name << " (thread id: " << data->threadId << "::" << id << ")" << endl;
// for future cleanup
- dlopenHandlers.push(handle);
+// dlopenHandlers.push(handle);
ThreadsList.push_back(data);
return true;
Index: helper.h
===================================================================
RCS file: /cvsroot/opensdk/openSDK/loader/helper.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- helper.h 4 Feb 2007 18:01:23 -0000 1.4
+++ helper.h 16 Jul 2007 13:09:00 -0000 1.5
@@ -22,6 +22,7 @@
#include <ModuleData.h>
#include <pthread.h>
#include <signal.h>
+#include <string>
#define BLOCK_SIGNALS() { sigset_t set; sigfillset(&set); pthread_sigmask(SIG_SETMASK, &set, NULL); }
#define BLOCK_SIGNAL(s) { sigset_t set; sigemptyset(&set); sigaddset(&set, (s)); pthread_sigmask(SIG_SETMASK, &set, NULL); }
@@ -30,8 +31,8 @@
void* module_executor(void *ptr);
struct executorArg {
- executorArg(void* (*func)(void), perThreadStruct* data) : function(func), threadData(data) {}
+ executorArg(std::string name, perThreadStruct* data) : mod_name(name), threadData(data) {}
- void* (*function)(void);
+ std::string mod_name;
perThreadStruct* threadData;
};
|