20#include <flow/error/error.hpp>
21#include <flow/common.hpp>
22#include <boost/filesystem/fstream.hpp>
23#include <boost/lexical_cast.hpp>
50 m_val.pid = process_id_init;
51 m_val.uid = user_id_init;
52 m_val.gid = group_id_init;
75 using boost::lexical_cast;
76 using boost::system::system_category;
87 static_assert(
false,
"process_invoked_as() depends on Linux /proc semantics.");
90 path cmd_line_path{
"/proc"};
91 cmd_line_path /= lexical_cast<path>(
process_id());
92 cmd_line_path /=
"cmdline";
103 ifstream cmd_line_file(cmd_line_path, ios_base::binary);
104 if (!cmd_line_file.good())
106 *err_code = {errno, system_category()};
123 const int ch_or_none = cmd_line_file.get();
124 if (!(done = (!cmd_line_file.good()) || (
char(ch_or_none) ==
'\0')))
126 result += ch_or_none;
132 if ((!cmd_line_file.good()) && (!cmd_line_file.eof()))
134 assert((errno != 0) &&
"There had to be *some* reason file reading failed, and it wasn't EOF.");
135 *err_code = {errno, system_category()};
178 const auto uid = val.
user_id();
180 if ((pid == 0) && (uid == 0) && (gid == 0))
189 return os <<
"pid[" << pid <<
"], user[" << uid <<
':' << gid <<
']';
A process's credentials (PID, UID, GID as of this writing).
process_id_t process_id() const
The process ID (PID).
static process_id_t own_process_id()
Obtains the calling process's process_id().
Process_credentials()
Default ctor: each value is initialized to zero/OS-appropriate equivalent.
static Process_credentials own_process_credentials()
Constructs and returns Process_credentials containing values pertaining to the calling process at thi...
::ucred m_val
The raw data. By using Linux ucred directly, we can reuse this as base for Opt_peer_process_credentia...
Process_credentials & operator=(const Process_credentials &src)
Boring copy assignment.
std::string process_invoked_as(Error_code *err_code=nullptr) const
Obtains, from the OS, information as to the binary name via which process process_id() was started,...
static user_id_t own_user_id()
Obtains the calling process's effective user_id().
static group_id_t own_group_id()
Obtains the calling process's effective group_id().
user_id_t user_id() const
The user ID (UID).
group_id_t group_id() const
The group ID (GID).
Flow-IPC module containing miscellaneous general-use facilities that are ubiquitously used by ~all Fl...
::pid_t process_id_t
Syntactic-sugary type for POSIX process ID (integer).
std::ostream & operator<<(std::ostream &os, const Native_handle &val)
Prints string representation of the given Native_handle to the given ostream.
::gid_t group_id_t
Syntactic-sugary type for POSIX group ID (integer).
::uid_t user_id_t
Syntactic-sugary type for POSIX user ID (integer).
const Process_credentials NULL_PROCESS_CREDENTIALS
A (default-cted) Process_credentials. May be useful for functions returning const Process_credentials...
constexpr bool operator!=(Native_handle val1, Native_handle val2) noexcept
Negation of similar ==.
constexpr bool operator==(Native_handle val1, Native_handle val2) noexcept
Returns true if and only if the two Native_handle objects are the same underlying handle.
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.