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 ) ;
76 static void cd(
const Path & dir ) ;
79 static bool cd(
const Path & dir , std::nothrow_t ) ;
87 static void errno_(
int e_new ) noexcept ;
102 static std::pair<Identity,Identity>
beOrdinaryAtStartup(
const std::string & nobody ,
bool change_group ) ;
157 static Path cwd( std::nothrow_t ) ;
170 explicit Id(
const char * ,
const char * end ) noexcept ;
171 explicit Id(
int ) noexcept ;
172 explicit Id( std::istream & ) ;
173 static Id invalid() noexcept ;
174 std::string str()
const ;
175 bool operator==(
const Id & )
const noexcept ;
176 bool operator!=(
const Id & )
const noexcept ;
177 template <
typename T> T value(
178 typename std::enable_if
179 <std::numeric_limits<T>::max() >= std::numeric_limits<pid_t>::max()>
180 ::type * = 0 )
const noexcept
182 static_assert(
sizeof(T) >=
sizeof(pid_t) ,
"" ) ;
183 return static_cast<T
>( m_pid ) ;
185 template <
typename T> T seed()
const noexcept
187 return static_cast<T
>( m_pid ) ;
210 explicit Umask( Mode ) ;
212 static void set( Mode ) ;
213 static void tightenOther() ;
214 static void loosenGroup() ;
221 std::unique_ptr<UmaskImp> m_imp ;
228 static Path cwdImp(
bool ) ;
231inline G::Process::Id::Id(
int n ) noexcept :
232 m_pid(
static_cast<pid_t
>(n))
236inline G::Process::Id::Id( std::istream & stream )
241inline G::Process::Id::Id(
const char * p ,
const char * end )
noexcept
243 bool overflow = false ;
244 m_pid = G::Str::toUnsigned<pid_t>( p , end , overflow ) ;
246 m_pid =
static_cast<pid_t
>(-1) ;
257 std::ostream & operator<<( std::ostream & stream ,
const G::Process::Id &
id )
259 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 optionally one other.
static Path cwd()
Returns the current working directory. Throws on error.
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 Path exe()
Returns the absolute path of the current executable, independent of the argv array passed to main().
static void setEffectiveGroup(Identity)
Sets the effective group-id. Throws on error.
static void closeStderr()
Closes stderr and reopens it to the null device.
static void inheritStandardFiles()
Makes sure that the standard file descriptors are inherited.
static void beOrdinary(Identity ordinary_id, bool change_group)
Releases special privileges.
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 reopens stdin, stdout and possibly stderr to the null device.
static void cd(const Path &dir)
Changes directory.
static std::string errorMessage(DWORD error)
Translates a GetLastError() value into a meaningful diagnostic string.
An empty structure that is used to indicate a signal-safe, reentrant implementation.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().