From 551ea3e10441030293332f20224b7820efc39fdb Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 16 Nov 2011 21:55:59 -0500 Subject: [PATCH] clear dlerror() to prevent old errors bubbling up dlerror() reports and clears errors. On some systems, it's necessary to call dlerror() before any calls to dlopen() and dlsysm() so that the error state can be reset before future calls to dlerror(). Otherwise, dlerror() may report errors from previous system calls even after a call to dlopen() or dlsysm(). Problem was originally seen on FreeBSD. ! Unable to locate method symbol [osrfAppInitialize] for app opensrf.dbmath: Undefined symbol "_nss_cache_cycle_prevention_function" See also: http://stackoverflow.com/questions/3559147/dlerror-undefined-symbol-nss-cache-cycle-prevention-function-on-freebsd-7-2 Signed-off-by: Bill Erickson --- src/libopensrf/osrf_application.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libopensrf/osrf_application.c b/src/libopensrf/osrf_application.c index 57a372b..9a6040e 100644 --- a/src/libopensrf/osrf_application.c +++ b/src/libopensrf/osrf_application.c @@ -149,6 +149,8 @@ int osrfAppRegisterApplication( const char* appName, const char* soFile ) { osrfLogInfo( OSRF_LOG_MARK, "Registering application %s with file %s", appName, soFile ); + dlerror(); // clear any existing errors + // Open the shared object. void* handle = dlopen( soFile, RTLD_NOW ); if( ! handle ) { @@ -167,6 +169,8 @@ int osrfAppRegisterApplication( const char* appName, const char* soFile ) { // Add the newly-constructed app to the list. osrfHashSet( _osrfAppHash, app, appName ); + dlerror(); // clear any existing errors + // Try to run the initialize method. Typically it will register one or more // methods of the application. int (*init) (void); @@ -211,6 +215,8 @@ static void osrfAppSetOnExit(osrfApplication* app, const char* appName) { /* see if we can run the initialize method */ char* error; void (*onExit) (void); + dlerror(); // clear any existing errors + *(void **) (&onExit) = dlsym(app->handle, "osrfAppChildExit"); if( (error = dlerror()) != NULL ) { @@ -238,6 +244,7 @@ int osrfAppRunChildInit(const char* appname) { char* error; int ret; int (*childInit) (void); + dlerror(); // clear any existing errors *(void**) (&childInit) = dlsym(app->handle, "osrfAppChildInit"); @@ -597,6 +604,7 @@ int osrfAppRunMethod( const char* appName, const char* methodName, // Function pointer through which we will call the function dynamically int (*meth) (osrfMethodContext*); + dlerror(); // clear any existing errors // Open the function that implements the method meth = dlsym(app->handle, method->symbol); -- 2.11.0