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