Creation of OpenFOAM-dev repository 15/04/2008

This commit is contained in:
OpenFOAM-admin
2008-04-15 18:56:58 +01:00
commit 3170c7c0c9
9896 changed files with 4016171 additions and 0 deletions

View File

@ -0,0 +1,13 @@
signals/sigFpe.C
signals/sigSegv.C
signals/sigInt.C
signals/sigQuit.C
timer.C
fileStat.C
Unix.C
cpuTime/cpuTime.C
clockTime/clockTime.C
printStack.C
/*dummyPrintStack.C*/
LIB = $(FOAM_LIBBIN)/libOSspecific

View File

1005
src/OSspecific/Unix/Unix.C Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Namespace
Foam::Unix
Description
UNIX versions of OS-specific functions.
SourceFiles
Unix.C
\*---------------------------------------------------------------------------*/
#ifndef Unix_H
#define Unix_H
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Unix
{
//- Declare name of the class and its debug switch
NamespaceName("Unix");
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,88 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "clockTime.H"
#include "scalar.H"
#include <sys/time.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void clockTime::getTime(struct timeval& t)
{
gettimeofday(&t, NULL);
}
double clockTime::timeDifference
(
const struct timeval& start,
const struct timeval& end
)
{
return end.tv_sec - start.tv_sec + 1E-6*(end.tv_usec - start.tv_usec);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
clockTime::clockTime()
{
getTime(startTime_);
lastTime_ = startTime_;
newTime_ = startTime_;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
double clockTime::elapsedTime() const
{
getTime(newTime_);
return timeDifference(startTime_, newTime_);
}
double clockTime::timeIncrement() const
{
lastTime_ = newTime_;
getTime(newTime_);
return timeDifference(lastTime_, newTime_);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::clockTime
Description
Starts timing (using rtc) and returns elapsed time from start.
Better resolution (2uSec instead of ~20mSec) than cpuTime.
SourceFiles
clockTime.C
\*---------------------------------------------------------------------------*/
#ifndef clockTime_H
#define clockTime_H
#include <sys/types.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class clockTime Declaration
\*---------------------------------------------------------------------------*/
class clockTime
{
// Private data
struct timeval startTime_;
mutable struct timeval lastTime_;
mutable struct timeval newTime_;
static void getTime(struct timeval& t);
static double timeDifference
(
const struct timeval& start,
const struct timeval& end
);
public:
// Constructors
//- Construct from components
clockTime();
// Member Functions
// Access
//- Returns CPU time from start of run
double elapsedTime() const;
//- Returns CPU time from last call of clockTimeIncrement()
double timeIncrement() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,100 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Starts timing CPU usage and return elapsed time from start.
\*---------------------------------------------------------------------------*/
#include "cpuTime.H"
#include <unistd.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
long cpuTime::Hz_(sysconf(_SC_CLK_TCK));
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void cpuTime::getTime(struct tms& t)
{
times(&t);
}
double cpuTime::timeDifference
(
const struct tms& start,
const struct tms& end
)
{
return
(
double
(
(end.tms_utime + end.tms_stime)
- (start.tms_utime + start.tms_stime)
)/Hz_
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
cpuTime::cpuTime()
{
getTime(startTime_);
lastTime_ = startTime_;
newTime_ = startTime_;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
double cpuTime::elapsedCpuTime() const
{
getTime(newTime_);
return timeDifference(startTime_, newTime_);
}
double cpuTime::cpuTimeIncrement() const
{
lastTime_ = newTime_;
getTime(newTime_);
return timeDifference(lastTime_, newTime_);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::cpuTime
Description
Starts timing CPU usage and return elapsed time from start.
SeeAlso
clockTime
SourceFiles
cpuTime.C
\*---------------------------------------------------------------------------*/
#ifndef cpuTime_H
#define cpuTime_H
#include <time.h>
#include <sys/times.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class cpuTime Declaration
\*---------------------------------------------------------------------------*/
class cpuTime
{
// Private data
static long Hz_;
struct tms startTime_;
mutable struct tms lastTime_;
mutable struct tms newTime_;
static void getTime(struct tms& t);
static double timeDifference
(
const struct tms& start,
const struct tms& end
);
public:
// Constructors
//- Construct from components
cpuTime();
// Member Functions
// Access
//- Returns CPU time from start of run
double elapsedCpuTime() const;
//- Returns CPU time from last call of cpuTimeIncrement()
double cpuTimeIncrement() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,35 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::error::printStack(Ostream& os)
{}
// ************************************************************************* //

View File

@ -0,0 +1,207 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Wrapper for stat() system call.
\*---------------------------------------------------------------------------*/
#include "fileStat.H"
#include "IOstreams.H"
#include "timer.H"
#include <signal.h>
#include <unistd.h>
#include <sys/sysmacros.h>
/*
#undef major
#undef minor
#undef makedev
# define major(dev) ((int)(((dev) >> 8) & 0xff))
# define minor(dev) ((int)((dev) & 0xff))
# define makedev(major, minor) ((((unsigned int) (major)) << 8) \
| ((unsigned int) (minor)))
*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct null
fileStat::fileStat()
:
isValid_(false)
{}
// Construct from components
fileStat::fileStat(const fileName& fName, const unsigned int maxTime)
{
// Work on volatile
volatile bool locIsValid = false;
timer myTimer(maxTime);
if (!timedOut(myTimer))
{
if (::stat(fName.c_str(), &status_) != 0)
{
locIsValid = false;
}
else
{
locIsValid = true;
}
}
// Copy into (non-volatile, possible register based) member var
isValid_ = locIsValid;
}
// Construct from Istream.
fileStat::fileStat(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// compare two fileStates for same device
bool fileStat::sameDevice(const fileStat& stat2) const
{
return
isValid_
&& (
major(status_.st_dev) == major(stat2.status().st_dev)
&& minor(status_.st_dev) == minor(stat2.status().st_dev)
);
}
// compare two fileStates for same Inode
bool fileStat::sameINode(const fileStat& stat2) const
{
return isValid_ && (status_.st_ino == stat2.status().st_ino);
}
// compare state against inode
bool fileStat::sameINode(const label iNode) const
{
return isValid_ && (status_.st_ino == ino_t(iNode));
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// Input in list syntax
Istream& operator>>(Istream& is, fileStat& fStat)
{
// Read beginning of machine info list
is.readBegin("fileStat");
label
devMaj, devMin,
ino, mode, uid, gid,
rdevMaj, rdevMin,
size, atime, mtime, ctime;
is >> fStat.isValid_
>> devMaj
>> devMin
>> ino
>> mode
>> uid
>> gid
>> rdevMaj
>> rdevMin
>> size
>> atime
>> mtime
>> ctime;
dev_t st_dev = makedev(devMaj, devMin);
fStat.status_.st_dev = st_dev;
fStat.status_.st_ino = ino;
fStat.status_.st_mode = mode;
fStat.status_.st_uid = uid;
fStat.status_.st_gid = gid;
dev_t st_rdev = makedev(rdevMaj, rdevMin);
fStat.status_.st_rdev = st_rdev;
fStat.status_.st_size = size;
fStat.status_.st_atime = atime;
fStat.status_.st_mtime = mtime;
fStat.status_.st_ctime = ctime;
// Read end of machine info list
is.readEnd("fileStat");
// Check state of Istream
is.check("Istream& operator>>(Istream&, fileStat&)");
return is;
}
// Output in list syntax
Ostream& operator<<(Ostream& os, const fileStat& fStat)
{
//Set precision so 32bit unsigned int can be printed
// int oldPrecision = os.precision();
int oldPrecision = 0;
os.precision(10);
os << token::BEGIN_LIST << fStat.isValid_
<< token::SPACE << label(major(fStat.status_.st_dev))
<< token::SPACE << label(minor(fStat.status_.st_dev))
<< token::SPACE << label(fStat.status_.st_ino)
<< token::SPACE << label(fStat.status_.st_mode)
<< token::SPACE << label(fStat.status_.st_uid)
<< token::SPACE << label(fStat.status_.st_gid)
<< token::SPACE << label(major(fStat.status_.st_rdev))
<< token::SPACE << label(minor(fStat.status_.st_rdev))
<< token::SPACE << label(fStat.status_.st_size)
<< token::SPACE << label(fStat.status_.st_atime)
<< token::SPACE << label(fStat.status_.st_mtime)
<< token::SPACE << label(fStat.status_.st_ctime)
<< token::END_LIST;
os.precision(oldPrecision);
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,134 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileStat
Description
Wrapper for stat() system call.
Warning
on Linux (an maybe on others) a stat() of an nfs mounted (remote)
file does never timeout and cannot be interrupted!
So e.g. Foam::ping first and hope nfs is running.
SourceFiles
fileStat.C
\*---------------------------------------------------------------------------*/
#ifndef fileStat_H
#define fileStat_H
#include <sys/stat.h>
#include <sys/types.h>
#include "label.H"
#include "fileName.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
class fileStat;
Istream& operator>>(Istream&, fileStat&);
Ostream& operator<<(Ostream&, const fileStat&);
/*---------------------------------------------------------------------------*\
Class fileStat Declaration
\*---------------------------------------------------------------------------*/
class fileStat
{
// Private data
struct stat status_;
bool isValid_;
public:
// Constructors
//- Empty constructor
fileStat();
//- Construct from components
fileStat(const fileName& fName, const unsigned int maxTime=0);
//- Construct from Istream
fileStat(Istream&);
// Member Functions
// Access
//- Raw status
const struct stat& status() const
{
return status_;
}
//- Did constructor fail
bool isValid() const
{
return isValid_;
}
// Check
//- compare two fileStats for same device
bool sameDevice(const fileStat& stat2) const;
//- compare two fileStats for same Inode
bool sameINode(const fileStat& stat2) const;
//- compare state against inode
bool sameINode(const label iNode) const;
// IOstream Operators
friend Istream& operator>>(Istream&, fileStat&);
friend Ostream& operator<<(Ostream&, const fileStat&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,310 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "IStringStream.H"
#include "OStringStream.H"
#include "OSspecific.H"
#include "IFstream.H"
#include "readHexLabel.H"
#include <cxxabi.h>
#include <execinfo.h>
#include <dlfcn.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
string pOpen(const string &cmd, label line=0)
{
const int MAX = 1000;
FILE *cmdPipe = popen(cmd.c_str(), "r");
if (cmdPipe)
{
// Read line number of lines
for (label cnt = 0; cnt <= line; cnt++)
{
char buffer[MAX];
char* s = fgets(buffer, MAX-1, cmdPipe);
if (s == NULL)
{
return "";
}
if (cnt == line)
{
string str(buffer);
return str.substr(0, str.size()-1);
}
}
pclose(cmdPipe);
}
return "";
}
// use popen to call addr2line (using bfd.h directly would have
// meant relinking everything)
void printSourceFileAndLine
(
Ostream& os,
const HashTable<label, fileName>& addressMap,
const fileName& filename,
const word& address
)
{
word myAddress = address;
if (filename.ext() == "so")
{
// Convert offset into .so into offset into executable.
void *addr;
sscanf(myAddress.c_str(), "%p",&addr);
Dl_info info;
dladdr(addr, &info);
unsigned long offset = ulong(info.dli_fbase);
IStringStream addressStr(address.substr(2));
label addressValue = readHexLabel(addressStr);
label relativeAddress = addressValue-offset;
// Reconstruct hex word from address
OStringStream nStream;
nStream << "0x" << hex << relativeAddress;
myAddress = nStream.str();
}
if (filename[0] == '/')
{
string line = pOpen
(
"addr2line -f --demangle=auto --exe "
+ filename
+ " "
+ myAddress,
1
);
if (line == "")
{
os << " addr2line failed";
}
else if (line == "??:0")
{
os << " in " << filename;
}
else
{
string cwdLine(line.replaceAll(cwd() + '/', ""));
string homeLine(cwdLine.replaceAll(home(), '~'));
os << " at " << homeLine.c_str();
}
}
}
void getSymbolForRaw
(
Ostream& os,
const string& raw,
const fileName& filename,
const word& address
)
{
if (filename[0] == '/')
{
string fcnt = pOpen
(
"addr2line -f --demangle=auto --exe "
+ filename
+ " "
+ address
);
if (fcnt != "")
{
os << fcnt.c_str();
return;
}
}
os << "Uninterpreted: " << raw.c_str();
}
void error::printStack(Ostream& os)
{
// Reads the starting addresses for the dynamically linked libraries
// from the /proc/pid/maps-file
// I'm afraid this works only for Linux 2.6-Kernels (may work on 2.4)
// Note2: the filenames in here will have softlinks resolved so will
// go wrong when having e.g. OpenFOAM installed under a softlink.
HashTable<label, fileName> addressMap;
{
IFstream is("/proc/" + name(pid()) + "/maps");
while(is.good())
{
string line;
is.getLine(line);
string::size_type space = line.rfind(' ') + 1;
fileName libPath = line.substr(space, line.size()-space);
if (libPath.size() > 0 && libPath[0] == '/')
{
string offsetString(line.substr(0, line.find('-')));
IStringStream offsetStr(offsetString);
addressMap.insert(libPath, readHexLabel(offsetStr));
}
}
}
// Get raw stack symbols
void *array[100];
size_t size = backtrace(array, 100);
char **strings = backtrace_symbols(array, size);
// See if they contain function between () e.g. "(__libc_start_main+0xd0)"
// and see if cplus_demangle can make sense of part before +
for (size_t i = 0; i < size; i++)
{
string msg(strings[i]);
fileName programFile;
word address;
os << '#' << label(i) << " ";
//os << "Raw : " << msg << "\n\t";
{
string::size_type lPos = msg.find('[');
string::size_type rPos = msg.find(']');
if (lPos != string::npos && rPos != string::npos && lPos<rPos)
{
address = msg.substr(lPos+1, rPos-lPos-1);
}
string::size_type bracketPos = msg.find('(');
string::size_type spacePos = msg.find(' ');
if (bracketPos != string::npos || spacePos != string::npos)
{
programFile = msg.substr(0, min(spacePos, bracketPos));
// not an absolute path
if (programFile[0] != '/')
{
string tmp = pOpen("which "+programFile);
if (tmp[0] == '/' || tmp[0] == '~')
{
programFile = tmp;
}
}
}
}
string::size_type bracketPos = msg.find('(');
if (bracketPos != string::size_type(string::npos))
{
string::size_type start = bracketPos+1;
string::size_type plusPos = msg.find('+', start);
if (plusPos != string::size_type(string::npos))
{
string cName(msg.substr(start, plusPos-start));
int status;
char* cplusNamePtr = abi::__cxa_demangle
(
cName.c_str(),
NULL, // have it malloc itself
0,
&status
);
if (status == 0 && cplusNamePtr)
{
os << cplusNamePtr;
free(cplusNamePtr);
}
else
{
os << cName.c_str();
}
}
else
{
string::size_type endBracketPos = msg.find(')', start);
if (endBracketPos != string::size_type(string::npos))
{
string fullName(msg.substr(start, endBracketPos-start));
os << fullName.c_str() << nl;
}
else
{
// Print raw message
getSymbolForRaw(os, msg, programFile, address);
}
}
}
else
{
// Print raw message
getSymbolForRaw(os, msg, programFile, address);
}
printSourceFileAndLine(os, addressMap, programFile, address);
os << nl;
}
free(strings);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,252 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "sigFpe.H"
#include "JobInfo.H"
#include "OSspecific.H"
#include "IOstreams.H"
#ifdef LINUX_GNUC
# ifndef __USE_GNU
# define __USE_GNU
# endif
# include <fenv.h>
# include <malloc.h>
#elif defined(sgiN32) || defined(sgiN32Gcc)
# include <sigfpe.h>
#endif
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
struct sigaction Foam::sigFpe::oldAction_;
#if defined(LINUX)
void *(*Foam::sigFpe::old_malloc_hook)(size_t, const void *) = NULL;
void* Foam::sigFpe::my_malloc_hook(size_t size, const void *caller)
{
void *result;
// Restore all old hooks
__malloc_hook = old_malloc_hook;
// Call recursively
result = malloc (size);
// initialize to signalling nan
# ifdef SP
const uint32_t sNAN = 0x7ff7fffflu;
int nScalars = size / sizeof(scalar);
uint32_t* dPtr = reinterpret_cast<uint32_t*>(result);
for (int i = 0; i < nScalars; i++)
{
*dPtr++ = sNAN;
}
# else
const uint64_t sNAN = 0x7ff7ffffffffffffllu;
int nScalars = size/sizeof(scalar);
uint64_t* dPtr = reinterpret_cast<uint64_t*>(result);
for (int i = 0; i < nScalars; i++)
{
*dPtr++ = sNAN;
}
# endif
// Restore our own hooks
__malloc_hook = my_malloc_hook;
return result;
}
#endif
#ifdef LINUX_GNUC
void Foam::sigFpe::sigFpeHandler(int)
{
// Reset old handling
if (sigaction(SIGFPE, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigSegv::sigFpeHandler()"
) << "Cannot reset SIGFPE trapping"
<< abort(FatalError);
}
// Update jobInfo file
jobInfo.signalEnd();
error::printStack(Perr);
// Throw signal (to old handler)
raise(SIGFPE);
}
#endif
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sigFpe::sigFpe()
{
oldAction_.sa_handler = NULL;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sigFpe::~sigFpe()
{
if (env("FOAM_SIGFPE"))
{
# ifdef LINUX_GNUC
// Reset signal
if (oldAction_.sa_handler && sigaction(SIGFPE, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigFpe::~sigFpe()"
) << "Cannot reset SIGFPE trapping"
<< abort(FatalError);
}
# endif
}
if (env("FOAM_SETNAN"))
{
# ifdef LINUX_GNUC
// Reset to standard malloc
if (oldAction_.sa_handler)
{
__malloc_hook = old_malloc_hook;
}
# endif
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigFpe::set()
{
if (oldAction_.sa_handler)
{
FatalErrorIn
(
"Foam::sigFpe::set()"
) << "Cannot call sigFpe::set() more than once"
<< abort(FatalError);
}
if (env("FOAM_SIGFPE"))
{
# ifdef LINUX_GNUC
feenableexcept
(
FE_DIVBYZERO
| FE_INVALID
| FE_OVERFLOW
);
struct sigaction newAction;
newAction.sa_handler = sigFpeHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGFPE, &newAction, &oldAction_) < 0)
{
FatalErrorIn
(
"Foam::sigFpe::set()"
) << "Cannot set SIGFPE trapping"
<< abort(FatalError);
}
# elif defined(sgiN32) || defined(sgiN32Gcc)
sigfpe_[_DIVZERO].abort=1;
sigfpe_[_OVERFL].abort=1;
sigfpe_[_INVALID].abort=1;
sigfpe_[_DIVZERO].trace=1;
sigfpe_[_OVERFL].trace=1;
sigfpe_[_INVALID].trace=1;
handle_sigfpes
(
_ON,
_EN_DIVZERO
| _EN_INVALID
| _EN_OVERFL,
0,
_ABORT_ON_ERROR,
NULL
);
# endif
}
if (env("FOAM_SETNAN"))
{
# ifdef LINUX_GNUC
// Set our malloc
__malloc_hook = Foam::sigFpe::my_malloc_hook;
# endif
}
}
// ************************************************************************* //

View File

@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::sigFpe
Description
Set up trapping for floating point exceptions (signal FPE).
Controlled by two env vars:
@param FOAM_SIGFPE \n
exception trapping
@param FOAM_SETNAN \n
initialization of all malloced memory to NaN. If FOAM_SIGFPE
also set, this will cause usage of uninitialized scalars to trigger
an abort.
SourceFiles
sigFpe.C
\*---------------------------------------------------------------------------*/
#ifndef sigFpe_H
#define sigFpe_H
#include "OSspecific.H"
#include <signal.h>
#if defined(linux) || defined(linuxAMD64) || defined(linuxIA64)
# define LINUX
#endif
#if defined(LINUX) && defined(__GNUC__)
# define LINUX_GNUC
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class sigFpe Declaration
\*---------------------------------------------------------------------------*/
class sigFpe
{
// Private data
//- Saved old signal trapping setting
static struct sigaction oldAction_;
# ifdef LINUX
//- Saved old malloc
static void *(*old_malloc_hook)(size_t, const void *);
//- nan malloc function. From malloc_hook manpage.
static void* my_malloc_hook(size_t size, const void *caller);
# endif
// Static data members
# ifdef LINUX_GNUC
//- Handler for caught signals
static void sigFpeHandler(int);
# endif
public:
// Constructors
sigFpe();
// Destructor
~sigFpe();
// Member functions
void set();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,110 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "sigInt.H"
#include "JobInfo.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
struct sigaction Foam::sigInt::oldAction_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::sigInt::sigIntHandler(int)
{
// Reset old handling
if (sigaction(SIGINT, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigInt::sigIntHandler()"
) << "Cannot reset SIGINT trapping"
<< abort(FatalError);
}
// Update jobInfo file
jobInfo.signalEnd();
// Throw signal (to old handler)
raise(SIGINT);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sigInt::sigInt()
{
oldAction_.sa_handler = NULL;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sigInt::~sigInt()
{
// Reset old handling
if (sigaction(SIGINT, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigInt::~sigInt()"
) << "Cannot reset SIGINT trapping"
<< abort(FatalError);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigInt::set()
{
if (oldAction_.sa_handler)
{
FatalErrorIn
(
"Foam::sigInt::set()"
) << "Cannot call sigInt::set() more than once"
<< abort(FatalError);
}
struct sigaction newAction;
newAction.sa_handler = sigIntHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGINT, &newAction, &oldAction_) < 0)
{
FatalErrorIn
(
"Foam::sigInt::set()"
) << "Cannot set SIGINT trapping"
<< abort(FatalError);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::sigInt
Description
Signal handler for INT interupt.
The standard interupt handler is overridden to ensure that the
runningJob file is removed.
See Also
Foam::JobInfo
SourceFiles
sigInt.C
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class sigInt Declaration
\*---------------------------------------------------------------------------*/
class sigInt
{
// Private data
//- Saved old signal trapping setting
static struct sigaction oldAction_;
// Private Member Functions
static void sigIntHandler(int);
public:
// Constructors
sigInt();
// Destructor
~sigInt();
// Member functions
void set();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "sigQuit.H"
#include "JobInfo.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
struct sigaction Foam::sigQuit::oldAction_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::sigQuit::sigQuitHandler(int)
{
// Reset old handling
if (sigaction(SIGQUIT, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigQuit::sigQuitHandler()"
) << "Cannot reset SIGQUIT trapping"
<< abort(FatalError);
}
// Update jobInfo file
jobInfo.signalEnd();
error::printStack(Perr);
// Throw signal (to old handler)
raise(SIGQUIT);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sigQuit::sigQuit()
{
oldAction_.sa_handler = NULL;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sigQuit::~sigQuit()
{
// Reset old handling
if (oldAction_.sa_handler && sigaction(SIGQUIT, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigQuit::~sigQuit()"
) << "Cannot reset SIGQUIT trapping"
<< abort(FatalError);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigQuit::set()
{
if (oldAction_.sa_handler)
{
FatalErrorIn
(
"Foam::sigQuit::set()"
) << "Cannot call sigQuit::set() more than once"
<< abort(FatalError);
}
struct sigaction newAction;
newAction.sa_handler = sigQuitHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGQUIT, &newAction, &oldAction_) < 0)
{
FatalErrorIn
(
"Foam::sigQuit::set()"
) << "Cannot set SIGQUIT trapping"
<< abort(FatalError);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::sigQuit
Description
Signal handler for QUIT interupt.
The standard interupt handler is overridden to ensure that the
runningJob file is removed.
See Also
Foam::JobInfo
SourceFiles
sigQuit.C
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class sigQuit Declaration
\*---------------------------------------------------------------------------*/
class sigQuit
{
// Private data
//- Saved old signal trapping setting
static struct sigaction oldAction_;
// Private Member Functions
static void sigQuitHandler(int);
public:
// Constructors
sigQuit();
// Destructor
~sigQuit();
// Member functions
void set();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "sigSegv.H"
#include "JobInfo.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
struct sigaction Foam::sigSegv::oldAction_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::sigSegv::sigSegvHandler(int)
{
// Reset old handling
if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigSegv::sigSegvHandler()"
) << "Cannot reset SIGSEGV trapping"
<< abort(FatalError);
}
// Update jobInfo file
jobInfo.signalEnd();
error::printStack(Perr);
// Throw signal (to old handler)
raise(SIGSEGV);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sigSegv::sigSegv()
{
oldAction_.sa_handler = NULL;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sigSegv::~sigSegv()
{
// Reset old handling
if (sigaction(SIGSEGV, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigSegv::~sigSegv()"
) << "Cannot reset SIGSEGV trapping"
<< abort(FatalError);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigSegv::set()
{
if (oldAction_.sa_handler)
{
FatalErrorIn
(
"Foam::sigSegv::set()"
) << "Cannot call sigSegv::set() more than once"
<< abort(FatalError);
}
struct sigaction newAction;
newAction.sa_handler = sigSegvHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGSEGV, &newAction, &oldAction_) < 0)
{
FatalErrorIn
(
"Foam::sigSegv::set()"
) << "Cannot set SIGSEGV trapping"
<< abort(FatalError);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::sigSegv
Description
Signal handler for SEGV interupt.
The standard interupt handler is overridden to ensure that the
runningJob file is removed.
See Also
Foam::JobInfo
SourceFiles
sigSegv.C
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include <signal.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class sigSegv Declaration
\*---------------------------------------------------------------------------*/
class sigSegv
{
// Private data
//- Saved old signal trapping setting
static struct sigaction oldAction_;
// Private Member Functions
static void sigSegvHandler(int);
public:
// Constructors
sigSegv();
// Destructor
~sigSegv();
// Member functions
void set();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

139
src/OSspecific/Unix/timer.C Normal file
View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include <unistd.h>
#include "error.H"
#include "timer.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::timer, 0);
jmp_buf Foam::timer::envAlarm;
struct sigaction Foam::timer::oldAction_;
unsigned int Foam::timer::oldTimeOut_ = 0;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::timer::signalHandler(int)
{
if (debug)
{
Info<< "Foam::timer::signalHandler(int sig) : "
<< " timed out. Jumping."
<< endl;
}
longjmp(envAlarm, 1);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::timer::timer(const unsigned int newTimeOut)
:
newTimeOut_(newTimeOut)
{
if (newTimeOut > 0)
{
// Is singleton since handler is static function
if (oldTimeOut_ != 0)
{
FatalErrorIn
(
"Foam::timer::timer(const unsigned int)"
) << "timer already used."
<< abort(FatalError);
}
// Install alarm signal handler:
// - do not block any signals while in it
// - clear list of signals to mask
struct sigaction newAction;
newAction.sa_handler = timer::signalHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(SIGALRM, &newAction, &oldAction_) < 0)
{
FatalErrorIn
(
"Foam::timer::timer(const unsigned int)"
) << "sigaction(SIGALRM) error"
<< abort(FatalError);
}
oldTimeOut_ = ::alarm(newTimeOut);
if (debug)
{
Info<< "Foam::timer::timer(const unsigned int) : "
<< " installing timeout " << int(newTimeOut_)
<< " seconds"
<< " (overriding old timeout " << int(oldTimeOut_)
<< ")." << endl;
}
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::timer::~timer()
{
if (newTimeOut_ > 0)
{
if (debug)
{
Info<< "Foam::timer::~timer(const unsigned int) : timeOut="
<< int(newTimeOut_)
<< " : resetting timeOut to " << int(oldTimeOut_) << endl;
}
// Reset timer
::alarm(oldTimeOut_);
oldTimeOut_ = 0;
// Restore signal handler
if (sigaction(SIGALRM, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::timer::~timer(const struct sigaction&"
"const struct sigaction&)"
) << "sigaction(SIGALRM) error"
<< abort(FatalError);
}
}
}
// ************************************************************************* //

135
src/OSspecific/Unix/timer.H Normal file
View File

@ -0,0 +1,135 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::timer
Description
Implements a timeout mechanism via sigalarm.
Example usage:
@code
timer myTimer(5); // 5 sec
..
if (timedOut(myTimer))
{
// timed out
}
else
{
// do something possible blocking
}
@endcode
Constructor set signal handler on sigalarm and alarm(). Destructor
clears these.
timedOut is macro because setjmp can't be in member function of timer.
?something to do with stack frames.
Warning
The setjmp restores complete register state so including local vars
held in regs. So if in blocking part something gets calced in a stack
based variable make sure it is declared 'volatile'.
SourceFiles
timer.C
\*---------------------------------------------------------------------------*/
#ifndef timer_H
#define timer_H
#include "className.H"
#include <signal.h>
#include <setjmp.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- check it a timeout has occured
// keep setjmp in same stack frame so no function calls
#define timedOut(x) \
(((x).newTimeOut_ > 0) ? setjmp(Foam::timer::envAlarm) : false)
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class timer Declaration
\*---------------------------------------------------------------------------*/
class timer
{
// Private data
//- old signal masks
static struct sigaction oldAction_;
//- old alarm() value
static unsigned int oldTimeOut_;
// Private Member Functions
//- alarm handler
static void signalHandler(int);
public:
// Public data
//- Declare name of the class and its debug switch
ClassName("timer");
//- current time out value. Needed by macro timedOut
unsigned int newTimeOut_;
//- state for setjmp. Needed by macro timedOut
static jmp_buf envAlarm;
// Constructors
//- Construct from components.
// newTimeOut=0 makes it do nothing.
timer(const unsigned int newTimeOut);
// Destructor
~timer();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //