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