Flow-IPC 1.0.2
Flow-IPC project: Full implementation reference.
|
A process's credentials (PID, UID, GID as of this writing). More...
#include <process_credentials.hpp>
Public Member Functions | |
Process_credentials () | |
Default ctor: each value is initialized to zero or equivalent. More... | |
Process_credentials (process_id_t process_id_init, user_id_t user_id_init, group_id_t group_id_init) | |
Ctor that sets the values explicitly. More... | |
Process_credentials (const Process_credentials &src) | |
Boring copy ctor. More... | |
Process_credentials & | operator= (const Process_credentials &src) |
Boring copy assignment. More... | |
process_id_t | process_id () const |
The process ID (PID). More... | |
user_id_t | user_id () const |
The user ID (UID). More... | |
group_id_t | group_id () const |
The group user ID (GID). More... | |
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, per its command line, namely argv[0] . More... | |
Static Public Member Functions | |
static process_id_t | own_process_id () |
Obtains the calling process's process_id(). More... | |
static user_id_t | own_user_id () |
Obtains the calling process's effective user_id(). More... | |
static group_id_t | own_group_id () |
Obtains the calling process's effective group_id(). More... | |
static Process_credentials | own_process_credentials () |
Constructs and returns Process_credentials containing values pertaining to the calling process at this time. More... | |
Private Attributes | |
::ucred | m_val |
The raw data. By using Linux ucred directly, we can reuse this as base for Opt_peer_process_credentials. More... | |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const Process_credentials &val1, const Process_credentials &val2) |
Checks for by-value equality between two Process_credentials objects. More... | |
bool | operator!= (const Process_credentials &val1, const Process_credentials &val2) |
Checks for by-value inequality between two Process_credentials objects. More... | |
std::ostream & | operator<< (std::ostream &os, const Process_credentials &val) |
Prints string representation of the given util::Process_credentials to the given ostream . More... | |
A process's credentials (PID, UID, GID as of this writing).
Definition at line 38 of file process_credentials.hpp.
ipc::util::Process_credentials::Process_credentials | ( | ) |
Default ctor: each value is initialized to zero or equivalent.
Definition at line 28 of file process_credentials.cpp.
Referenced by own_process_credentials().
|
explicit |
Ctor that sets the values explicitly.
process_id_init | See process_id(). |
user_id_init | See user_id(). |
group_id_init | See group_id(). |
Definition at line 34 of file process_credentials.cpp.
References m_val.
|
default |
Boring copy ctor.
src | Source object. |
group_id_t ipc::util::Process_credentials::group_id | ( | ) | const |
The group user ID (GID).
Definition at line 57 of file process_credentials.cpp.
References m_val.
Referenced by operator<<(), and operator==().
|
default |
Boring copy assignment.
src | Source object. |
*this
.
|
static |
Obtains the calling process's effective group_id().
This value can be changed via OS calls.
Definition at line 136 of file process_credentials.cpp.
Referenced by ipc::session::Client_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_GRACEFUL_FINISH_REQUIRED_V >::async_connect(), and own_process_credentials().
|
static |
Constructs and returns Process_credentials containing values pertaining to the calling process at this time.
Note that certain values therein may become incorrect over time (see own_user_id(), own_group_id()).
Definition at line 141 of file process_credentials.cpp.
References own_group_id(), own_process_id(), own_user_id(), and Process_credentials().
|
static |
Obtains the calling process's process_id().
This value will never change.
Definition at line 126 of file process_credentials.cpp.
Referenced by ipc::session::Client_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_GRACEFUL_FINISH_REQUIRED_V >::async_connect(), and own_process_credentials().
|
static |
Obtains the calling process's effective user_id().
This value can be changed via OS calls.
Definition at line 131 of file process_credentials.cpp.
Referenced by ipc::session::Client_session_impl< S_MQ_TYPE_OR_NONE, S_TRANSMIT_NATIVE_HANDLES, Mdt_payload, S_SHM_TYPE_OR_NONE, S_GRACEFUL_FINISH_REQUIRED_V >::async_connect(), and own_process_credentials().
process_id_t ipc::util::Process_credentials::process_id | ( | ) | const |
The process ID (PID).
Definition at line 47 of file process_credentials.cpp.
References m_val.
Referenced by operator<<(), operator==(), and process_invoked_as().
std::string ipc::util::Process_credentials::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, per its command line, namely argv[0]
.
In simplified terms this is the executable of *this
process; however there are important properties to consider about this information:
Because of these facts we feel it is, informally, best to use this information for one of these use cases:
For these cases it should be reasonable to use.
(Normally we omit impl details in public doc headers, but in this case the utility is low-level, and it may benefit you to know it.)
This builds in Linux only; it reads /proc/(pid)/cmdline (if it exists) and obtains the first NUL-terminated entry there. This is argv[0]
. argv
space may be overwritten by the process, so it could be something other than the original invocation. Ignoring that, it'll be whatever the command line included; could be absolute or not, normalized or not, the symlink or not... and so on. The tool ps
uses the same technique.
One technique was considered: read Linux's /proc/(pid)/exe symlink which points to the absolute, normalized executable path actually invoked. That would have been perfect; however it appears to require admin privileges on our part, and we do not want to require this. On balance, since the original use case prompting this feature (session::App::m_exec_path verification) is acceptably served by the less-demanding /proc/.../cmdline method, we chose that.
err_code | See flow::Error_code docs for error reporting semantics. Error_code generated: some system error code; but most likely no-such-file error of some kind, indicating the process is not executing (any longer?). |
err_code
not null), empty string. Caution: If error is not emitted, returned value might still be empty, if the process overrode its own command line (see above). Definition at line 62 of file process_credentials.cpp.
References process_id(), and process_invoked_as().
Referenced by process_invoked_as().
user_id_t ipc::util::Process_credentials::user_id | ( | ) | const |
The user ID (UID).
Definition at line 52 of file process_credentials.cpp.
References m_val.
Referenced by operator<<(), and operator==().
|
related |
Checks for by-value inequality between two Process_credentials objects.
process_invoked_as() does not participate in this and is not invoked.
val1 | Value to compare. |
val2 | Value to compare. |
Definition at line 152 of file process_credentials.cpp.
References ipc::util::operator==().
|
related |
Prints string representation of the given util::Process_credentials to the given ostream
.
process_invoked_as() does not participate in this and is not invoked; you may query that information if desired manually; just remember val.process_id()
must be live at the time for it to work.
os | Stream to which to write. |
val | Object to serialize. |
os
. Definition at line 157 of file process_credentials.cpp.
References group_id(), process_id(), and user_id().
|
related |
Checks for by-value equality between two Process_credentials objects.
process_invoked_as() does not participate in this and is not invoked.
val1 | Value to compare. |
val2 | Value to compare. |
Definition at line 146 of file process_credentials.cpp.
References group_id(), process_id(), and user_id().
|
private |
The raw data. By using Linux ucred
directly, we can reuse this as base for Opt_peer_process_credentials.
Definition at line 167 of file process_credentials.hpp.
Referenced by group_id(), Process_credentials(), process_id(), and user_id().