E-MailRelay

Classes | Static Public Member Functions | List of all members
G::Process Class Reference

A static interface for doing things with processes. More...

`#include <gprocess.h>`

## Classes
class | Id
| Process-id class. More...
class | Umask
| Used to temporarily modify the process umask. More...
class | UmaskImp
| A private implemetation class for G::Process::Umask that hides mode_t. More...

## Static Public Member Functions
static void | closeFiles (bool keep_stderr=false)
| Closes all open file descriptors and reopen stdin, stdout and possibly stderr to the null device. More...
static void | closeStderr ()
| Closes stderr and reopens it to the null device. More...
static void | closeOtherFiles (int fd_keep=-1)
| Closes all open file descriptors except the three standard ones and possibly one other. More...
static void | cd (const Path &dir)
| Changes directory. More...
static bool | cd (const Path &dir, std::nothrow_t)
| Changes directory. Returns false on error. More...
static int | errno_ (const SignalSafe &=G::SignalSafe()) noexcept
| Returns the process's current 'errno' value. More...
static int | errno_ (const SignalSafe &, int e_new) noexcept
| Sets the process's 'errno' value. More...
static std::string | strerror (int errno_)
| Translates an 'errno' value into a meaningful diagnostic string. More...
static Identity | beOrdinaryAtStartup (Identity ordinary_id, bool change_group)
| Revokes special privileges (root or suid), possibly including extra group membership. More...
static void | beOrdinary (Identity ordinary_id, bool change_group)
| Releases special privileges. More...
static void | beSpecial (Identity special_id, bool change_group=true)
| Re-acquires special privileges (either root or suid). More...
static void | beSpecialForExit (SignalSafe, Identity special_id) noexcept
| A signal-safe version of beSpecial() that should only be used just before process exit. More...
static void | beOrdinaryForExec (Identity run_as_id) noexcept
| Sets the real and effective user and group ids to those given, on a best-effort basis. More...
static void | setEffectiveUser (Identity)
| Sets the effective user. Throws on error. More...
static void | setEffectiveGroup (Identity)
| Sets the effective group. Throws on error. More...
static std::string | cwd (bool no_throw=false)
| Returns the current working directory. More...
static std::string | exe ()
| Returns the absolute path of the current executable, independent of the argv array passed to main(). More...

## Detailed Description

A static interface for doing things with processes.

See also
  G::Identity

Definition at line 45 of file gprocess.h.

## Member Function Documentation

## ◆ beOrdinary()

void G::Process::beOrdinary | ( | Identity | ordinary_id,
|  | bool | change_group
| ) |  |
| static

Releases special privileges.

If the real-id is root then the effective id is changed to whatever is passed in. Otherwise the effective id is changed to the real id (optionally including the group), and the identity parameter is ignored.

Returns the old effective-id, which can be passed to beSpecial().

Logs an error message and throws on failure, resulting in a call to std::terminate() when called from a destructor (see G::Root).

This affects all threads in the calling processes, with signal hacks used in some implementations to do the synchronisation. This can lead to surprising interruptions of sleep(), select() etc.

See also class G::Root.

Definition at line 160 of file gprocess_unix.cpp.

## ◆ beOrdinaryAtStartup()

G::Identity G::Process::beOrdinaryAtStartup | ( | Identity | ordinary_id,
|  | bool | change_group
| ) |  |
| static

Revokes special privileges (root or suid), possibly including extra group membership.

Definition at line 145 of file gprocess_unix.cpp.

## ◆ beOrdinaryForExec()

void G::Process::beOrdinaryForExec | ( | Identity | run_as_id | ) |
| static noexcept

Sets the real and effective user and group ids to those given, on a best-effort basis.

Errors are ignored.

Definition at line 165 of file gprocess_unix.cpp.

## ◆ beSpecial()

void G::Process::beSpecial | ( | Identity | special_id,
|  | bool | change_group = `true`
| ) |  |
| static

Re-acquires special privileges (either root or suid).

The parameter must have come from a previous call to beOrdinary() and use the same change_group value.

See also class G::Root.

Definition at line 135 of file gprocess_unix.cpp.

## ◆ beSpecialForExit()

void G::Process::beSpecialForExit | ( | SignalSafe | ,
|  | Identity | special_id
| ) |  |
| static noexcept

A signal-safe version of beSpecial() that should only be used just before process exit.

Definition at line 140 of file gprocess_unix.cpp.

## ◆ cd() [1/2]

void G::Process::cd | ( | const Path & | dir | ) |
| static

Changes directory.

Definition at line 69 of file gprocess_unix.cpp.

## ◆ cd() [2/2]

bool G::Process::cd | ( | const Path & | dir,
|  | std::nothrow_t |
| ) |  |
| static

Changes directory. Returns false on error.

Definition at line 75 of file gprocess_unix.cpp.

## ◆ closeFiles()

void G::Process::closeFiles | ( | bool | keep_stderr = `false` | ) |
| static

Closes all open file descriptors and reopen stdin, stdout and possibly stderr to the null device.

Definition at line 85 of file gprocess_unix.cpp.

## ◆ closeOtherFiles()

void G::Process::closeOtherFiles | ( | int | fd_keep = `-1` | ) |
| static

Closes all open file descriptors except the three standard ones and possibly one other.

Definition at line 98 of file gprocess_unix.cpp.

## ◆ closeStderr()

void G::Process::closeStderr | ( |  | ) |
| static

Closes stderr and reopens it to the null device.

Definition at line 80 of file gprocess_unix.cpp.

## ◆ cwd()

std::string G::Process::cwd | ( | bool | no_throw = `false` | ) |
| static

Returns the current working directory.

Throws on error by default or returns the empty string.

Definition at line 180 of file gprocess_unix.cpp.

## ◆ errno_() [1/2]

int G::Process::errno_ | ( | const SignalSafe & | ,
|  | int | e_new
| ) |  |
| static noexcept

Sets the process's 'errno' value.

Returns the old value. Used in signal handlers.

Definition at line 120 of file gprocess_unix.cpp.

## ◆ errno_() [2/2]

int G::Process::errno_ | ( | const SignalSafe & | = `G::SignalSafe()` | ) |
| static noexcept

Returns the process's current 'errno' value.

(Beware of destructors of c++ temporaries disrupting the global errno value.)

Definition at line 115 of file gprocess_unix.cpp.

## ◆ exe()

std::string G::Process::exe | ( |  | ) |
| static

Returns the absolute path of the current executable, independent of the argv array passed to main().

Returns the empty string if unknown.

Definition at line 225 of file gprocess_unix.cpp.

## ◆ setEffectiveGroup()

void G::Process::setEffectiveGroup | ( | Identity | id | ) |
| static

Sets the effective group. Throws on error.

Definition at line 175 of file gprocess_unix.cpp.

## ◆ setEffectiveUser()

void G::Process::setEffectiveUser | ( | Identity | id | ) |
| static

Sets the effective user. Throws on error.

Definition at line 170 of file gprocess_unix.cpp.

## ◆ strerror()

std::string G::Process::strerror | ( | int | errno_ | ) |
| static

Translates an 'errno' value into a meaningful diagnostic string.

The returned string is non-empty, even for a zero errno.

Definition at line 127 of file gprocess_unix.cpp.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/glib/gprocess.h
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/glib/gprocess_unix.cpp