Flow-IPC 1.0.2
Flow-IPC project: Public API.
|
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. | |
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... | |
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).
|
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(). |
|
default |
Boring copy ctor.
src | Source object. |
group_id_t ipc::util::Process_credentials::group_id | ( | ) | const |
The group user ID (GID).
|
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.
|
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()).
|
static |
|
static |
Obtains the calling process's effective user_id().
This value can be changed via OS calls.
process_id_t ipc::util::Process_credentials::process_id | ( | ) | const |
The process ID (PID).
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). user_id_t ipc::util::Process_credentials::user_id | ( | ) | const |
The user ID (UID).
|
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. |
|
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
.
|
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. |