Merge branch 'master' of ssh://opencfd@repo.or.cz/srv/git/OpenFOAM-1.5.x
[freefoam.git] / src / OSspecific / Unix / signals / sigQuit.C
blob764270a900f155bfbd10f09754de61bed28155b7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "error.H"
28 #include "sigQuit.H"
29 #include "JobInfo.H"
30 #include "IOstreams.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 struct sigaction Foam::sigQuit::oldAction_;
36 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
38 void Foam::sigQuit::sigQuitHandler(int)
40     // Reset old handling
41     if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
42     {
43         FatalErrorIn
44         (
45             "Foam::sigQuit::sigQuitHandler()"
46         )   << "Cannot reset SIGQUIT trapping"
47             << abort(FatalError);    
48     }
50     // Update jobInfo file
51     jobInfo.signalEnd();
53     error::printStack(Perr);
55     // Throw signal (to old handler)
56     raise(SIGQUIT);
60 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
62 Foam::sigQuit::sigQuit()
64     oldAction_.sa_handler = NULL;
68 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
70 Foam::sigQuit::~sigQuit()
72     // Reset old handling
73     if (oldAction_.sa_handler && sigaction(SIGQUIT, &oldAction_, NULL) < 0)
74     {
75         FatalErrorIn
76         (
77             "Foam::sigQuit::~sigQuit()"
78         )   << "Cannot reset SIGQUIT trapping"
79             << abort(FatalError);    
80     }
84 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
86 void Foam::sigQuit::set()
88     if (oldAction_.sa_handler)
89     {
90         FatalErrorIn
91         (
92             "Foam::sigQuit::set()"
93         )   << "Cannot call sigQuit::set() more than once"
94             << abort(FatalError);
95     }
97     struct sigaction newAction;
98     newAction.sa_handler = sigQuitHandler;
99     newAction.sa_flags = SA_NODEFER;
100     sigemptyset(&newAction.sa_mask);
101     if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
102     {
103         FatalErrorIn
104         (
105             "Foam::sigQuit::set()"
106         )   << "Cannot set SIGQUIT trapping"
107             << abort(FatalError);    
108     }
112 // ************************************************************************* //