Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DbuSignalHandler.cxx

Go to the documentation of this file.
00001 
00002 // $Id: DbuSignalHandler.cxx,v 1.4 2004/02/12 18:04:55 rhatcher Exp $
00004 #include "DatabaseUpdater/DbuSignalHandler.h"
00005 
00006 // MINOS include files
00007 #include "MessageService/MsgService.h"
00008 
00009 #include <syslog.h>
00010 #include <signal.h>
00011 #include "OnlineUtil/msgLogLib/msgLog.h"
00012 
00013 CVSID("$Id: DbuSignalHandler.cxx,v 1.4 2004/02/12 18:04:55 rhatcher Exp $");
00014 
00015 //......................................................................
00016 
00017 DbuSignalHandler* DbuSignalHandler::fgInstance = 0;
00018 
00019 //----------------------------------------------------------------------
00020 
00021 class DbuSIGINTHandler : public TSignalHandler {
00022 public:
00023    DbuSIGINTHandler() : TSignalHandler(kSigInterrupt, kFALSE) { }
00024    Bool_t  Notify();
00025 };
00026 
00027 Bool_t DbuSIGINTHandler::Notify()
00028 {
00029   //syslog(LOG_INFO,"<I> DbuSIGINTHandler::Notify()");
00030   logDebug(5,"DbuSIGINTHandler::Notify()");
00031   if (fDelay) { 
00032     //syslog(LOG_INFO,"<I> DbuSIGINTHandler::Notify() delayed");
00033     logDebug(4,"DbuSIGINTHandler::Notify() delayed");
00034     fDelay++; 
00035     return kFALSE; 
00036   }
00037 
00038   DbuSignalHandler::Instance().SignalAction(fSignal);
00039   return kTRUE;
00040 }
00041 
00042 class DbuSIGTERMHandler : public TSignalHandler {
00043 public:
00044    DbuSIGTERMHandler() : TSignalHandler(kSigTermination, kFALSE) { }
00045    Bool_t  Notify();
00046 };
00047 
00048 Bool_t DbuSIGTERMHandler::Notify()
00049 {
00050   //syslog(LOG_INFO,"<I> DbuSIGTERMHandler::Notify()");
00051   logDebug(5,"DbuSIGTERMHandler::Notify()");
00052   if (fDelay) { 
00053     //syslog(LOG_INFO,"<I> DbuSIGTERMHandler::Notify() delayed");
00054     logDebug(4,"DbuSIGINTHandler::Notify() delayed");
00055     fDelay++; 
00056     return kFALSE; 
00057   }
00058 
00059   DbuSignalHandler::Instance().SignalAction(fSignal);
00060   return kTRUE;
00061 }
00062 
00063 //----------------------------------------------------------------------
00064 //......................................................................
00065 
00066 DbuSignalHandler::DbuSignalHandler() :
00067    fSIGINT(0), fSIGTERM(0)
00068 {
00069   // ctor
00070   // create handlers for SIGTERM and SIGINT
00071 
00072   fSIGINT  = new DbuSIGINTHandler;
00073   fSIGINT->Add();
00074 
00075   fSIGTERM = new DbuSIGTERMHandler;
00076   fSIGTERM->Add();
00077 }
00078 
00079 //......................................................................
00080 
00081 DbuSignalHandler::~DbuSignalHandler() 
00082 {
00083   delete fSIGINT;
00084   delete fSIGTERM;
00085 }
00086 
00087 //......................................................................
00088   
00089 DbuSignalHandler& DbuSignalHandler::Instance()
00090 {
00091   // protect singleton
00092   if (fgInstance == 0) {
00093     static DbuSignalHandler::Cleaner c; // end-of-run clean up
00094     c.ClassIsUsed();
00095 
00096     fgInstance = new DbuSignalHandler;
00097   }
00098   return *fgInstance;
00099 }
00100 
00101 //......................................................................
00102 
00103 void DbuSignalHandler::Delay()
00104 {
00105    // delay processing of signals until HandleDelayedSignal is called
00106 
00107   fSIGTERM->Delay();
00108   fSIGINT->Delay();
00109 
00110   //syslog(LOG_INFO,"<I> DbuSignalHandler::Delay()");
00111   logDebug(5,"DbuSignalHandler::Delay()");
00112 }
00113 
00114 //......................................................................
00115 
00116 void DbuSignalHandler::HandleDelayedSignal()
00117 {
00118    // processing any delayed signals
00119 
00120   fSIGTERM->HandleDelayedSignal();
00121   fSIGINT->HandleDelayedSignal();
00122 
00123   //syslog(LOG_INFO,"<I> DbuSignalHandler::HandleDelayedSignal()");
00124   logDebug(5,"DbuSignalHandler::HandleDelayedSignal()");
00125 }
00126 
00127 //......................................................................
00128 
00129 bool DbuSignalHandler::SignalAction(int signal)
00130 {
00131   // This is where the real work is done
00132   // decisions about what to do when a signal is caught go here
00133 
00134   MSG("Dbu",Msg::kInfo) 
00135     << "Dbu SignalAction (signal " << signal 
00136     << ") called" << endl;
00137 
00138   logNotice("SignalAction: signal %d, attempt shutdown.",signal);
00139 
00140   // make sure the clean up code is called
00141 
00142   // closelog(); // shutdown code might want to write to syslog
00143   //NO!//msgLogCleanup();
00144 
00145   exit(1);
00146 
00147   return true;
00148 
00149 }
00150 

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1