helper.cc

Go to the documentation of this file.
00001 /*
00002  * This file is part of openSDK.
00003  *
00004  * Copyright (C) 2006-2007 openSDK team
00005  *
00006  * openSDK is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; version 2.
00009  *
00010  * openSDK is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with openSDK; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  *     $Id: helper.cc,v 1.5 2007/07/16 13:09:00 nuno-lopes Exp $
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         // load the module and call the entry-point function
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         ; // from dlopen_flags
00053 
00054         void *handle = dlopen(args->mod_name.c_str(), dlopen_flags);
00055         // compatibility with GDB: don't delete the library file because GDB reads the file multiple times
00056         // unlink(args->mod_name.c_str());
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 }

Generated on Sun Dec 2 23:04:28 2007 for openSDK by  doxygen 1.3.9.1