- add additional control via a Foam::infoDetailLevel flag, which is supported by a 'DetailLevel' macro. Eg, DetailLevel << "some information" << nl - When infoDetailLevel is zero, the stdout for all Foam::system() calls are also redirected to stderr to prevent child output from appearing on the parent. - close stdin before exec in system call.
This commit is contained in:
parent
83c9d3b287
commit
6390c18381
@ -124,7 +124,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (nProcs)
|
||||
{
|
||||
// Info<< "Remove " << timeDirs.size()
|
||||
// Serr<< "Remove " << timeDirs.size()
|
||||
// << " processor time directories" << nl;
|
||||
|
||||
forAllReverse(timeDirs, timei)
|
||||
@ -153,7 +153,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
// Info<< "Remove " << timeDirs.size()
|
||||
// Serr<< "Remove " << timeDirs.size()
|
||||
// << " time directories" << nl;
|
||||
|
||||
forAllReverse(timeDirs, timei)
|
||||
|
@ -122,7 +122,7 @@ int main(int argc, char *argv[])
|
||||
const scalar scaling = args.lookupOrDefault<scalar>("scale", -1);
|
||||
if (scaling > 0)
|
||||
{
|
||||
Info<< " -scale " << scaling << nl;
|
||||
DetailInfo << " -scale " << scaling << nl;
|
||||
surf.scalePoints(scaling);
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,6 @@ notTest()
|
||||
# Extract 'numberOfSubdomains' from system/decomposeParDict
|
||||
# (or alternative location).
|
||||
#
|
||||
# Note that '#include' and other directives are disabled - only entries that
|
||||
# are in the dictionary are considered.
|
||||
#
|
||||
# On failure:
|
||||
# return '1'
|
||||
# exit status 1
|
||||
@ -68,14 +65,14 @@ getNumberOfProcessors()
|
||||
local dict="${1:-system/decomposeParDict}"
|
||||
|
||||
# Re-use positional parameters for automatic whitespace elimination
|
||||
set -- $(foamDictionary -disableFunctionEntries -entry numberOfSubdomains -value "$dict" 2>/dev/null)
|
||||
set -- $(foamDictionary -entry numberOfSubdomains -value "$dict" 2>/dev/null)
|
||||
|
||||
if [ "$#" -eq 1 ]
|
||||
then
|
||||
echo "$1"
|
||||
else
|
||||
echo "Error getting 'numberOfSubdomains' from '$dict'" 1>&2
|
||||
echo 1 # serial as fallback
|
||||
echo 1 # Fallback is 1 proc (serial)
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@ -84,9 +81,6 @@ getNumberOfProcessors()
|
||||
#
|
||||
# Extract 'application' from system/controlDict
|
||||
#
|
||||
# Note that '#include' and other directives are disabled - only entries that
|
||||
# are in the dictionary are considered.
|
||||
#
|
||||
# On failure:
|
||||
# return 'false' which is also a command (ie, shell builtin or /bin/false)
|
||||
# exit status 1
|
||||
@ -94,14 +88,14 @@ getNumberOfProcessors()
|
||||
getApplication()
|
||||
{
|
||||
# Re-use positional parameters for automatic whitespace elimination
|
||||
set -- $(foamDictionary -disableFunctionEntries -entry application -value system/controlDict 2>/dev/null)
|
||||
set -- $(foamDictionary -entry application -value system/controlDict 2>/dev/null)
|
||||
|
||||
if [ "$#" -eq 1 ]
|
||||
then
|
||||
echo "$1"
|
||||
else
|
||||
echo "Error getting 'application' from system/controlDict" 1>&2
|
||||
echo false
|
||||
echo false # Fallback
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ Description
|
||||
#include <link.h>
|
||||
#endif
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
@ -74,9 +75,7 @@ namespace Foam
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * * //
|
||||
|
||||
//! \cond fileScope
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
// Like fileName "/" global operator, but retain any invalid characters
|
||||
static inline Foam::fileName fileNameConcat
|
||||
@ -106,7 +105,23 @@ static inline Foam::fileName fileNameConcat
|
||||
// Both strings are empty
|
||||
return Foam::fileName();
|
||||
}
|
||||
//! \endcond
|
||||
|
||||
|
||||
// After a fork in system(), before the exec() do the following
|
||||
// 1. close stdin
|
||||
// 2. redirect stdout to stderr when infoDetailLevel == 0
|
||||
static inline void redirects()
|
||||
{
|
||||
// Close stdin(0) - unchecked return value
|
||||
(void) ::close(STDIN_FILENO);
|
||||
|
||||
// Redirect stdout(1) to stderr(2) '1>&2'
|
||||
if (Foam::infoDetailLevel == 0)
|
||||
{
|
||||
// This is correct. 1>&2 means dup2(2, 1);
|
||||
(void) ::dup2(STDERR_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -1312,6 +1327,7 @@ static int waitpid(const pid_t pid)
|
||||
// in parent - blocking wait
|
||||
// modest treatment of signals (in child)
|
||||
// treat 'stopped' like exit (suspend/continue)
|
||||
|
||||
while (true)
|
||||
{
|
||||
pid_t wpid = ::waitpid(pid, &status, WUNTRACED);
|
||||
@ -1354,11 +1370,7 @@ static int waitpid(const pid_t pid)
|
||||
}
|
||||
|
||||
|
||||
int Foam::system
|
||||
(
|
||||
const std::string& command,
|
||||
const bool background
|
||||
)
|
||||
int Foam::system(const std::string& command, const bool bg)
|
||||
{
|
||||
if (command.empty())
|
||||
{
|
||||
@ -1369,17 +1381,22 @@ int Foam::system
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t child_pid = ::vfork(); // NB: vfork, not fork!
|
||||
const pid_t child_pid = ::vfork(); // NB: vfork, not fork!
|
||||
|
||||
if (child_pid == -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "vfork() failed for system command " << command
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (child_pid == 0)
|
||||
return -1; // fallback error value
|
||||
}
|
||||
else if (child_pid == 0)
|
||||
{
|
||||
// in child
|
||||
// In child
|
||||
|
||||
// Close or redirect file descriptors
|
||||
redirects();
|
||||
|
||||
// execl uses the current environ
|
||||
(void) ::execl
|
||||
@ -1395,27 +1412,19 @@ int Foam::system
|
||||
FatalErrorInFunction
|
||||
<< "exec failed: " << command
|
||||
<< exit(FatalError);
|
||||
|
||||
return -1; // fallback error value
|
||||
}
|
||||
|
||||
|
||||
// In parent:
|
||||
// In parent
|
||||
// - started as background process, or blocking wait for the child
|
||||
|
||||
if (background)
|
||||
{
|
||||
// Started as background process
|
||||
return 0;
|
||||
}
|
||||
|
||||
// blocking wait for the child
|
||||
return waitpid(child_pid);
|
||||
return (bg ? 0 : waitpid(child_pid));
|
||||
}
|
||||
|
||||
|
||||
int Foam::system
|
||||
(
|
||||
const CStringList& command,
|
||||
const bool background
|
||||
)
|
||||
int Foam::system(const CStringList& command, const bool bg)
|
||||
{
|
||||
const int argc = command.size();
|
||||
|
||||
@ -1432,17 +1441,25 @@ int Foam::system
|
||||
// triggered by fork.
|
||||
// The normal system() command has a fork buried in it that causes
|
||||
// issues with infiniband and openmpi etc.
|
||||
pid_t child_pid = ::vfork();
|
||||
|
||||
const pid_t child_pid = ::vfork();
|
||||
|
||||
if (child_pid == -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "vfork() failed for system command " << command[0]
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (child_pid == 0)
|
||||
return -1; // fallback error value
|
||||
}
|
||||
else if (child_pid == 0)
|
||||
{
|
||||
// In child:
|
||||
// In child
|
||||
|
||||
// Close or redirect file descriptors
|
||||
redirects();
|
||||
|
||||
|
||||
// Need command and arguments separately.
|
||||
// args is a nullptr-terminated list of c-strings
|
||||
|
||||
@ -1453,32 +1470,24 @@ int Foam::system
|
||||
FatalErrorInFunction
|
||||
<< "exec(" << command[0] << ", ...) failed"
|
||||
<< exit(FatalError);
|
||||
|
||||
return -1; // fallback error value
|
||||
}
|
||||
|
||||
|
||||
// In parent:
|
||||
// In parent
|
||||
// - started as background process, or blocking wait for the child
|
||||
|
||||
if (background)
|
||||
{
|
||||
// Started as background process
|
||||
return 0;
|
||||
}
|
||||
|
||||
// blocking wait for the child
|
||||
return waitpid(child_pid);
|
||||
return (bg ? 0 : waitpid(child_pid));
|
||||
}
|
||||
|
||||
|
||||
int Foam::system
|
||||
(
|
||||
const Foam::UList<Foam::string>& command,
|
||||
const bool background
|
||||
)
|
||||
int Foam::system(const Foam::UList<Foam::string>& command, const bool bg)
|
||||
{
|
||||
// In the future simply call the CStringList version:
|
||||
//
|
||||
// const CStringList cmd(command);
|
||||
// return Foam::system(cmd, background);
|
||||
// return Foam::system(cmd, bg);
|
||||
|
||||
const int argc = command.size();
|
||||
|
||||
@ -1495,17 +1504,25 @@ int Foam::system
|
||||
// triggered by fork.
|
||||
// The normal system() command has a fork buried in it that causes
|
||||
// issues with infiniband and openmpi etc.
|
||||
pid_t child_pid = ::vfork();
|
||||
|
||||
const pid_t child_pid = ::vfork();
|
||||
|
||||
if (child_pid == -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "vfork() failed for system command " << command[0]
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (child_pid == 0)
|
||||
return -1; // fallback error value
|
||||
}
|
||||
else if (child_pid == 0)
|
||||
{
|
||||
// In child:
|
||||
// In child
|
||||
|
||||
// Close or redirect file descriptors
|
||||
redirects();
|
||||
|
||||
|
||||
// Need command and arguments separately.
|
||||
// args is a nullptr-terminated list of c-strings
|
||||
|
||||
@ -1522,19 +1539,15 @@ int Foam::system
|
||||
FatalErrorInFunction
|
||||
<< "exec(" << command[0] << ", ...) failed"
|
||||
<< exit(FatalError);
|
||||
|
||||
return -1; // fallback error value
|
||||
}
|
||||
|
||||
|
||||
// In parent:
|
||||
// In parent
|
||||
// - started as background process, or blocking wait for the child
|
||||
|
||||
if (background)
|
||||
{
|
||||
// Started as background process
|
||||
return 0;
|
||||
}
|
||||
|
||||
// blocking wait for the child
|
||||
return waitpid(child_pid);
|
||||
return (bg ? 0 : waitpid(child_pid));
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,10 +47,19 @@ Description
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
//- An Istream wrapper for std::cin
|
||||
extern ISstream Sin;
|
||||
|
||||
//- An Ostream wrapper for std::cout
|
||||
extern OSstream Sout;
|
||||
|
||||
//- An Ostream wrapper for std::cerr
|
||||
extern OSstream Serr;
|
||||
|
||||
//- An Ostream wrapper for parallel output to std::cout
|
||||
extern prefixOSstream Pout;
|
||||
|
||||
//- An Ostream wrapper for parallel output to std::cerr
|
||||
extern prefixOSstream Perr;
|
||||
}
|
||||
|
||||
|
@ -93,8 +93,6 @@ void Foam::Time::readDict()
|
||||
}
|
||||
|
||||
// Check for local switches and settings
|
||||
// - echo values, unless the application was invoked with noBanner
|
||||
const bool echo = argList::bannerEnabled();
|
||||
|
||||
const dictionary* localDict = nullptr;
|
||||
|
||||
@ -105,11 +103,9 @@ void Foam::Time::readDict()
|
||||
&& localDict->size()
|
||||
)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< "Overriding DebugSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
}
|
||||
DetailInfo
|
||||
<< "Overriding DebugSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::debugObjects();
|
||||
|
||||
@ -123,10 +119,7 @@ void Foam::Time::readDict()
|
||||
{
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
if (echo)
|
||||
{
|
||||
Info<< " " << iter() << nl;
|
||||
}
|
||||
DetailInfo << " " << iter() << nl;
|
||||
|
||||
if (iter().isDict())
|
||||
{
|
||||
@ -157,11 +150,9 @@ void Foam::Time::readDict()
|
||||
&& localDict->size()
|
||||
)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< "Overriding InfoSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
}
|
||||
DetailInfo
|
||||
<< "Overriding InfoSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::infoObjects();
|
||||
|
||||
@ -175,10 +166,7 @@ void Foam::Time::readDict()
|
||||
{
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
if (echo)
|
||||
{
|
||||
Info<< " " << iter() << nl;
|
||||
}
|
||||
DetailInfo << " " << iter() << nl;
|
||||
|
||||
if (iter().isDict())
|
||||
{
|
||||
@ -208,11 +196,9 @@ void Foam::Time::readDict()
|
||||
&& localDict->size()
|
||||
)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< "Overriding OptimisationSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
}
|
||||
DetailInfo
|
||||
<< "Overriding OptimisationSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::optimisationObjects();
|
||||
|
||||
@ -224,10 +210,7 @@ void Foam::Time::readDict()
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< " " << iter() << nl;
|
||||
}
|
||||
DetailInfo << " " << iter() << nl;
|
||||
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
@ -263,10 +246,7 @@ void Foam::Time::readDict()
|
||||
&& fileHandler().type() != fileHandlerName
|
||||
)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< "Overriding fileHandler to " << fileHandlerName << nl;
|
||||
}
|
||||
DetailInfo << "Overriding fileHandler to " << fileHandlerName << nl;
|
||||
|
||||
// Remove old watches since destroying the file
|
||||
fileNameList oldWatched(controlDict_.watchIndices().size());
|
||||
@ -304,11 +284,9 @@ void Foam::Time::readDict()
|
||||
&& localDict->size()
|
||||
)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< "Overriding DimensionedConstants according to "
|
||||
<< controlDict_.name() << nl;
|
||||
}
|
||||
DetailInfo
|
||||
<< "Overriding DimensionedConstants according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::dimensionedConstantObjects();
|
||||
|
||||
@ -325,7 +303,7 @@ void Foam::Time::readDict()
|
||||
{
|
||||
obj->readData(dummyIs);
|
||||
|
||||
if (echo)
|
||||
if (Foam::infoDetailLevel > 0)
|
||||
{
|
||||
Info<< " ";
|
||||
obj->writeData(Info);
|
||||
@ -343,11 +321,9 @@ void Foam::Time::readDict()
|
||||
&& localDict->size()
|
||||
)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< "Overriding DimensionSets according to "
|
||||
<< controlDict_.name() << nl;
|
||||
}
|
||||
DetailInfo
|
||||
<< "Overriding DimensionSets according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::dimensionSetObjects();
|
||||
|
||||
@ -358,10 +334,7 @@ void Foam::Time::readDict()
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
if (echo)
|
||||
{
|
||||
Info<< *localDict << nl;
|
||||
}
|
||||
DetailInfo << *localDict << nl;
|
||||
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -66,7 +66,8 @@ bool Foam::functionEntries::calcEntry::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
Info<< "Using #calc at line " << is.lineNumber()
|
||||
DetailInfo
|
||||
<< "Using #calc at line " << is.lineNumber()
|
||||
<< " in file " << parentDict.name() << endl;
|
||||
|
||||
dynamicCode::checkSecurity
|
||||
@ -110,7 +111,8 @@ bool Foam::functionEntries::calcEntry::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
Info<< "Using #calc at line " << is.lineNumber()
|
||||
DetailInfo
|
||||
<< "Using #calc at line " << is.lineNumber()
|
||||
<< " in file " << parentDict.name() << endl;
|
||||
|
||||
dynamicCode::checkSecurity
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -147,7 +147,8 @@ Foam::functionEntries::codeStream::getFunction
|
||||
|
||||
if (!lib)
|
||||
{
|
||||
Info<< "Using #codeStream with " << libPath << endl;
|
||||
DetailInfo
|
||||
<< "Using #codeStream with " << libPath << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -372,7 +373,8 @@ bool Foam::functionEntries::codeStream::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
Info<< "Using #codeStream at line " << is.lineNumber()
|
||||
DetailInfo
|
||||
<< "Using #codeStream at line " << is.lineNumber()
|
||||
<< " in file " << parentDict.name() << endl;
|
||||
|
||||
dynamicCode::checkSecurity
|
||||
@ -405,7 +407,8 @@ bool Foam::functionEntries::codeStream::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
Info<< "Using #codeStream at line " << is.lineNumber()
|
||||
DetailInfo
|
||||
<< "Using #codeStream at line " << is.lineNumber()
|
||||
<< " in file " << parentDict.name() << endl;
|
||||
|
||||
dynamicCode::checkSecurity
|
||||
|
@ -141,7 +141,7 @@ bool Foam::functionEntries::includeEntry::execute
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::log)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
DetailInfo << fName << endl;
|
||||
}
|
||||
|
||||
// Add watch on included file
|
||||
@ -188,7 +188,7 @@ bool Foam::functionEntries::includeEntry::execute
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::log)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
DetailInfo << fName << endl;
|
||||
}
|
||||
|
||||
// Add watch on included file
|
||||
@ -234,7 +234,7 @@ bool Foam::functionEntries::sincludeEntry::execute
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::log)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
DetailInfo << fName << endl;
|
||||
}
|
||||
|
||||
// Add watch on included file
|
||||
@ -272,7 +272,7 @@ bool Foam::functionEntries::sincludeEntry::execute
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::log)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
DetailInfo << fName << endl;
|
||||
}
|
||||
|
||||
// Add watch on included file
|
||||
|
@ -102,7 +102,7 @@ bool Foam::functionEntries::includeEtcEntry::execute
|
||||
{
|
||||
if (Foam::functionEntries::includeEtcEntry::log)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
DetailInfo << fName << endl;
|
||||
}
|
||||
parentDict.read(ifs);
|
||||
return true;
|
||||
@ -137,7 +137,7 @@ bool Foam::functionEntries::includeEtcEntry::execute
|
||||
{
|
||||
if (Foam::functionEntries::includeEtcEntry::log)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
DetailInfo << fName << endl;
|
||||
}
|
||||
entry.read(parentDict, ifs);
|
||||
return true;
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -350,7 +350,8 @@ void Foam::codedBase::updateLibrary
|
||||
return;
|
||||
}
|
||||
|
||||
Info<< "Using dynamicCode for " << this->description().c_str()
|
||||
DetailInfo
|
||||
<< "Using dynamicCode for " << this->description().c_str()
|
||||
<< " at line " << dict.startLineNumber()
|
||||
<< " in " << dict.name() << endl;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,7 @@ License
|
||||
#include "dynamicCodeContext.H"
|
||||
#include "stringOps.H"
|
||||
#include "Fstream.H"
|
||||
#include "IOstreams.H"
|
||||
#include "OSspecific.H"
|
||||
#include "etcFiles.H"
|
||||
#include "dictionary.H"
|
||||
@ -210,12 +211,12 @@ bool Foam::dynamicCode::createMakeFiles() const
|
||||
mkDir(dstFile.path());
|
||||
|
||||
OFstream os(dstFile);
|
||||
//Info<< "Writing to " << dstFile << endl;
|
||||
//Debug: Info << "Writing to " << dstFile << endl;
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Failed writing " << dstFile
|
||||
<< exit(FatalError);
|
||||
<< "Failed writing " << dstFile
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
writeCommentSHA1(os);
|
||||
@ -247,12 +248,12 @@ bool Foam::dynamicCode::createMakeOptions() const
|
||||
mkDir(dstFile.path());
|
||||
|
||||
OFstream os(dstFile);
|
||||
//Info<< "Writing to " << dstFile << endl;
|
||||
//Debug: Info<< "Writing to " << dstFile << endl;
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Failed writing " << dstFile
|
||||
<< exit(FatalError);
|
||||
<< "Failed writing " << dstFile
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
writeCommentSHA1(os);
|
||||
@ -403,7 +404,8 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "Creating new library in " << this->libRelPath() << endl;
|
||||
DetailInfo
|
||||
<< "Creating new library in " << this->libRelPath() << endl;
|
||||
}
|
||||
|
||||
const label nFiles = compileFiles_.size() + copyFiles_.size();
|
||||
@ -441,7 +443,7 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const
|
||||
const fileName dstFile(outputDir/srcFile.name());
|
||||
|
||||
IFstream is(srcFile);
|
||||
//Info<< "Reading from " << is.name() << endl;
|
||||
//Debug: Info<< "Reading from " << is.name() << endl;
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -450,7 +452,7 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const
|
||||
}
|
||||
|
||||
OFstream os(dstFile);
|
||||
//Info<< "Writing to " << dstFile.name() << endl;
|
||||
//Debug: Info<< "Writing to " << dstFile.name() << endl;
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -473,7 +475,7 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const
|
||||
|
||||
mkDir(dstFile.path());
|
||||
OFstream os(dstFile);
|
||||
//Info<< "Writing to " << createFiles_[fileI].first() << endl;
|
||||
//Debug: Info<< "Writing to " << createFiles_[fileI].first() << endl;
|
||||
if (!os.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -501,15 +503,25 @@ bool Foam::dynamicCode::wmakeLibso() const
|
||||
// NOTE: could also resolve wmake command explicitly
|
||||
// cmd[0] = stringOps::expand("$WM_PROJECT_DIR/wmake/wmake");
|
||||
|
||||
Info<< "Invoking wmake libso " << this->codePath().c_str() << endl;
|
||||
if (Foam::system(cmd))
|
||||
// This can take a bit longer, so report that we are starting wmake
|
||||
|
||||
if (Foam::infoDetailLevel > 0)
|
||||
{
|
||||
return false;
|
||||
Info<< "Invoking wmake libso " << this->codePath().c_str() << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Even with details turned off, we want some feedback
|
||||
Serr
|
||||
<< "Invoking wmake libso " << this->codePath().c_str() << endl;
|
||||
}
|
||||
|
||||
if (Foam::system(cmd) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
class error;
|
||||
Ostream& operator<<(Ostream& os, const error& err);
|
||||
|
||||
@ -215,7 +215,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
class IOerror;
|
||||
Ostream& operator<<(Ostream& os, const IOerror& err);
|
||||
|
||||
@ -334,9 +334,15 @@ public:
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Global error declarations: defined in error.C
|
||||
|
||||
//- Error stream (uses stdout - output on all processes),
|
||||
//- with additional 'FOAM FATAL ERROR' header text and stack trace.
|
||||
extern error FatalError;
|
||||
|
||||
//- Error stream (uses stdout - output on all processes),
|
||||
//- with additional 'FOAM FATAL IO ERROR' header text and stack trace.
|
||||
extern IOerror FatalIOError;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
@ -31,10 +31,16 @@ Description
|
||||
|
||||
Usage
|
||||
\code
|
||||
error << "message1" << "message2" << FoamDataType << exit(error, errNo);
|
||||
error << "message1" << "message2" << FoamDataType << abort(error);
|
||||
error << "message " << someType << abort(error);
|
||||
error << "message " << someType << exit(error, errNo);
|
||||
\endcode
|
||||
|
||||
Class
|
||||
Foam::errorManipArg
|
||||
|
||||
Description
|
||||
Error stream manipulators for functions with an argument.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef errorManip_H
|
||||
@ -47,7 +53,7 @@ Usage
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
template<class Err> class errorManip;
|
||||
template<class Err> Ostream& operator<<(Ostream&, errorManip<Err>);
|
||||
|
||||
@ -90,7 +96,6 @@ inline Ostream& operator<<(Ostream& os, errorManip<Err> m)
|
||||
Class errorManipArg Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- errorManipArg
|
||||
template<class Err, class T>
|
||||
class errorManipArg
|
||||
{
|
||||
|
@ -29,8 +29,12 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// Default is 2 : report source file name and line number if available
|
||||
int Foam::messageStream::level(Foam::debug::debugSwitch("level", 2));
|
||||
|
||||
// Default is 1 : report to Info
|
||||
int Foam::infoDetailLevel(1);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -72,10 +76,8 @@ Foam::OSstream& Foam::messageStream::masterStream(const label communicator)
|
||||
{
|
||||
return operator()();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Snull;
|
||||
}
|
||||
|
||||
return Snull;
|
||||
}
|
||||
|
||||
|
||||
@ -217,7 +219,7 @@ Foam::messageStream::operator Foam::OSstream&()
|
||||
|
||||
if (maxErrors_)
|
||||
{
|
||||
errorCount_++;
|
||||
++errorCount_;
|
||||
|
||||
if (errorCount_ >= maxErrors_)
|
||||
{
|
||||
@ -244,12 +246,7 @@ Foam::messageStream::operator Foam::OSstream&()
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Variables * * * * * * * * * * * * * //
|
||||
|
||||
Foam::messageStream Foam::SeriousError
|
||||
(
|
||||
"--> FOAM Serious Error : ",
|
||||
messageStream::SERIOUS,
|
||||
100
|
||||
);
|
||||
Foam::messageStream Foam::Info("", messageStream::INFO);
|
||||
|
||||
Foam::messageStream Foam::Warning
|
||||
(
|
||||
@ -257,7 +254,12 @@ Foam::messageStream Foam::Warning
|
||||
messageStream::WARNING
|
||||
);
|
||||
|
||||
Foam::messageStream Foam::Info("", messageStream::INFO);
|
||||
Foam::messageStream Foam::SeriousError
|
||||
(
|
||||
"--> FOAM Serious Error : ",
|
||||
messageStream::SERIOUS,
|
||||
100
|
||||
);
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,9 +28,9 @@ Description
|
||||
Class to handle messaging in a simple, consistent stream-based
|
||||
manner.
|
||||
|
||||
The messageStream class is globaly instantiated with a title string and
|
||||
The messageStream class is globally instantiated with a title string and
|
||||
a severity (which controls the program termination) and a number of
|
||||
errors before termination. Errors, messages and other data are piped to
|
||||
errors before termination. Errors, messages and other data are sent to
|
||||
the messageStream class in the standard manner.
|
||||
|
||||
Usage
|
||||
@ -55,7 +55,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
// Forward declarations
|
||||
class IOstream;
|
||||
class Ostream;
|
||||
class OSstream;
|
||||
@ -71,13 +71,13 @@ class messageStream
|
||||
|
||||
public:
|
||||
|
||||
//- Severity flags
|
||||
//- Message type, or error severity flags
|
||||
enum errorSeverity
|
||||
{
|
||||
INFO, // Debugging information in event of error
|
||||
WARNING, // Warning of possible problem
|
||||
SERIOUS, // A serious problem (data corruption?)
|
||||
FATAL // Oh bugger!
|
||||
INFO, //!< General information output, not necessarily an error.
|
||||
WARNING, //!< Warning of possible problem.
|
||||
SERIOUS, //!< A serious problem - eg, data corruption.
|
||||
FATAL //!< A fatal error.
|
||||
};
|
||||
|
||||
|
||||
@ -93,8 +93,15 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
// Debug switches
|
||||
// Static data
|
||||
|
||||
//- Controls the output verbosity of messageStream
|
||||
//
|
||||
// - level == 0 : suppress all output
|
||||
// - level == 1 : normal output
|
||||
// - level >= 2 : report source file name and line number if available
|
||||
//
|
||||
// \note The default level is normally 2.
|
||||
static int level;
|
||||
|
||||
|
||||
@ -203,10 +210,31 @@ public:
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Global error declarations: defined in messageStream.C
|
||||
|
||||
extern messageStream SeriousError;
|
||||
extern messageStream Warning;
|
||||
//- Global for selective suppression of Info output.
|
||||
// This is normally accessed implicitly via the DetailInfo macro and is often
|
||||
// associated applications with suppressed banners. For example,
|
||||
//
|
||||
// \code
|
||||
// DetailInfo << "Hello, I'm running from program xyz" << nl;
|
||||
// Info<< "Found ... invalid items" << nl;
|
||||
// \endcode
|
||||
//
|
||||
// The values are normally 0 or a positive value.
|
||||
// \note This flag is initialized to 1 by default.
|
||||
extern int infoDetailLevel;
|
||||
|
||||
//- Information stream (uses stdout - output is on the master only)
|
||||
extern messageStream Info;
|
||||
|
||||
//- Warning stream (uses stdout - output is on the master only),
|
||||
//- with additional 'FOAM Warning' header text.
|
||||
extern messageStream Warning;
|
||||
|
||||
//- Error stream (uses stdout - output on all processes),
|
||||
//- with additional 'FOAM Serious Error' header text.
|
||||
extern messageStream SeriousError;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
@ -290,6 +318,10 @@ extern messageStream Info;
|
||||
// for FUNCTION_NAME in file __FILE__ at line __LINE__
|
||||
#define PoutInFunction PoutIn(FUNCTION_NAME)
|
||||
|
||||
//- Write to Foam::Info if the Foam::infoDetailLevel is +ve non-zero (default)
|
||||
#define DetailInfo \
|
||||
if (::Foam::infoDetailLevel > 0) Info
|
||||
|
||||
//- Report write to Foam::Info if the local log switch is true
|
||||
#define Log \
|
||||
if (log) Info
|
||||
|
@ -50,7 +50,6 @@ License
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::argList::argsMandatory_ = true;
|
||||
bool Foam::argList::bannerEnabled_ = true;
|
||||
bool Foam::argList::checkProcessorDirectories_ = true;
|
||||
Foam::SLList<Foam::string> Foam::argList::validArgs;
|
||||
Foam::HashTable<Foam::string> Foam::argList::validOptions;
|
||||
@ -295,13 +294,13 @@ void Foam::argList::nonMandatoryArgs()
|
||||
|
||||
void Foam::argList::noBanner()
|
||||
{
|
||||
bannerEnabled_ = false;
|
||||
::Foam::infoDetailLevel = 0;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::argList::bannerEnabled()
|
||||
{
|
||||
return bannerEnabled_;
|
||||
return (::Foam::infoDetailLevel > 0);
|
||||
}
|
||||
|
||||
|
||||
@ -914,7 +913,7 @@ void Foam::argList::parse
|
||||
const string timeString = clock::clockTime();
|
||||
|
||||
// Print the banner once only for parallel runs
|
||||
if (Pstream::master() && bannerEnabled_)
|
||||
if (Pstream::master() && bannerEnabled())
|
||||
{
|
||||
IOobject::writeBanner(Info, true)
|
||||
<< "Build : " << Foam::FOAMbuild << nl
|
||||
@ -972,7 +971,7 @@ void Foam::argList::parse
|
||||
fileOperation::New
|
||||
(
|
||||
handlerType,
|
||||
bannerEnabled_
|
||||
bannerEnabled()
|
||||
)
|
||||
);
|
||||
Foam::fileHandler(handler);
|
||||
@ -1320,7 +1319,7 @@ void Foam::argList::parse
|
||||
}
|
||||
}
|
||||
|
||||
if (Pstream::master() && bannerEnabled_)
|
||||
if (Pstream::master() && bannerEnabled())
|
||||
{
|
||||
Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl
|
||||
<< "nProcs : " << nProcs << endl;
|
||||
@ -1371,12 +1370,12 @@ void Foam::argList::parse
|
||||
|
||||
// Switch on signal trapping. We have to wait until after Pstream::init
|
||||
// since this sets up its own ones.
|
||||
sigFpe::set(bannerEnabled_);
|
||||
sigInt::set(bannerEnabled_);
|
||||
sigQuit::set(bannerEnabled_);
|
||||
sigSegv::set(bannerEnabled_);
|
||||
sigFpe::set(bannerEnabled());
|
||||
sigInt::set(bannerEnabled());
|
||||
sigQuit::set(bannerEnabled());
|
||||
sigSegv::set(bannerEnabled());
|
||||
|
||||
if (Pstream::master() && bannerEnabled_)
|
||||
if (Pstream::master() && bannerEnabled())
|
||||
{
|
||||
Info<< "fileModificationChecking : "
|
||||
<< "Monitoring run-time modified files using "
|
||||
|
@ -121,9 +121,6 @@ class argList
|
||||
//- Track enabled/disabled mandatory arguments
|
||||
static bool argsMandatory_;
|
||||
|
||||
//- Track enabled/disabled banner state
|
||||
static bool bannerEnabled_;
|
||||
|
||||
//- Track enabled/disabled checking of processor directories state
|
||||
static bool checkProcessorDirectories_;
|
||||
|
||||
@ -494,10 +491,12 @@ public:
|
||||
//- Flag command arguments as being non-mandatory
|
||||
static void nonMandatoryArgs();
|
||||
|
||||
//- Disable emitting the banner information
|
||||
//- Disable emitting the banner information.
|
||||
// Adjusts the Foam::infoDetailLevel flag.
|
||||
static void noBanner();
|
||||
|
||||
//- Banner status (enabled/disabled)
|
||||
//- Banner status (enabled/disabled).
|
||||
// Queries the Foam::infoDetailLevel flag.
|
||||
static bool bannerEnabled();
|
||||
|
||||
//- Remove the 'noFunctionObjects' option,
|
||||
|
@ -244,10 +244,7 @@ Foam::profiling::profiling
|
||||
Information *info = this->create(Zero);
|
||||
this->beginTimer(info);
|
||||
|
||||
if (argList::bannerEnabled())
|
||||
{
|
||||
Info<< "profiling initialized" << nl;
|
||||
}
|
||||
DetailInfo << "profiling initialized" << nl;
|
||||
}
|
||||
|
||||
|
||||
@ -283,10 +280,7 @@ Foam::profiling::profiling
|
||||
Information *info = this->create(Zero);
|
||||
this->beginTimer(info);
|
||||
|
||||
if (argList::bannerEnabled())
|
||||
{
|
||||
Info<< "profiling initialized" << nl;
|
||||
}
|
||||
DetailInfo << "profiling initialized" << nl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -83,7 +83,7 @@ string domainName();
|
||||
//- Return the user's login name
|
||||
string userName();
|
||||
|
||||
//- Is user administrator
|
||||
//- Is the current user the administrator (root)
|
||||
bool isAdministrator();
|
||||
|
||||
//- Return home directory path name for the current user
|
||||
@ -208,34 +208,39 @@ bool ping(const std::string& host, const label timeOut=10);
|
||||
|
||||
//- Execute the specified command via the shell.
|
||||
// Uses vfork/execl internally.
|
||||
// When Foam::infoDetailLevel is zero, redirects stdout to stderr.
|
||||
//
|
||||
// Where possible, use the list version instead.
|
||||
//
|
||||
// \param background return immediately to parent process instead of waiting
|
||||
// \param bg return immediately to parent process instead of waiting
|
||||
// for the child. Can be used (with moderation) to create background
|
||||
// processes.
|
||||
//
|
||||
// \note treats an empty command as a successful no-op.
|
||||
int system(const std::string& command, const bool background=false);
|
||||
// When Foam::infoDetailLevel is zero, redirects stdout to stderr.
|
||||
int system(const std::string& command, const bool bg = false);
|
||||
|
||||
//- Execute the specified command with arguments.
|
||||
// Uses vfork/execvp internally
|
||||
// When Foam::infoDetailLevel is zero, redirects stdout to stderr.
|
||||
//
|
||||
// \param background return immediately to parent process instead of waiting
|
||||
// \param bg return immediately to parent process instead of waiting
|
||||
// for the child. Can be used (with moderation) to create background
|
||||
// processes.
|
||||
//
|
||||
// \note treats an empty command as a successful no-op.
|
||||
int system(const UList<string>& command, const bool background=false);
|
||||
int system(const UList<string>& command, const bool bg = false);
|
||||
|
||||
//- Execute the specified command with arguments.
|
||||
// Uses vfork/execvp internally
|
||||
// When Foam::infoDetailLevel is zero, redirects stdout to stderr.
|
||||
//
|
||||
// \param background return immediately to parent process instead of waiting
|
||||
// \param bg return immediately to parent process instead of waiting
|
||||
// for the child. Can be used (with moderation) to create background
|
||||
// processes.
|
||||
//
|
||||
// \note treats an empty command as a successful no-op.
|
||||
int system(const CStringList& command, const bool background=false);
|
||||
int system(const CStringList& command, const bool bg = false);
|
||||
|
||||
//- Open a shared library and return handle to library.
|
||||
// Print error message if library cannot be loaded (suppress with check=true)
|
||||
|
Loading…
Reference in New Issue
Block a user