20#include <flow/error/error.hpp>
21#include <flow/common.hpp>
39 m_val.pid = process_id_init;
40 m_val.uid = user_id_init;
41 m_val.gid = group_id_init;
64 using boost::lexical_cast;
65 using boost::system::system_category;
76# error "process_invoked_as() depends on Linux /proc semantics."
79 path cmd_line_path(
"/proc");
80 cmd_line_path /= lexical_cast<path>(
process_id());
81 cmd_line_path /=
"cmdline";
86 ifstream cmd_line_file(cmd_line_path, ios_base::binary);
87 if (!cmd_line_file.good())
89 *err_code =
Error_code(errno, system_category());
106 const int ch_or_none = cmd_line_file.get();
107 if (!(done = (!cmd_line_file.good()) || (
char(ch_or_none) ==
'\0')))
109 result += ch_or_none;
115 if ((!cmd_line_file.good()) && (!cmd_line_file.eof()))
117 assert((errno != 0) &&
"There had to be *some* reason file reading failed, and it wasn't EOF.");
118 *err_code =
Error_code(errno, system_category());
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 or 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.
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).
std::string process_invoked_as(Error_code *err_code=0) const
Obtains, from the OS, information as to the binary name via which process process_id() was started,...
group_id_t group_id() const
The group user ID (GID).
Flow-IPC module containing miscellaneous general-use facilities that ubiquitously used by ~all Flow-I...
::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).
bool operator!=(Native_handle val1, Native_handle val2)
Negation of similar ==.
bool operator==(Native_handle val1, Native_handle val2)
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.