Forward compatibility: flex
[foam-extend-3.2.git] / src / OSspecific / POSIX / signals / sigQuit.C
blob23f72aebeb7714590b4c307523ff33d321c3adf2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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 \*---------------------------------------------------------------------------*/
26 #include "error.H"
27 #include "sigQuit.H"
28 #include "JobInfo.H"
29 #include "IOstreams.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 struct sigaction Foam::sigQuit::oldAction_;
35 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
37 void Foam::sigQuit::sigQuitHandler(int)
39     // Reset old handling
40     if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
41     {
42         FatalErrorIn
43         (
44             "Foam::sigQuit::sigQuitHandler()"
45         )   << "Cannot reset SIGQUIT trapping"
46             << abort(FatalError);
47     }
49     // Update jobInfo file
50     jobInfo.signalEnd();
52     error::printStack(Perr);
54     // Throw signal (to old handler)
55     raise(SIGQUIT);
59 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
61 Foam::sigQuit::sigQuit()
63     oldAction_.sa_handler = NULL;
67 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
69 Foam::sigQuit::~sigQuit()
71     // Reset old handling
72     if (oldAction_.sa_handler && sigaction(SIGQUIT, &oldAction_, NULL) < 0)
73     {
74         FatalErrorIn
75         (
76             "Foam::sigQuit::~sigQuit()"
77         )   << "Cannot reset SIGQUIT trapping"
78             << abort(FatalError);
79     }
83 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
85 void Foam::sigQuit::set(const bool verbose)
87     if (oldAction_.sa_handler)
88     {
89         FatalErrorIn
90         (
91             "Foam::sigQuit::set()"
92         )   << "Cannot call sigQuit::set() more than once"
93             << abort(FatalError);
94     }
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)
101     {
102         FatalErrorIn
103         (
104             "Foam::sigQuit::set()"
105         )   << "Cannot set SIGQUIT trapping"
106             << abort(FatalError);
107     }
111 // ************************************************************************* //