/usr/include/bobcat/process is in libbobcat-dev 4.01.03-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | #ifndef INCLUDED_BOBCAT_PROCESS_
#define INCLUDED_BOBCAT_PROCESS_
#include <string>
#include <ostream>
#include <istream>
#include <bobcat/fork>
#include <bobcat/string>
#include <bobcat/pipe>
#include <bobcat/selector>
#include <bobcat/ifdstreambuf>
#include <bobcat/ofdstreambuf>
#include <bobcat/iostream>
#include <bobcat/processenums>
#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
#ifndef BOBCAT_DIY_CLOEXEC_
#define BOBCAT_DIY_CLOEXEC_
#endif
#endif
namespace FBB
{
struct ProcessData;
struct Process: private Fork, public IOStream, public ProcessEnums
{
friend Process &operator|(Process &lhs, Process &rhs);
enum ProcessType
{
NO_PATH,
USE_PATH,
USE_SHELL
};
private:
bool d_active;
IOMode d_mode;
size_t d_timeLimit; // seconds allowed to child-process
ProcessType d_processType;
IOMode d_setMode; // these values are set by the
size_t d_setTimeLimit; // set members and used as
ProcessType d_setProcessType; // defaults unless overridden by
// actual values
// Constructors set these values
// too.
std::string d_command;
Pipe d_oChildInPipe; // cin read by the CHILD
Pipe d_iChildOutPipe; // cout written by the CHILD
Pipe d_iChildErrPipe; // cerr written by the CHILD
OFdStreambuf d_oChildInbuf; // Child extracts,
IFdStreambuf d_iChildOutbuf; // Child inserts,
IFdStreambuf d_iChildErrbuf; // Child inserts
std::ostream d_oChildIn; // Parent inserts to child's cin
std::istream d_iChildOut; // Parent extracts child's cout
std::istream d_iChildErr; // Parent extracts child's cerr
Selector d_selector; // senses activities on Child's
// out/err streams
struct RetPid
{
int ret;
pid_t pid;
RetPid(); // 1.f
};
RetPid d_child;
ProcessData *d_data;
char d_notUsed[sizeof(RetPid) - sizeof(ProcessData *)];
#ifdef BOBCAT_DIY_CLOEXEC_
int d_closedByChild = 0; // DIY CLOSE_ON_EXEC
#endif
public:
explicit Process(std::string const &command = ""); // 1
explicit Process(size_t iomode, std::string const &command = ""); // 2
Process(size_t mode, ProcessType type, // 3
std::string const &command = "");
Process(size_t mode, ProcessType type, size_t timeLimit, // 4
std::string const &command = "");
Process(IOMode mode, ProcessType type, size_t timeLimit, // 5
size_t bufSize, std::string const &command = "");
Process(Process const &other) = delete;
~Process() override; // stop()s any ongoing process
Process &operator=(Process const &other) = delete;
size_t bufSize() const; // returns current buffer size
IOMode ioMode() const; // returns default IOMode .f
ProcessType processType() const; // returns default ProcessType .f
size_t timeLimit() const; // returns default time limit .f
void setBufSize(size_t bufSize);
void setIOMode(IOMode mode); // change IOMode .f
void setProcessType(ProcessType type); // .f
void setTimeLimit(size_t timeLimit); // .f
// for the next cmd to start
// 0 means: no time monitor
void setCommand(std::string const &command); // sets cmd, .f
Process &operator+=(std::string const &text); // opaddis.f
// adds to the command
void start(); // 1.f
void start(IOMode mode); // 2.f
void start(IOMode mode, ProcessType type); // 3.f
void start(size_t mode, ProcessType type, size_t timeLimit); // 1
void start(IOMode mode, ProcessType type, // 2
size_t timeLimit, size_t bufSize);
void system(); // calls /bin/sh -c cmd; 1.f
// shell redirs OK
void system(IOMode mode); // 2.f
void system(IOMode mode, size_t timeLimit); // 3.f
void system(IOMode mode, size_t timeLimit, size_t bufSize); // 4.f
int operator=(std::string const &cmd); // sets and starts a command
std::string const &str() const; // current command .f
template <typename Type>
Process &operator<<(Type const &value); // opinsert.f
Process &operator<<(std::ostream &(*pf)(std::ostream &));
template <typename Type>
Process &operator>>(Type &value); // opextract.f
int stop(); // terminate a running childprocess
void close(); // closes input to the child
void eoi(); // closes input and waits for
// the child to end
using Fork::waitForChild;
bool active();
Process &operator()(IOMode mode); // opfun1.f
Process &operator()(IOMode mode, ProcessType type); // opfun2.f
// operatorfun1.cc
Process &operator()(size_t mode, ProcessType type, size_t timeLimit);
Process &operator()(IOMode mode, ProcessType type, // operatorfun2.cc
size_t timeLimit, size_t bufSize);
std::istream &childErrStream(); // READ cerr from the child
std::istream &cerr(); // same, but deprecated
std::istream &childOutStream(); // .f
// READ cout from the child
// (also: direct through
// extraction)
size_t available(); // returns ChildOutput bit_or
// (cf. manpage)
void showMode(char const *lab) const;
private:
void childProcess() override;
void childRedirections() override;
void parentProcess() override;
void parentRedirections() override;
void newPipe(Pipe &pipe);
pid_t discontinue(RetPid &proc);
ChildOutput whichStream();
void close(int fd);
void closeWriteFd(Pipe &pipe);
void closeReadFd(Pipe &pipe);
void rmBackticks();
void forking();
IOMode sanitizeIOMode(IOMode mode);
void newPipes();
void closeChildInputOnExec();
typedef std::string::const_iterator ConstIter;
struct ExecContext;
ExecContext analyzeCommand();
static void limiter(Process *process);
};
inline std::istream &Process::childOutStream()
{
return static_cast<std::istream &>(*this);
}
inline std::ostream &eoi(std::ostream &str)
{
return str;
}
inline void Process::eoi()
{
*this << FBB::eoi;
}
inline Process::IOMode Process::ioMode() const
{
return d_mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC);
}
inline Process &Process::operator+=(std::string const &command)
{
d_command += command;
return *this;
}
template <typename Type>
Process &Process::operator>>(Type &value)
{
if ((available() & CHILD_COUT) || active())
dynamic_cast<std::istream &>(*this) >> value;
return *this;
}
inline Process &Process::operator()(IOMode mode)
{
return operator()(mode, d_setProcessType, d_setTimeLimit);
}
inline Process &Process::operator()(IOMode mode, ProcessType type)
{
return operator()(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC),
type, d_setTimeLimit);
}
template <typename Type>
Process &Process::operator<<(Type const &value)
{
if (active())
dynamic_cast<std::ostream &>(*this) << value;
return *this;
}
inline Process::ProcessType Process::processType() const
{
return d_setProcessType;
}
inline void Process::setCommand(std::string const &command)
{
d_command = command;
}
inline void Process::setIOMode(IOMode mode)
{
d_setMode = sanitizeIOMode(mode);
}
inline void Process::setProcessType(ProcessType type)
{
d_setProcessType = d_processType = type;
}
inline void Process::setTimeLimit(size_t timeLimit)
{
d_setTimeLimit = d_timeLimit = timeLimit;
}
inline void Process::start()
{
start(d_setMode, d_setProcessType, d_setTimeLimit);
}
inline void Process::start(IOMode mode)
{
start(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC),
d_setProcessType, d_setTimeLimit);
}
inline void Process::start(IOMode mode, ProcessType type)
{
start(mode & ~(IN_PIPE | OUT_PIPE | CLOSE_ON_EXEC), type, d_setTimeLimit);
}
inline std::string const &Process::str() const
{
return d_command;
}
inline void Process::system()
{
start(d_mode, USE_SHELL, d_timeLimit, bufSize());
}
inline void Process::system(IOMode mode)
{
start(mode, USE_SHELL, d_timeLimit, bufSize());
}
inline void Process::system(IOMode mode, size_t timeLimit)
{
start(mode, USE_SHELL, timeLimit, bufSize());
}
inline void Process::system(IOMode mode, size_t timeLimit, size_t bufSize)
{
start(mode, USE_SHELL, timeLimit, bufSize);
}
inline size_t Process::timeLimit() const
{
return d_setTimeLimit;
}
} // FBB
#endif
|