sigSegv.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) 2018-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "sigSegv.H"
30 #include "error.H"
31 #include "JobInfo.H"
32 #include "IOstreams.H"
33 
34 // File-local functions
35 #include "signalMacros.C"
36 
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 bool Foam::sigSegv::sigActive_ = false;
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void Foam::sigSegv::sigHandler(int)
46 {
47  resetHandler("SIGSEGV", SIGSEGV);
48 
49  JobInfo::shutdown(); // From running -> finished
51  ::raise(SIGSEGV); // Throw signal (to old handler)
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 {
59  set(false);
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64 
66 {
67  unset(false);
68 }
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
74 {
75  if (sigActive_)
76  {
77  return;
78  }
79  sigActive_ = true;
80 
81  setHandler("SIGSEGV", SIGSEGV, sigHandler);
82 }
83 
84 
86 {
87  if (!sigActive_)
88  {
89  return;
90  }
91  sigActive_ = false;
92 
93  resetHandler("SIGSEGV", SIGSEGV);
94 }
95 
96 
97 // ************************************************************************* //
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
sigSegv.H
Foam::BitOps::unset
void unset(List< bool > &bools, const labelRange &range)
Unset the specified range 'on' in a boolList.
Definition: BitOps.C:96
Foam::sigSegv::sigSegv
sigSegv()
Construct null.
Definition: sigSegv.C:57
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
Foam::sigSegv::set
static void set(bool verbose=false)
Activate SIGSEGV signal handler.
Definition: sigSegv.C:73
JobInfo.H
Foam::sigSegv::unset
static void unset(bool verbose=false)
Deactivate SIGSEGV signal handler.
Definition: sigSegv.C:85
Foam::sigSegv::~sigSegv
~sigSegv()
Destructor.
Definition: sigSegv.C:65