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

sigInt.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 "sigInt.H"
00029 #include "JobInfo.H"
00030 #include "IOstreams.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 struct sigaction Foam::sigInt::oldAction_;
00035 
00036 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00037 
00038 void Foam::sigInt::sigIntHandler(int)
00039 {
00040     // Reset old handling
00041     if (sigaction(SIGINT, &oldAction_, NULL) < 0)
00042     {
00043         FatalErrorIn
00044         (
00045             "Foam::sigInt::sigIntHandler()"
00046         )   << "Cannot reset SIGINT trapping"
00047             << abort(FatalError);    
00048     }
00049 
00050     // Update jobInfo file
00051     jobInfo.signalEnd();
00052 
00053     // Throw signal (to old handler)
00054     raise(SIGINT);
00055 }
00056 
00057 
00058 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00059 
00060 Foam::sigInt::sigInt()
00061 {
00062     oldAction_.sa_handler = NULL;
00063 }
00064 
00065 
00066 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00067 
00068 Foam::sigInt::~sigInt()
00069 {
00070     // Reset old handling
00071     if (sigaction(SIGINT, &oldAction_, NULL) < 0)
00072     {
00073         FatalErrorIn
00074         (
00075             "Foam::sigInt::~sigInt()"
00076         )   << "Cannot reset SIGINT trapping"
00077             << abort(FatalError);    
00078     }
00079 }
00080 
00081 
00082 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00083 
00084 void Foam::sigInt::set(const bool verbose)
00085 {
00086     if (oldAction_.sa_handler)
00087     {
00088         FatalErrorIn
00089         (
00090             "Foam::sigInt::set()"
00091         )   << "Cannot call sigInt::set() more than once"
00092             << abort(FatalError);
00093     }
00094 
00095     struct sigaction newAction;
00096     newAction.sa_handler = sigIntHandler;
00097     newAction.sa_flags = SA_NODEFER;
00098     sigemptyset(&newAction.sa_mask);
00099     if (sigaction(SIGINT, &newAction, &oldAction_) < 0)
00100     {
00101         FatalErrorIn
00102         (
00103             "Foam::sigInt::set()"
00104         )   << "Cannot set SIGINT trapping"
00105             << abort(FatalError);    
00106     }
00107 }
00108 
00109 
00110 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd