Changeset 493

Show
Ignore:
Timestamp:
04/08/06 19:48:35 (3 years ago)
Author:
common
Message:

Nepenthes
- ModuleManager? dlopen() with RTLD_LOCAL, osx has RTLD_GLOBAL as default and segfaults therefore

osx manpage

RTLD_LOCAL Symbols exported from this image (dynamic library or bun-bundle)

dle) are generally hidden and only availble to dlsym() when
directly using the handle returned by this call to
dlopen(). If neither RTLD_GLOBAL nor RTLD_LOCAL is speci-specified,
fied, the default is RTLD_GLOBAL.

linux manpage
svn commit -m

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/nepenthes-core/src/ModuleManager.cpp

    r460 r493  
    2828/* $Id$ */ 
    2929 
    30 #ifdef WIN32 
    31  
    32 #else 
    3330#include <dlfcn.h> 
    34 #endif 
    3531 
    3632#include "ModuleManager.hpp" 
     
    165161bool ModuleManager::Exit() 
    166162{ 
    167 /*      list<Module *>::iterator it; 
    168         for( it = m_Modules.begin(); it != m_Modules.end(); it++ ) 
    169                 unregisterModule(&(*it)->getModuleName()); 
    170 */ 
    171  
    172         while(m_Modules.size() > 0) 
     163        while ( m_Modules.size() > 0 ) 
    173164        { 
    174165                void *handle = m_Modules.front()->getDlHandle(); 
    175166                m_Modules.front()->Exit(); 
    176                 if(m_Modules.front()->getConfig() != NULL) 
     167 
     168                if ( m_Modules.front()->getConfig() != NULL ) 
     169                { 
    177170                delete m_Modules.front()->getConfig(); 
    178                  
    179         delete m_Modules.front(); 
    180 #ifdef WIN32 
    181                 FreeLibrary((HINSTANCE)handle); 
    182 #else 
     171                } 
     172 
     173                delete m_Modules.front(); 
    183174                dlclose(handle); 
    184 #endif 
    185175                m_Modules.pop_front(); 
    186176        } 
     
    202192        bool retval=true; 
    203193 
    204 #ifdef WIN32 
    205         HMODULE handle; 
    206 #else 
    207194    void *handle; 
    208 #endif 
    209195 
    210196    typedef int32_t (*module_init_proc)(int32_t, Module**, Nepenthes *); 
    211197    module_init_proc module_init; 
    212198 
    213 #ifdef WIN32 
    214         handle = LoadLibrary(modulepath->c_str()); 
    215     if ( handle == NULL ) 
    216     { 
    217  
    218                 LPVOID lpMsgBuf; 
    219                 FormatMessage(  
    220                         FORMAT_MESSAGE_ALLOCATE_BUFFER |  
    221                         FORMAT_MESSAGE_FROM_SYSTEM |  
    222                         FORMAT_MESSAGE_IGNORE_INSERTS, 
    223                         NULL, 
    224                         GetLastError(), 
    225                         0, // Default language 
    226                         (LPTSTR) &lpMsgBuf, 
    227                         0, 
    228                         NULL  
    229                 ); 
    230         printf("LoadLibary %s\n",(char *)lpMsgBuf); 
    231         logCrit("%s\n","handle == NULL "); 
    232         return false; 
    233     } 
    234  
    235 #else     
    236         handle = dlopen (modulepath->c_str(), RTLD_NOW); 
     199        handle = dlopen (modulepath->c_str(), RTLD_NOW|RTLD_LOCAL); 
    237200 
    238201    if ( handle == NULL ) 
     
    242205        return false; 
    243206    } 
    244 #endif 
    245  
    246 #ifdef WIN32 
    247         (FARPROC&) module_init = GetProcAddress(handle, "module_init"); 
    248 #else 
     207 
    249208    module_init = (module_init_proc)dlsym(handle, "module_init"); 
    250 #endif 
    251209    if ( module_init == NULL ) 
    252210    { 
    253211        logCrit("%s\n","module_init == NULL" ); 
    254  
    255 #ifdef WIN32 
    256                 FreeLibrary((HMODULE) handle); 
    257 #else 
    258212        dlclose (handle); 
    259 #endif 
    260  
    261213        return false; 
    262214    } 
     
    267219 
    268220        logCrit("%s\n","module_init() != 1" ); 
    269 #ifdef WIN32 
    270  
    271 #else 
    272221        dlclose (handle); 
    273 #endif 
    274222        return false; 
    275223    } 
     
    304252                logCrit("Loading Module %s failed, Module->Init() returned false\n", modulepath->c_str()); 
    305253                delete newmodule; 
    306 #ifdef WIN32 
    307                  
    308 #else 
    309254                dlclose (handle); 
    310 #endif 
    311255                return false; 
    312256        } 
  • nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp

    r454 r493  
    750750        } 
    751751 
    752         if( run == true ) 
    753         { 
    754         doLoop(); 
    755         }else 
    756752        if (filecheck) 
    757753        { 
    758754                show_version(); 
    759755                fileCheckMain(filecheckarg,argc,optind,argv); 
     756        } 
     757        if( run == true ) 
     758        { 
     759        doLoop(); 
    760760        } 
    761761