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::sigInt::oldAction_;
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 void Foam::sigInt::sigIntHandler(int)
40 if (sigaction(SIGINT, &oldAction_, NULL) < 0)
44 "Foam::sigInt::sigIntHandler()"
45 ) << "Cannot reset SIGINT trapping"
49 // Update jobInfo file
52 // Throw signal (to old handler)
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 Foam::sigInt::sigInt()
61 oldAction_.sa_handler = NULL;
65 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 Foam::sigInt::~sigInt()
70 if (sigaction(SIGINT, &oldAction_, NULL) < 0)
74 "Foam::sigInt::~sigInt()"
75 ) << "Cannot reset SIGINT trapping"
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 void Foam::sigInt::set(const bool verbose)
85 if (oldAction_.sa_handler)
90 ) << "Cannot call sigInt::set() more than once"
94 struct sigaction newAction;
95 newAction.sa_handler = sigIntHandler;
96 newAction.sa_flags = SA_NODEFER;
97 sigemptyset(&newAction.sa_mask);
98 if (sigaction(SIGINT, &newAction, &oldAction_) < 0)
102 "Foam::sigInt::set()"
103 ) << "Cannot set SIGINT trapping"
104 << abort(FatalError);
109 // ************************************************************************* //