Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include <OpenFOAM/error.H>
00027 #include "sigQuitImpl.H"
00028 #include <OpenFOAM/JobInfo.H>
00029 #include <OpenFOAM/IOstreams.H>
00030 
00031 
00032 
00033 struct sigaction Foam::sigQuitImpl::oldAction_;
00034 
00035 
00036 
00037 void Foam::sigQuitImpl::sigQuitHandler(int)
00038 {
00039     
00040     if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
00041     {
00042         FatalErrorIn
00043         (
00044             "Foam::sigQuitImpl::sigQuitHandler()"
00045         )   << "Cannot reset SIGQUIT trapping"
00046             << abort(FatalError);    
00047     }
00048 
00049     
00050     jobInfo.signalEnd();
00051 
00052     error::printStack(Perr);
00053 
00054     
00055     raise(SIGQUIT);
00056 }
00057 
00058 
00059 
00060 
00061 Foam::sigQuitImpl::sigQuitImpl()
00062 {
00063     oldAction_.sa_handler = NULL;
00064 }
00065 
00066 
00067 
00068 
00069 Foam::sigQuitImpl::~sigQuitImpl()
00070 {
00071     
00072     if (oldAction_.sa_handler && sigaction(SIGQUIT, &oldAction_, NULL) < 0)
00073     {
00074         FatalErrorIn
00075         (
00076             "Foam::sigQuitImpl::~sigQuitImpl()"
00077         )   << "Cannot reset SIGQUIT trapping"
00078             << abort(FatalError);    
00079     }
00080 }
00081 
00082 
00083 
00084 
00085 void Foam::sigQuitImpl::set(const bool verbose)
00086 {
00087     if (oldAction_.sa_handler)
00088     {
00089         FatalErrorIn
00090         (
00091             "Foam::sigQuitImpl::set()"
00092         )   << "Cannot call sigQuitImpl::set() more than once"
00093             << abort(FatalError);
00094     }
00095 
00096     struct sigaction newAction;
00097     newAction.sa_handler = sigQuitHandler;
00098     newAction.sa_flags = SA_NODEFER;
00099     sigemptyset(&newAction.sa_mask);
00100     if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
00101     {
00102         FatalErrorIn
00103         (
00104             "Foam::sigQuitImpl::set()"
00105         )   << "Cannot set SIGQUIT trapping"
00106             << abort(FatalError);    
00107     }
00108 }
00109 
00110 
00111