From a53dae9be39c21076831d66695d7d474329dfa1b Mon Sep 17 00:00:00 2001 From: XinyuHou Date: Tue, 27 Jan 2015 11:04:23 +0000 Subject: [PATCH] added assersions before lib func invoking and adjust log level #4313 --- src/lib/arch/unix/ArchPluginUnix.cpp | 31 ++++++++++++++++++++--- src/lib/arch/win32/ArchPluginWindows.cpp | 32 +++++++++++++++++++++--- src/lib/plugin/ns/SecureSocket.cpp | 6 ++--- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/lib/arch/unix/ArchPluginUnix.cpp b/src/lib/arch/unix/ArchPluginUnix.cpp index 0678120e..c4a87d41 100644 --- a/src/lib/arch/unix/ArchPluginUnix.cpp +++ b/src/lib/arch/unix/ArchPluginUnix.cpp @@ -91,7 +91,13 @@ ArchPluginUnix::unload() PluginTable::iterator it; for (it = m_pluginTable.begin(); it != m_pluginTable.end(); it++) { cleanupFunc cleanup = (cleanupFunc)dlsym(it->second, "cleanup"); - cleanup(); + if (cleanup != NULL) { + cleanup(); + } + else { + LOG((CLOG_DEBUG "no cleanup function in %s", it->first.c_str())); + } + LOG((CLOG_DEBUG "unloading plugin: %s", it->first.c_str())); dlclose(it->second); } @@ -103,7 +109,12 @@ ArchPluginUnix::init(void* log, void* arch) PluginTable::iterator it; for (it = m_pluginTable.begin(); it != m_pluginTable.end(); it++) { initFunc initPlugin = (initFunc)dlsym(it->second, "init"); - initPlugin(log, arch); + if (initPlugin != NULL) { + initPlugin(log, arch); + } + else { + LOG((CLOG_DEBUG "no init function in %s", it->first.c_str())); + } } } @@ -116,7 +127,12 @@ ArchPluginUnix::initEvent(void* eventTarget, IEventQueue* events) PluginTable::iterator it; for (it = m_pluginTable.begin(); it != m_pluginTable.end(); it++) { initEventFunc initEventPlugin = (initEventFunc)dlsym(it->second, "initEvent"); - initEventPlugin(&sendEvent); + if (initEventPlugin != NULL) { + initEventPlugin(&sendEvent); + } + else { + LOG((CLOG_DEBUG "no init event function in %s", it->first.c_str())); + } } } @@ -138,7 +154,14 @@ ArchPluginUnix::invoke( it = m_pluginTable.find(plugin); if (it != m_pluginTable.end()) { invokeFunc invokePlugin = (invokeFunc)dlsym(it->second, "invoke"); - return invokePlugin(command, args); + void* result = NULL; + if (invokePlugin != NULL) { + result = invokePlugin(command, args); + } + else { + LOG((CLOG_DEBUG "no invoke function in %s", it->first.c_str())); + } + return result; } else { LOG((CLOG_DEBUG "invoke command failed, plugin: %s command: %s", diff --git a/src/lib/arch/win32/ArchPluginWindows.cpp b/src/lib/arch/win32/ArchPluginWindows.cpp index 378258f3..45408ee1 100644 --- a/src/lib/arch/win32/ArchPluginWindows.cpp +++ b/src/lib/arch/win32/ArchPluginWindows.cpp @@ -77,7 +77,13 @@ ArchPluginWindows::unload() for (it = m_pluginTable.begin(); it != m_pluginTable.end(); it++) { lib = reinterpret_cast(it->second); cleanupFunc cleanup = (cleanupFunc)GetProcAddress(lib, "cleanup"); - cleanup(); + if (cleanup != NULL) { + cleanup(); + } + else { + LOG((CLOG_DEBUG "no cleanup function in %s", it->first.c_str())); + } + LOG((CLOG_DEBUG "unloading plugin: %s", it->first.c_str())); FreeLibrary(lib); } @@ -91,7 +97,12 @@ ArchPluginWindows::init(void* log, void* arch) for (it = m_pluginTable.begin(); it != m_pluginTable.end(); it++) { lib = reinterpret_cast(it->second); initFunc initPlugin = (initFunc)GetProcAddress(lib, "init"); - initPlugin(log, arch); + if (initPlugin != NULL) { + initPlugin(log, arch); + } + else { + LOG((CLOG_DEBUG "no init function in %s", it->first.c_str())); + } } } @@ -106,7 +117,12 @@ ArchPluginWindows::initEvent(void* eventTarget, IEventQueue* events) for (it = m_pluginTable.begin(); it != m_pluginTable.end(); it++) { lib = reinterpret_cast(it->second); initEventFunc initEventPlugin = (initEventFunc)GetProcAddress(lib, "initEvent"); - initEventPlugin(&sendEvent); + if (initEventPlugin != NULL) { + initEventPlugin(&sendEvent); + } + else { + LOG((CLOG_DEBUG "no init event function in %s", it->first.c_str())); + } } } @@ -130,7 +146,15 @@ ArchPluginWindows::invoke( if (it != m_pluginTable.end()) { HINSTANCE lib = reinterpret_cast(it->second); invokeFunc invokePlugin = (invokeFunc)GetProcAddress(lib, "invoke"); - return invokePlugin(command, args); + void* result = NULL; + if (invokePlugin != NULL) { + result = invokePlugin(command, args); + } + else { + LOG((CLOG_DEBUG "no invoke function in %s", it->first.c_str())); + } + + return result; } else { LOG((CLOG_DEBUG "invoke command failed, plugin: %s command: %s", diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index 88aa37b5..07c3a95f 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -218,7 +218,7 @@ SecureSocket::secureAccept(int socket) SSL_set_fd(m_ssl->m_ssl, socket); // do SSL-protocol accept - LOG((CLOG_DEBUG "secureAccept")); + LOG((CLOG_DEBUG1 "secureAccept")); int r = SSL_accept(m_ssl->m_ssl); bool retry = checkResult(r); @@ -241,9 +241,9 @@ SecureSocket::secureConnect(int socket) // attach the socket descriptor SSL_set_fd(m_ssl->m_ssl, socket); - LOG((CLOG_DEBUG "secureConnect")); - int r = SSL_connect(m_ssl->m_ssl); + LOG((CLOG_DEBUG1 "secureConnect")); + int r = SSL_connect(m_ssl->m_ssl); bool retry = checkResult(r); //TODO: don't use this infinite loop