1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 <OpenFOAM/error.H>
28 #include "sigSegvImpl.H"
29 #include <OpenFOAM/JobInfo.H>
30 #include <OpenFOAM/IOstreams.H>
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 struct sigaction Foam::sigSegvImpl::oldAction_;
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 void Foam::sigSegvImpl::sigSegvHandler(int)
41 if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
45 "Foam::sigSegvImpl::sigSegvHandler()"
46 ) << "Cannot reset SIGSEGV trapping"
50 // Update jobInfo file
54 "************************************************************\n"
55 "* FreeFOAM crashed. See below for a backtrace to help *\n"
56 "* locating the problem. *\n"
57 "************************************************************\n";
58 error::printStack(Perr);
59 Perr << "************************************************************\n"
62 // Throw signal (to old handler)
67 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 Foam::sigSegvImpl::sigSegvImpl()
71 oldAction_.sa_handler = NULL;
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
77 Foam::sigSegvImpl::~sigSegvImpl()
80 if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
84 "Foam::sigSegvImpl::~sigSegvImpl()"
85 ) << "Cannot reset SIGSEGV trapping"
91 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 void Foam::sigSegvImpl::set(const bool verbose)
95 if (oldAction_.sa_handler)
99 "Foam::sigSegvImpl::set()"
100 ) << "Cannot call sigSegvImpl::set() more than once"
101 << abort(FatalError);
104 struct sigaction newAction;
105 newAction.sa_handler = sigSegvHandler;
106 newAction.sa_flags = SA_NODEFER;
107 sigemptyset(&newAction.sa_mask);
108 if (sigaction(SIGSEGV, &newAction, &oldAction_) < 0)
112 "Foam::sigSegvImpl::set()"
113 ) << "Cannot set SIGSEGV trapping"
114 << abort(FatalError);
119 // ************************ vim: set sw=4 sts=4 et: ************************ //