52 G_EXCEPTION( CannotChangeDirectory ,
tx(
"cannot change directory") ) ;
53 G_EXCEPTION( InvalidId ,
tx(
"invalid process-id string") ) ;
54 G_EXCEPTION( UidError ,
tx(
"cannot set uid") ) ;
55 G_EXCEPTION( GidError ,
tx(
"cannot set gid") ) ;
56 G_EXCEPTION( GetCwdError ,
tx(
"cannot get current working directory") ) ;
61 static void closeFiles(
bool keep_stderr =
false ) ;
72 static void cd(
const Path & dir ) ;
75 static bool cd(
const Path & dir , std::nothrow_t ) ;
83 static void errno_(
int e_new ) noexcept ;
94 static std::pair<Identity,Identity>
beOrdinaryAtStartup(
const std::string & nobody ,
bool change_group ) ;
145 static std::string
cwd(
bool no_throw =
false ) ;
149 static std::string
exe() ;
158 explicit Id(
const char * ,
const char * end ) noexcept ;
159 explicit Id(
int ) noexcept ;
160 explicit Id( std::istream & ) ;
161 static Id invalid() noexcept ;
162 std::string str()
const ;
163 bool operator==(
const Id & )
const noexcept ;
164 bool operator!=(
const Id & )
const noexcept ;
165 template <
typename T> T value(
166 typename std::enable_if
167 <std::numeric_limits<T>::max() >= std::numeric_limits<pid_t>::max()>
168 ::type * = 0 )
const noexcept
170 static_assert(
sizeof(T) >=
sizeof(pid_t) ,
"" ) ;
171 return static_cast<T
>( m_pid ) ;
173 template <
typename T> T seed()
const noexcept
175 return static_cast<T
>( m_pid ) ;
198 explicit Umask( Mode ) ;
200 static void set( Mode ) ;
201 static void tightenOther() ;
202 static void loosenGroup() ;
209 std::unique_ptr<UmaskImp> m_imp ;
216inline G::Process::Id::Id(
int n ) noexcept :
217 m_pid(
static_cast<pid_t
>(n))
221inline G::Process::Id::Id( std::istream & stream )
226inline G::Process::Id::Id(
const char * p ,
const char * end )
noexcept
228 bool overflow = false ;
229 m_pid = G::Str::toUnsigned<pid_t>( p , end , overflow ) ;
231 m_pid =
static_cast<pid_t
>(-1) ;
242 std::ostream & operator<<( std::ostream & stream ,
const G::Process::Id &
id )
244 return stream <<
id.str() ;
A combination of user-id and group-id, with a very low-level interface to the get/set/e/uid/gid funct...
A class for creating new processes.
A Path object represents a file system path.
Used to temporarily modify the process umask.
A static interface for doing things with processes.
static void beSpecialForExit(SignalSafe, Identity special_id) noexcept
A signal-safe version of beSpecial() that should only be used just before process exit.
static void closeOtherFiles(int fd_keep=-1)
Closes all open file descriptors except the three standard ones and possibly one other.
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,...
static void beSpecial(Identity special_id, bool change_group=true)
Re-acquires special privileges (either root or suid).
static std::string strerror(int errno_)
Translates an 'errno' value into a meaningful diagnostic string.
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.
static void setEffectiveGroup(Identity)
Sets the effective group-id. Throws on error.
static std::string cwd(bool no_throw=false)
Returns the current working directory.
static void closeStderr()
Closes stderr and reopens it to the null device.
static void beOrdinary(Identity ordinary_id, bool change_group)
Releases special privileges.
static std::string exe()
Returns the absolute path of the current executable, independent of the argv array passed to main().
static int errno_(const SignalSafe &=G::SignalSafe()) noexcept
Returns the process's current 'errno' value.
static void setEffectiveUser(Identity)
Sets the effective user-id. Throws on error.
static void closeFiles(bool keep_stderr=false)
Closes all open file descriptors and reopen stdin, stdout and possibly stderr to the null device.
static void cd(const Path &dir)
Changes directory.
An empty structure that is used to indicate a signal-safe, reentrant implementation.
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().