VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
G::NewProcess Class Reference

A class for creating new processes. More...

#include <gnewprocess.h>

Public Member Functions

 NewProcess (const Path &exe, const StringArray &args, int capture_stdxxx=1, bool clean=true, bool strict_path=true, Identity run_as_id=Identity::invalid(), bool strict_id=true, int exec_error_exit=127, const std::string &exec_error_format=std::string(), std::string(*exec_error_format_fn)(std::string, int)=0)
 Constructor. More...
 
 ~NewProcess ()
 Destructor. More...
 
NewProcessWaitFuturewait ()
 Returns a reference to the WaitFuture sub-object so that the caller can wait for the child process to exit. More...
 
void kill ()
 Tries to kill the spawned process.
 

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...
 

Public Attributes

while the user id is zero
 
 error
 

Detailed Description

A class for creating new processes.

See Also
G::Daemon, G::NewProcess

Definition at line 45 of file gnewprocess.h.

Constructor & Destructor Documentation

G::NewProcess::NewProcess ( const Path exe,
const StringArray args,
int  capture_stdxxx = 1,
bool  clean = true,
bool  strict_path = true,
Identity  run_as_id = Identity::invalid(),
bool  strict_id = true,
int  exec_error_exit = 127,
const std::string &  exec_error_format = std::string(),
std::string(*)(std::string, int)  exec_error_format_fn = 0 
)

Constructor.

Spawns the given program to run independently in a child process.

The parent process can capture the child process's stdout or stderr (ie. stdxxx) by redirecting it to an internal pipe going from child to parent.

The child process is optionally given a clean, minimalist environment.

If 'strict_path' then the program must be given as an absolute path. Otherwise it can be relative and the PATH environment is used to find it. (The PATH search applies after the environment has been cleaned or not.)

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 Process::beOrdinaryForExec().

By default the child process runs with stdin and stderr attached to the null device and stdout attached to the internal pipe. The internal pipe is also used for error messages in case the exec() fails.

If the exec() fails then the 'exec_error_exit' argument is used as the child process exit code, and if either of the other 'exec_whatever' arguments is supplied then an exec error message is written into the child process's end of the internal pipe.

The exec error message is assembled by the given callback function, with the 'exec_error_format' argument passed as its second parameter. The first 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 91 of file gnewprocess_unix.cpp.

G::NewProcess::~NewProcess ( )

Destructor.

Kills the spawned process if the WaitFuture has not been resolved.

Definition at line 101 of file gnewprocess_unix.cpp.

Member Function Documentation

std::pair< bool, pid_t > G::NewProcess::fork ( )
static

A utility function that forks the calling process and returns twice; once in the parent and once in the child.

Returns an "is-in-child/child-pid" pair.

See Also
G::Daemon

Definition at line 111 of file gnewprocess_unix.cpp.

G::NewProcessWaitFuture & G::NewProcess::wait ( )

Returns a reference to the WaitFuture sub-object so that the caller can wait for the child process to exit.

Definition at line 106 of file gnewprocess_unix.cpp.


The documentation for this class was generated from the following files: