OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

sigQuit.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "error.H"
00028 #include "sigQuit.H"
00029 #include "JobInfo.H"
00030 #include "IOstreams.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 struct sigaction Foam::sigQuit::oldAction_;
00035 
00036 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00037 
00038 void Foam::sigQuit::sigQuitHandler(int)
00039 {
00040     // Reset old handling
00041     if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
00042     {
00043         FatalErrorIn
00044         (
00045             "Foam::sigQuit::sigQuitHandler()"
00046         )   << "Cannot reset SIGQUIT trapping"
00047             << abort(FatalError);    
00048     }
00049 
00050     // Update jobInfo file
00051     jobInfo.signalEnd();
00052 
00053     error::printStack(Perr);
00054 
00055     // Throw signal (to old handler)
00056     raise(SIGQUIT);
00057 }
00058 
00059 
00060 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00061 
00062 Foam::sigQuit::sigQuit()
00063 {
00064     oldAction_.sa_handler = NULL;
00065 }
00066 
00067 
00068 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00069 
00070 Foam::sigQuit::~sigQuit()
00071 {
00072     // Reset old handling
00073     if (oldAction_.sa_handler && sigaction(SIGQUIT, &oldAction_, NULL) < 0)
00074     {
00075         FatalErrorIn
00076         (
00077             "Foam::sigQuit::~sigQuit()"
00078         )   << "Cannot reset SIGQUIT trapping"
00079             << abort(FatalError);    
00080     }
00081 }
00082 
00083 
00084 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00085 
00086 void Foam::sigQuit::set(const bool verbose)
00087 {
00088     if (oldAction_.sa_handler)
00089     {
00090         FatalErrorIn
00091         (
00092             "Foam::sigQuit::set()"
00093         )   << "Cannot call sigQuit::set() more than once"
00094             << abort(FatalError);
00095     }
00096 
00097     struct sigaction newAction;
00098     newAction.sa_handler = sigQuitHandler;
00099     newAction.sa_flags = SA_NODEFER;
00100     sigemptyset(&newAction.sa_mask);
00101     if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
00102     {
00103         FatalErrorIn
00104         (
00105             "Foam::sigQuit::set()"
00106         )   << "Cannot set SIGQUIT trapping"
00107             << abort(FatalError);    
00108     }
00109 }
00110 
00111 
00112 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd