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::sigSegv::oldAction_;
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 void Foam::sigSegv::sigSegvHandler(int)
40 if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
44 "Foam::sigSegv::sigSegvHandler()"
45 ) << "Cannot reset SIGSEGV trapping"
49 // Update jobInfo file
52 error::printStack(Perr);
54 // Throw signal (to old handler)
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 Foam::sigSegv::sigSegv()
63 oldAction_.sa_handler = NULL;
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 Foam::sigSegv::~sigSegv()
72 if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
76 "Foam::sigSegv::~sigSegv()"
77 ) << "Cannot reset SIGSEGV trapping"
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 void Foam::sigSegv::set(const bool verbose)
87 if (oldAction_.sa_handler)
91 "Foam::sigSegv::set()"
92 ) << "Cannot call sigSegv::set() more than once"
96 struct sigaction newAction;
97 newAction.sa_handler = sigSegvHandler;
98 newAction.sa_flags = SA_NODEFER;
99 sigemptyset(&newAction.sa_mask);
100 if (sigaction(SIGSEGV, &newAction, &oldAction_) < 0)
104 "Foam::sigSegv::set()"
105 ) << "Cannot set SIGSEGV trapping"
106 << abort(FatalError);
111 // ************************************************************************* //