E-MailRelay
|
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... | |
A static interface for doing things with processes.
Definition at line 45 of file gprocess.h.
|
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.
|
static |
Revokes special privileges (root or suid), possibly including extra group membership.
Definition at line 145 of file gprocess_unix.cpp.
|
staticnoexcept |
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.
|
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.
|
staticnoexcept |
A signal-safe version of beSpecial() that should only be used just before process exit.
Definition at line 140 of file gprocess_unix.cpp.
|
static |
Changes directory.
Definition at line 69 of file gprocess_unix.cpp.
|
static |
Changes directory. Returns false on error.
Definition at line 75 of file gprocess_unix.cpp.
|
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.
|
static |
Closes all open file descriptors except the three standard ones and possibly one other.
Definition at line 98 of file gprocess_unix.cpp.
|
static |
Closes stderr and reopens it to the null device.
Definition at line 80 of file gprocess_unix.cpp.
|
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.
|
staticnoexcept |
Sets the process's 'errno' value.
Returns the old value. Used in signal handlers.
Definition at line 120 of file gprocess_unix.cpp.
|
staticnoexcept |
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.
|
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.
|
static |
Sets the effective group. Throws on error.
Definition at line 175 of file gprocess_unix.cpp.
|
static |
Sets the effective user. Throws on error.
Definition at line 170 of file gprocess_unix.cpp.
|
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.