systemCall.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "systemCall.H"
27 #include "Time.H"
28 #include "dynamicCode.H"
29 #include "OSspecific.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(systemCall, 0);
39 
41  (
42  functionObject,
43  systemCall,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const word& name,
55  const Time&,
56  const dictionary& dict
57 )
58 :
59  functionObject(name),
60  executeCalls_(),
61  endCalls_(),
62  writeCalls_()
63 {
64  read(dict);
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 {
78  dict.readIfPresent("executeCalls", executeCalls_);
79  dict.readIfPresent("endCalls", endCalls_);
80  dict.readIfPresent("writeCalls", writeCalls_);
81 
82  if (executeCalls_.empty() && endCalls_.empty() && writeCalls_.empty())
83  {
85  << "no executeCalls, endCalls or writeCalls defined."
86  << endl;
87  }
89  {
91  << "Executing user-supplied system calls is not enabled by "
92  << "default because of " << nl
93  << "security issues. If you trust the case you can enable this "
94  << "facility by " << nl
95  << "adding to the InfoSwitches setting in the system controlDict:"
96  << nl << nl
97  << " allowSystemOperations 1" << nl << nl
98  << "The system controlDict is either" << nl << nl
99  << " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << nl << nl
100  << "or" << nl << nl
101  << " $WM_PROJECT_DIR/etc/controlDict" << nl << nl
102  << exit(FatalError);
103  }
104 
105  return true;
106 }
107 
108 
110 {
111  forAll(executeCalls_, callI)
112  {
113  Foam::system(executeCalls_[callI]);
114  }
115 
116  return true;
117 }
118 
119 
121 {
122  forAll(endCalls_, callI)
123  {
124  Foam::system(endCalls_[callI]);
125  }
126 
127  return true;
128 }
129 
130 
132 {
133  forAll(writeCalls_, callI)
134  {
135  Foam::system(writeCalls_[callI]);
136  }
137 
138  return true;
139 }
140 
141 
142 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual ~systemCall()
Destructor.
Definition: systemCall.C:70
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool write()
Write, execute the "writeCalls".
Definition: systemCall.C:131
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Abstract base-class for Time/database functionObjects.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual bool execute()
Execute the "executeCalls" at each time-step.
Definition: systemCall.C:109
A class for handling words, derived from string.
Definition: word.H:59
static int allowSystemOperations
Flag if system operations are allowed.
Definition: dynamicCode.H:156
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(Qdot, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
virtual bool read(const dictionary &)
Read the system calls.
Definition: systemCall.C:76
systemCall(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: systemCall.C:53
virtual bool end()
Execute the "endCalls" at the final time-loop.
Definition: systemCall.C:120
Namespace for OpenFOAM.
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1230