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 "sigSegvImpl.H"
00028 #include <OpenFOAM/JobInfo.H>
00029 #include <OpenFOAM/IOstreams.H>
00030 
00031 
00032 
00033 struct sigaction Foam::sigSegvImpl::oldAction_;
00034 
00035 
00036 
00037 void Foam::sigSegvImpl::sigSegvHandler(int)
00038 {
00039     
00040     if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
00041     {
00042         FatalErrorIn
00043         (
00044             "Foam::sigSegvImpl::sigSegvHandler()"
00045         )   << "Cannot reset SIGSEGV trapping"
00046             << abort(FatalError);
00047     }
00048 
00049     
00050     jobInfo.signalEnd();
00051 
00052     Perr << "\n"
00053             "************************************************************\n"
00054             "* FreeFOAM  crashed. See  below  for a  backtrace to  help *\n"
00055             "* locating the problem.                                    *\n"
00056             "************************************************************\n";
00057     error::printStack(Perr);
00058     Perr << "************************************************************\n"
00059             "\n";
00060 
00061     
00062     raise(SIGSEGV);
00063 }
00064 
00065 
00066 
00067 
00068 Foam::sigSegvImpl::sigSegvImpl()
00069 {
00070     oldAction_.sa_handler = NULL;
00071 }
00072 
00073 
00074 
00075 
00076 Foam::sigSegvImpl::~sigSegvImpl()
00077 {
00078     
00079     if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
00080     {
00081         FatalErrorIn
00082         (
00083             "Foam::sigSegvImpl::~sigSegvImpl()"
00084         )   << "Cannot reset SIGSEGV trapping"
00085             << abort(FatalError);
00086     }
00087 }
00088 
00089 
00090 
00091 
00092 void Foam::sigSegvImpl::set(const bool verbose)
00093 {
00094     if (oldAction_.sa_handler)
00095     {
00096         FatalErrorIn
00097         (
00098             "Foam::sigSegvImpl::set()"
00099         )   << "Cannot call sigSegvImpl::set() more than once"
00100             << abort(FatalError);
00101     }
00102 
00103     struct sigaction newAction;
00104     newAction.sa_handler = sigSegvHandler;
00105     newAction.sa_flags = SA_NODEFER;
00106     sigemptyset(&newAction.sa_mask);
00107     if (sigaction(SIGSEGV, &newAction, &oldAction_) < 0)
00108     {
00109         FatalErrorIn
00110         (
00111             "Foam::sigSegvImpl::set()"
00112         )   << "Cannot set SIGSEGV trapping"
00113             << abort(FatalError);
00114     }
00115 }
00116 
00117 
00118