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