48 G_EXCEPTION( CannotChangeDirectory ,
"cannot change directory" ) ;
49 G_EXCEPTION( InvalidId ,
"invalid process-id string" ) ;
50 G_EXCEPTION( UidError ,
"cannot set uid" ) ;
51 G_EXCEPTION( GidError ,
"cannot set gid" ) ;
56 static void closeFiles(
bool keep_stderr =
false ) ;
67 static void cd(
const Path & dir ) ;
70 static bool cd(
const Path & dir , std::nothrow_t ) ;
130 static std::string
cwd(
bool no_throw =
false ) ;
134 static std::string
exe() ;
143 explicit Id(
const char * ,
const char * end ) noexcept ;
144 explicit Id(
int ) noexcept ;
145 explicit Id( std::istream & ) ;
146 static Id invalid() noexcept ;
147 std::string str()
const ;
148 bool operator==(
const Id & )
const noexcept ;
149 bool operator!=(
const Id & )
const noexcept ;
160 enum class Mode { Readable , Tighter , Tightest , GroupOpen , Open } ;
161 explicit Umask( Mode ) ;
163 static void set( Mode ) ;
164 static void tighten() ;
167 void operator=(
const Umask & ) = delete ;
168 void operator=(
Umask && ) = delete ;
169 private: std::unique_ptr<UmaskImp> m_imp ;
176inline G::Process::Id::Id(
int n ) noexcept :
177 m_pid(
static_cast<pid_t
>(n))
181inline G::Process::Id::Id( std::istream & stream )
186inline G::Process::Id::Id(
const char * p ,
const char * end )
noexcept
188 bool overflow = false ;
189 m_pid = G::Str::toUnsigned<pid_t>( p , end , overflow ) ;
191 m_pid =
static_cast<pid_t
>(-1) ;
202 std::ostream & operator<<( std::ostream & stream ,
const G::Process::Id &
id )
204 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.
A private implemetation class for G::Process::Umask that hides mode_t.
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 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 and group ids to those given, on a best-effort basis.
static void setEffectiveGroup(Identity)
Sets the effective group. 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. 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.
static Identity beOrdinaryAtStartup(Identity ordinary_id, bool change_group)
Revokes special privileges (root or suid), possibly including extra group membership.
An empty structure that is used to indicate a signal-safe, reentrant implementation.