1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
29 #include "IOstreams.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 struct sigaction Foam::sigQuit::oldAction_;
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 void Foam::sigQuit::sigHandler(int)
41 if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
45 "Foam::sigQuit::sigHandler()"
46 ) << "Cannot reset SIGQUIT trapping"
50 // Update jobInfo file
53 error::printStack(Perr);
55 // Throw signal (to old handler)
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 Foam::sigQuit::sigQuit()
64 oldAction_.sa_handler = NULL;
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 Foam::sigQuit::~sigQuit()
73 if (oldAction_.sa_handler && sigaction(SIGQUIT, &oldAction_, NULL) < 0)
77 "Foam::sigQuit::~sigQuit()"
78 ) << "Cannot reset SIGQUIT trapping"
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 void Foam::sigQuit::set(const bool verbose)
88 if (oldAction_.sa_handler)
92 "Foam::sigQuit::set()"
93 ) << "Cannot call sigQuit::set() more than once"
97 struct sigaction newAction;
98 newAction.sa_handler = sigHandler;
99 newAction.sa_flags = SA_NODEFER;
100 sigemptyset(&newAction.sa_mask);
101 if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
105 "Foam::sigQuit::set()"
106 ) << "Cannot set SIGQUIT trapping"
107 << abort(FatalError);
112 // ************************************************************************* //