Add logging when catching unknown errors.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Sun, 21 Oct 2007 20:39:16 +0000 (20:39 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Sun, 21 Oct 2007 20:39:16 +0000 (20:39 +0000)
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

apache/mod_apache.cpp
isapi_shib/isapi_shib.cpp
nsapi_shib/nsapi_shib.cpp
schemas/shibboleth-2.0-native-sp-config.xsd
shibsp/remoting/impl/SocketListener.cpp
shibsp/remoting/impl/SocketListener.h

index 0cfbbf4..4dd4796 100644 (file)
@@ -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;
   }
 }
index 8099110..e04bdcd 100644 (file)
@@ -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;
     }
 
index f20ed7d..d7ee771 100644 (file)
@@ -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<char*>("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;
   }
 }
index 5352c19..5c197ef 100644 (file)
                                <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>\r
                        </sequence>\r
                        <attribute name="logger" type="anyURI"/>\r
+                   <attribute name="catchAll" type="boolean"/>\r
                        <anyAttribute namespace="##other" processContents="lax"/>\r
                </complexType>\r
        </element>\r
index eaebc37..d302b5d 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "internal.h"
 #include "exceptions.h"
+#include "ServiceProvider.h"
 #include "remoting/impl/SocketListener.h"
 
 #include <errno.h>
@@ -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<bool,bool> 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());
index 4544e36..0922cf4 100644 (file)
@@ -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;