1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
29 #include "IOstreams.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 struct sigaction Foam::sigQuit::oldAction_;
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 void Foam::sigQuit::sigQuitHandler(int)
40 if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
44 "Foam::sigQuit::sigQuitHandler()"
45 ) << "Cannot reset SIGQUIT trapping"
49 // Update jobInfo file
52 error::printStack(Perr);
54 // Throw signal (to old handler)
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 Foam::sigQuit::sigQuit()
63 oldAction_.sa_handler = NULL;
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 Foam::sigQuit::~sigQuit()
72 if (oldAction_.sa_handler && sigaction(SIGQUIT, &oldAction_, NULL) < 0)
76 "Foam::sigQuit::~sigQuit()"
77 ) << "Cannot reset SIGQUIT trapping"
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 void Foam::sigQuit::set(const bool verbose)
87 if (oldAction_.sa_handler)
91 "Foam::sigQuit::set()"
92 ) << "Cannot call sigQuit::set() more than once"
96 struct sigaction newAction;
97 newAction.sa_handler = sigQuitHandler;
98 newAction.sa_flags = SA_NODEFER;
99 sigemptyset(&newAction.sa_mask);
100 if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
104 "Foam::sigQuit::set()"
105 ) << "Cannot set SIGQUIT trapping"
106 << abort(FatalError);
111 // ************************************************************************* //