38G::Process::Id::Id() noexcept
40 m_pid =
static_cast<unsigned int>(::_getpid()) ;
43std::string G::Process::Id::str()
const
45 std::ostringstream ss ;
50bool G::Process::Id::operator==(
const Id & rhs )
const noexcept
52 return m_pid == rhs.m_pid ;
55bool G::Process::Id::operator!=(
const Id & rhs )
const noexcept
57 return m_pid != rhs.m_pid ;
64 std::cout << std::flush ;
65 std::cerr << std::flush ;
78 if( !
cd(dir,std::nothrow) )
79 throw CannotChangeDirectory( dir.str() ) ;
84 return 0 == ::_chdir( dir.cstr() ) ;
90 if( _get_errno( &e ) )
102 int old =
errno_( SignalSafe() ) ;
109 std::vector<char> buffer( 80U ,
'\0' ) ;
110 if( strerror_s( &buffer[0] , buffer.size()-1U ,
errno_ ) || buffer.at(0U) ==
'\0' )
112 std::string s( &buffer[0] ) ;
149 std::vector<char> buffer ;
150 std::size_t sizes[] = { 80U , 1024U , 32768U , 0U } ;
151 for( std::size_t * size_p = sizes ; *size_p ; ++size_p )
153 buffer.resize( *size_p+1U ,
'\0' ) ;
154 DWORD size =
static_cast<DWORD
>( buffer.size() ) ;
155 HINSTANCE hinstance = HNULL ;
156 DWORD rc = ::GetModuleFileNameA( hinstance , &buffer[0] , size ) ;
157 if( rc == 0 ) break ;
159 return std::string( &buffer[0] , rc ) ;
161 return std::string() ;
166 char * p = _getcwd(
nullptr , 2048 ) ;
170 throw GetCwdError() ;
171 return std::string() ;
175 std::string result( p ) ;
183class G::Process::UmaskImp
187G::Process::Umask::Umask( Process::Umask::Mode )
191G::Process::Umask::~Umask()
194void G::Process::Umask::set( Process::Umask::Mode )
199void G::Process::Umask::tightenOther()
204void G::Process::Umask::loosenGroup()
static Identity invalid() noexcept
Returns an invalid identity.
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.
static bool isPrintableAscii(string_view s) noexcept
Returns true if every character is a 7-bit, non-control character (ie.
static std::string fromInt(int i)
Converts int 'i' to a string.
static std::string lower(string_view)
Returns a copy of 's' in which all seven-bit upper-case characters have been replaced by lower-case c...