E-MailRelay
|
A class for creating new processes. More...
#include <gnewprocess.h>
Classes | |
struct | Config |
Configuration structure for G::NewProcess. More... | |
struct | Fd |
Wraps up a file descriptor for passing to G::NewProcess. More... | |
Public Member Functions | |
NewProcess (const Path &exe, const G::StringArray &args, const Config &) | |
Constructor. More... | |
~NewProcess () | |
Destructor. More... | |
int | id () const noexcept |
Returns the process id. More... | |
NewProcessWaitable & | waitable () noexcept |
Returns a reference to the Waitable sub-object so that the caller can wait for the child process to exit. More... | |
void | kill (bool yield=false) noexcept |
Tries to kill the spawned process and optionally yield to a thread that might be waiting on it. More... | |
NewProcess (const NewProcess &)=delete | |
NewProcess (NewProcess &&)=delete | |
NewProcess & | operator= (const NewProcess &)=delete |
NewProcess & | operator= (NewProcess &&)=delete |
Static Public Member Functions | |
static std::pair< bool, pid_t > | fork () |
A utility function that forks the calling process and returns twice; once in the parent and once in the child. More... | |
A class for creating new processes.
Eg:
Definition at line 61 of file gnewprocess.h.
G::NewProcess::NewProcess | ( | const Path & | exe, |
const G::StringArray & | args, | ||
const Config & | config | ||
) |
Constructor.
Spawns the given program to run independently in a child process.
The child process's stdin, stdout and stderr are connected as directed, but exactly one of stdout and stderr must be the internal pipe since it is used to detect process termination. To inherit the existing file descriptors use Fd(STDIN_FILENO) etc. Using Fd::fd(-1) is equivalent to Fd::devnull().
The child process is given the new environment, unless the environment given is empty() in which case the environment is inherited from the calling process (see G::Environment::inherit()).
If 'strict_exe' then the program must be given as an absolute path. Otherwise it can be a relative path and the calling process's PATH variable or the 'exec_search_path' is used to find it.
If a valid identity is supplied then the child process runs as that identity. If 'strict_id' is also true then the id is not allowed to be root. See G::Process::beOrdinaryForExec().
If the exec() fails then the 'exec_error_exit' argument is used as the child process exit code.
The internal pipe can be used for error messages in the situation where the exec() in the forked child process fails. This requires that one of the 'exec_error_format' parameters is given; by default nothing is sent over the pipe when the exec() fails.
The exec error message is assembled by the given callback function, with the 'exec_error_format' argument passed as its first parameter. The second parameter is the exec() errno. The default callback function does text substitution for "__errno__" and "__strerror__" substrings that appear within the error format string.
Definition at line 109 of file gnewprocess_unix.cpp.
|
default |
Destructor.
Kills the spawned process if the Waitable has not been resolved.
|
static |
A utility function that forks the calling process and returns twice; once in the parent and once in the child.
Not implemented on windows. Returns an "is-in-child/child-pid" pair.
Definition at line 122 of file gnewprocess_unix.cpp.
|
noexcept |
Returns the process id.
Definition at line 127 of file gnewprocess_unix.cpp.
|
noexcept |
Tries to kill the spawned process and optionally yield to a thread that might be waiting on it.
Definition at line 132 of file gnewprocess_unix.cpp.
|
noexcept |
Returns a reference to the Waitable sub-object so that the caller can wait for the child process to exit.
Definition at line 117 of file gnewprocess_unix.cpp.