40G::Process::Id::Id() noexcept
42 m_pid =
static_cast<unsigned int>(::_getpid()) ;
45std::string G::Process::Id::str()
const
47 std::ostringstream ss ;
52bool G::Process::Id::operator==(
const Id & rhs )
const noexcept
54 return m_pid == rhs.m_pid ;
57bool G::Process::Id::operator!=(
const Id & rhs )
const noexcept
59 return m_pid != rhs.m_pid ;
66 std::cout << std::flush ;
67 std::cerr << std::flush ;
84 if( !
cd(dir,std::nothrow) )
85 throw CannotChangeDirectory( dir.str() ) ;
90 return 0 == ::_chdir( dir.cstr() ) ;
96 if( _get_errno( &e ) )
108 int old =
errno_( SignalSafe() ) ;
115 std::string s = nowide::strerror(
errno_ ) ;
121 std::string s = nowide::formatMessage( e ) ;
124 return std::string(
"error ").append( std::to_string(e) ) ;
161 return nowide::exe() ;
166 G::Path result = nowide::cwd() ;
168 throw Process::GetCwdError() ;
174 return nowide::cwd() ;
179class G::Process::UmaskImp
183G::Process::Umask::Umask( Process::Umask::Mode )
187G::Process::Umask::~Umask()
190void G::Process::Umask::set( Process::Umask::Mode )
195void G::Process::Umask::tightenOther()
200void G::Process::Umask::loosenGroup()
static Identity invalid() noexcept
Returns an invalid identity.
A Path object represents a file system path.
bool empty() const noexcept
Returns true if the path is empty.
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.
static std::string & trimRight(std::string &s, std::string_view ws, std::size_t limit=0U)
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
static std::string lower(std::string_view)
Returns a copy of 's' in which all seven-bit upper-case characters have been replaced by lower-case c...
static bool isPrintableAscii(std::string_view s) noexcept
Returns true if every character is between 0x20 and 0x7e inclusive.
Contains inline functions that convert to and from UTF-8 strings in order to call wide-character "W()...