From: cantor Date: Sun, 21 Oct 2007 20:39:16 +0000 (+0000) Subject: Add logging when catching unknown errors. X-Git-Tag: 2.4~706 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fsp.git;a=commitdiff_plain;h=c7edcac223ff582f749005f45e14472b0907c6f7 Add logging when catching unknown errors. Add catchAll flag to OutOfProcess config, implement in listener. git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2547 cb58f699-b61c-0410-a6fe-9272a202ed29 --- diff --git a/apache/mod_apache.cpp b/apache/mod_apache.cpp index 0cfbbf4..4dd4796 100644 --- a/apache/mod_apache.cpp +++ b/apache/mod_apache.cpp @@ -567,10 +567,9 @@ extern "C" int shib_check_user(request_rec* r) return SERVER_ERROR; } catch (...) { - if (g_catchAll) { - ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an uncaught exception!"); + ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_check_user threw an unknown exception!"); + if (g_catchAll) return SERVER_ERROR; - } throw; } } @@ -613,10 +612,9 @@ extern "C" int shib_handler(request_rec* r) return SERVER_ERROR; } catch (...) { - if (g_catchAll) { - ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an uncaught exception!"); + ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_handler threw an unknown exception!"); + if (g_catchAll) return SERVER_ERROR; - } throw; } } @@ -652,10 +650,9 @@ extern "C" int shib_auth_checker(request_rec* r) return SERVER_ERROR; } catch (...) { - if (g_catchAll) { - ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an uncaught exception!"); + ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, SH_AP_R(r), "shib_auth_checker threw an unknown exception!"); + if (g_catchAll) return SERVER_ERROR; - } throw; } } diff --git a/isapi_shib/isapi_shib.cpp b/isapi_shib/isapi_shib.cpp index 8099110..e04bdcd 100644 --- a/isapi_shib/isapi_shib.cpp +++ b/isapi_shib/isapi_shib.cpp @@ -601,8 +601,9 @@ extern "C" DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificat return WriteClientError(pfc,"Shibboleth Filter caught an exception, check Event Log for details."); } catch(...) { + LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "Shibboleth Filter threw an unknown exception."); if (g_catchAll) - return WriteClientError(pfc,"Shibboleth Filter caught an unknown exception."); + return WriteClientError(pfc,"Shibboleth Filter threw an unknown exception."); throw; } @@ -918,8 +919,9 @@ extern "C" DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) return WriteClientError(lpECB,"Shibboleth Extension caught an exception, check Event Log for details."); } catch(...) { + LogEvent(NULL, EVENTLOG_ERROR_TYPE, 2100, NULL, "Shibboleth Extension threw an unknown exception."); if (g_catchAll) - return WriteClientError(lpECB,"Shibboleth Extension caught an unknown exception."); + return WriteClientError(lpECB,"Shibboleth Extension threw an unknown exception."); throw; } diff --git a/nsapi_shib/nsapi_shib.cpp b/nsapi_shib/nsapi_shib.cpp index f20ed7d..d7ee771 100644 --- a/nsapi_shib/nsapi_shib.cpp +++ b/nsapi_shib/nsapi_shib.cpp @@ -422,8 +422,9 @@ extern "C" NSAPI_PUBLIC int nsapi_shib(pblock* pb, ::Session* sn, Request* rq) return WriteClientError(sn, rq, FUNC, "Shibboleth module threw an exception, see web server log for error."); } catch (...) { + log_error(LOG_FAILURE,FUNC,sn,rq,const_cast("Shibboleth module threw an unknown exception.")); if (g_catchAll) - return WriteClientError(sn, rq, FUNC, "Shibboleth module threw an uncaught exception."); + return WriteClientError(sn, rq, FUNC, "Shibboleth module threw an unknown exception."); throw; } } diff --git a/schemas/shibboleth-2.0-native-sp-config.xsd b/schemas/shibboleth-2.0-native-sp-config.xsd index 5352c19..5c197ef 100644 --- a/schemas/shibboleth-2.0-native-sp-config.xsd +++ b/schemas/shibboleth-2.0-native-sp-config.xsd @@ -178,6 +178,7 @@ + diff --git a/shibsp/remoting/impl/SocketListener.cpp b/shibsp/remoting/impl/SocketListener.cpp index eaebc37..d302b5d 100644 --- a/shibsp/remoting/impl/SocketListener.cpp +++ b/shibsp/remoting/impl/SocketListener.cpp @@ -22,6 +22,7 @@ #include "internal.h" #include "exceptions.h" +#include "ServiceProvider.h" #include "remoting/impl/SocketListener.h" #include @@ -153,7 +154,7 @@ void SocketPool::put(SocketListener::ShibSocket s) m_lock->unlock(); } -SocketListener::SocketListener(const DOMElement* e) : log(&Category::getInstance(SHIBSP_LOGCAT".Listener")), +SocketListener::SocketListener(const DOMElement* e) : m_catchAll(false), log(&Category::getInstance(SHIBSP_LOGCAT".Listener")), m_socketpool(NULL), m_shutdown(NULL), m_child_lock(NULL), m_child_wait(NULL), m_socket((ShibSocket)0) { // Are we a client? @@ -181,6 +182,15 @@ bool SocketListener::run(bool* shutdown) #endif log->info("listener service starting"); + ServiceProvider* sp = SPConfig::getConfig().getServiceProvider(); + sp->lock(); + const PropertySet* props = sp->getPropertySet("OutOfProcess"); + if (props) { + pair flag = props->getBool("catchAll"); + m_catchAll = flag.first && flag.second; + } + sp->unlock(); + // Save flag to monitor for shutdown request. m_shutdown=shutdown; unsigned long count = 0; @@ -229,6 +239,8 @@ bool SocketListener::run(bool* shutdown) } catch (...) { log->crit("error starting new server thread to service incoming request"); + if (!m_catchAll) + *m_shutdown = true; } } } @@ -511,16 +523,16 @@ int ServerThread::job() DDFJanitor jout(out); sink << out; } -#ifndef _DEBUG catch (...) { if (incomingError) log.error("unexpected error processing incoming message"); + if (!m_listener->m_catchAll) + throw; ListenerException ex("An unexpected error occurred while processing an incoming message."); DDF out=DDF("exception").string(ex.toString().c_str()); DDFJanitor jout(out); sink << out; } -#endif // Return whatever's available. string response(sink.str()); diff --git a/shibsp/remoting/impl/SocketListener.h b/shibsp/remoting/impl/SocketListener.h index 4544e36..0922cf4 100644 --- a/shibsp/remoting/impl/SocketListener.h +++ b/shibsp/remoting/impl/SocketListener.h @@ -69,6 +69,7 @@ namespace shibsp { virtual int send(ShibSocket& s, const char* buf, int len) const=0; virtual int recv(ShibSocket& s, char* buf, int buflen) const=0; + bool m_catchAll; protected: bool log_error() const; // for OS-level errors xmltooling::logging::Category* log;