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 |
Static Public Member Functions | |
static void | closeFiles (bool keep_stderr=false) |
Closes all open file descriptors and reopens 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 optionally one other. More... | |
static void | inheritStandardFiles () |
Makes sure that the standard file descriptors are inherited. 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 void | errno_ (int e_new) noexcept |
Sets the process's '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 std::string | errorMessage (DWORD error) |
Translates a GetLastError() value into a meaningful diagnostic string. More... | |
static std::pair< Identity, Identity > | beOrdinaryAtStartup (const std::string &nobody, bool change_group) |
Revokes special privileges (root or suid) at startup, possibly including extra group membership, making the named user the effective identity. 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-id and group-ids to those given, on a best-effort basis. More... | |
static void | setEffectiveUser (Identity) |
Sets the effective user-id. Throws on error. More... | |
static void | setEffectiveGroup (Identity) |
Sets the effective group-id. Throws on error. More... | |
static Path | cwd () |
Returns the current working directory. Throws on error. More... | |
static Path | cwd (std::nothrow_t) |
Returns the current working directory. More... | |
static Path | 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 49 of file gprocess.h.
|
static |
Releases special privileges.
If the real-id is root then the effective user-id is changed to whatever is passed in. Otherwise the effective user-id is changed to the real user-id (optionally including the group), and the identity parameter is ignored.
Logs an error message and throws on failure, resulting in a call to std::terminate() when called from a destructor (see G::Root).
(Note that the identity switch applies to all threads in the calling processes, so some run-time libraries engage in signal shenanigans to synchronise the change across threads, which can lead to surprising interruptions of sleep(), select() etc.)
See also class G::Root.
Definition at line 186 of file gprocess_unix.cpp.
|
static |
Revokes special privileges (root or suid) at startup, possibly including extra group membership, making the named user the effective identity.
Returns the new effective identity and the original effective identity as a pair.
Definition at line 167 of file gprocess_unix.cpp.
|
staticnoexcept |
Sets the real and effective user-id and group-ids to those given, on a best-effort basis.
Errors are ignored.
Definition at line 191 of file gprocess_unix.cpp.
|
static |
Re-acquires special privileges (either root or suid).
The parameter must have come from a previous call to beOrdinaryAtStartup() and use the same change_group value.
See also class G::Root.
Definition at line 157 of file gprocess_unix.cpp.
|
staticnoexcept |
A signal-safe version of beSpecial() that should only be used just before process exit.
Definition at line 162 of file gprocess_unix.cpp.
|
static |
Changes directory.
Definition at line 74 of file gprocess_unix.cpp.
|
static |
Changes directory. Returns false on error.
Definition at line 80 of file gprocess_unix.cpp.
|
static |
Closes all open file descriptors and reopens stdin, stdout and possibly stderr to the null device.
Definition at line 90 of file gprocess_unix.cpp.
|
static |
Closes all open file descriptors except the three standard ones and optionally one other.
Definition at line 104 of file gprocess_unix.cpp.
|
static |
Closes stderr and reopens it to the null device.
Definition at line 85 of file gprocess_unix.cpp.
|
static |
Returns the current working directory. Throws on error.
Definition at line 210 of file gprocess_unix.cpp.
|
static |
Returns the current working directory.
Returns the empty path on error.
Definition at line 215 of file gprocess_unix.cpp.
|
staticnoexcept |
Sets the process's 'errno' value.
Returns the old value. Typically used in signal handlers.
Definition at line 135 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 125 of file gprocess_unix.cpp.
|
staticnoexcept |
Sets the process's 'errno' value.
Definition at line 130 of file gprocess_unix.cpp.
|
static |
Translates a GetLastError() value into a meaningful diagnostic string.
The returned string is non-empty, even for a zero error number.
Definition at line 151 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 path if unknown.
Definition at line 265 of file gprocess_unix.cpp.
|
static |
Makes sure that the standard file descriptors are inherited.
Definition at line 118 of file gprocess_unix.cpp.
|
static |
Sets the effective group-id. Throws on error.
Definition at line 204 of file gprocess_unix.cpp.
|
static |
Sets the effective user-id. Throws on error.
Definition at line 197 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 142 of file gprocess_unix.cpp.