E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
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_environment=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...
int | id () const
| Returns the process id.
NewProcessWaitFuture & | wait ()
| 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.

Eg:

{
NewProcess task( "foo" , args ) ;
int rc = task.wait().run().get() ;
std::string s = task.wait().output() ;
...
}

See also
  G::Daemon, G::NewProcessWaitFuture

Definition at line 56 of file gnewprocess.h.

## Constructor & Destructor Documentation

G::NewProcess::NewProcess | ( | const Path & | exe,
|  | const StringArray & | args,
|  | int | capture_stdxxx = `1`,
|  | bool | clean_environment = `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 is done after the environment has been either 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 95 of file gnewprocess_unix.cpp.

G::NewProcess::~NewProcess | ( |  | ) |

Destructor.

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

Definition at line 105 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 115 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 110 of file gnewprocess_unix.cpp.

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

- /tmp/slackrepo/SBo/slackrepo.S3SYfd/build_emailrelay/emailrelay-2.0.1/src/glib/gnewprocess.h
- /tmp/slackrepo/SBo/slackrepo.S3SYfd/build_emailrelay/emailrelay-2.0.1/src/glib/gnewprocess_unix.cpp