sigQuit.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2011 Symscape
10  Copyright (C) 2018-2021 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "sigQuit.H"
31 #include "error.H"
32 #include "JobInfo.H"
33 #include "IOstreams.H"
34 
35 // File-local functions
36 #include "signalMacros.C"
37 
38 // NOTE: SIGBREAK is the best alternative to SIGQUIT on windows
39 
40 
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 
43 bool Foam::sigQuit::sigActive_ = false;
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::sigQuit::sigHandler(int)
49 {
50  resetHandler("SIGBREAK", SIGBREAK);
51 
52  JobInfo::shutdown(); // From running -> finished
54  ::raise(SIGBREAK); // Throw signal (to old handler)
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 {
62  set(false);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {
70  unset(false);
71 }
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 {
78  if (sigActive_)
79  {
80  return;
81  }
82  sigActive_ = true;
83 
84  setHandler("SIGBREAK", SIGBREAK, sigHandler);
85 }
86 
87 
89 {
90  if (!sigActive_)
91  {
92  return;
93  }
94  sigActive_ = false;
95 
96  resetHandler("SIGBREAK", SIGBREAK);
97 }
98 
99 
100 // ************************************************************************* //
sigQuit.H
Foam::error::printStack
static void printStack(Ostream &os)
Helper function to print a stack.
Definition: dummyPrintStack.C:36
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::resetHandler
static void resetHandler(const char *what, int sigNum)
Definition: signalMacros.C:46
Foam::sigQuit::~sigQuit
~sigQuit()
Destructor.
Definition: sigQuit.C:68
Foam::BitOps::unset
void unset(List< bool > &bools, const labelRange &range)
Unset the specified range 'on' in a boolList.
Definition: BitOps.C:96
Foam::sigQuit::unset
static void unset(bool verbose=false)
Deactivate SIGQUIT signal handler.
Definition: sigQuit.C:88
error.H
signalMacros.C
File-local code for setting/resetting signal handlers.
Foam::JobInfo::shutdown
static void shutdown()
Simple shutdown (finalize) of JobInfo.
Definition: JobInfo.C:98
Foam::Perr
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Foam::setHandler
static void setHandler(const char *what, int sigNum, void(*handler)(int))
Definition: signalMacros.C:61
JobInfo.H
Foam::sigQuit::set
static void set(bool verbose=false)
Activate SIGQUIT signal handler.
Definition: sigQuit.C:76
Foam::sigQuit::sigQuit
sigQuit()
Construct null.
Definition: sigQuit.C:60