Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
session_broker.cpp File Reference

Client for the privileged Hermes session account broker. More...

#include "session_broker.h"
#include "session_broker_transport.h"
#include "src/logging.h"
#include <algorithm>
#include <charconv>
#include <cstdlib>
#include <limits>
#include <sstream>
#include <sys/stat.h>
Include dependency graph for session_broker.cpp:

Go to the source code of this file.

Functions

bool platf::session_broker::available ()
 Whether a broker socket is there to talk to.
std::optional< account_t > platf::session_broker::ensure (const std::string &client_uuid)
 The client's account, created if this is the first time it asked.
std::optional< account_t > platf::session_broker::lookup (const std::string &client_uuid)
 The client's account if it already has one, without creating it.
std::optional< std::string > platf::session_broker::start (const std::string &client_uuid, const std::vector< std::string > &arguments, const std::vector< std::string > &environment, const std::string &scope={})
 Start arguments as the client's account, and return the unit name.
std::optional< std::string > platf::session_broker::wayland_socket (const std::string &client_uuid)
 The name of the Wayland socket the session's compositor created.
std::optional< bool > platf::session_broker::query_active (const std::string &client_uuid)
 Query liveness without treating communication failure as session exit.
bool platf::session_broker::active (const std::string &client_uuid)
 Whether the client's session is running right now.
bool platf::session_broker::stop (const std::string &client_uuid)
 Stop the client's session unit. Stopping one that is already gone succeeds, so this is safe to call on a teardown path that may run twice.

Detailed Description

Client for the privileged Hermes session account broker.

Definition in file session_broker.cpp.

Function Documentation

◆ active()

bool platf::session_broker::active ( const std::string & client_uuid)

Whether the client's session is running right now.

A session started this way is a systemd unit, not a child of Hermes, so there is no process handle on this side to ask. systemd is the only thing that knows, and the broker is how this side reaches it.

Definition at line 245 of file session_broker.cpp.

◆ available()

bool platf::session_broker::available ( )

Whether a broker socket is there to talk to.

False on every host that has not installed and enabled the broker, which is the normal case. A caller that finds none runs the session as the Hermes user, the way it did before accounts existed - less isolated, but working.

Definition at line 124 of file session_broker.cpp.

◆ ensure()

std::optional< account_t > platf::session_broker::ensure ( const std::string & client_uuid)

The client's account, created if this is the first time it asked.

Idempotent: a client that comes back gets the account it had, which is what makes its files still be there. Fails when the Hermes user is not in the broker's allow file, or when every configured slot is in use. Account and lifetime mutations have a bounded three-minute budget, including queues; read-only queries retain their short deadline.

Definition at line 130 of file session_broker.cpp.

◆ lookup()

std::optional< account_t > platf::session_broker::lookup ( const std::string & client_uuid)

The client's account if it already has one, without creating it.

Definition at line 142 of file session_broker.cpp.

◆ query_active()

std::optional< bool > platf::session_broker::query_active ( const std::string & client_uuid)

Query liveness without treating communication failure as session exit.

Returns
True for active/activating/reloading, false for a confirmed stopped or unmapped session, nullopt for unavailable/malformed/unknown status.

Lifecycle monitoring should use this query and preserve a live session on nullopt. The bool active() wrapper retains its older false-on-error contract.

Definition at line 215 of file session_broker.cpp.

◆ start()

std::optional< std::string > platf::session_broker::start ( const std::string & client_uuid,
const std::vector< std::string > & arguments,
const std::vector< std::string > & environment,
const std::string & scope = {} )

Start arguments as the client's account, and return the unit name.

The session becomes a transient systemd unit rather than a child of Hermes: it needs a uid Hermes cannot assume, and a unit is also what gives it a cgroup, a lifetime and a sandbox of its own. arguments[0] must be an absolute path - the broker resolves nothing and no shell is involved on either side, so nothing here needs quoting. environment is a list of NAME=VALUE assignments; XDG_RUNTIME_DIR is set by the broker to match the account and cannot be overridden from here.

scope names a second unit beside the session's own, for what runs inside the session once it is up; an empty scope is the session itself. A scoped unit is bound to the session's, so stopping the session stops it too - the way terminating the process group did when all of this was a child of Hermes.

Definition at line 149 of file session_broker.cpp.

◆ stop()

bool platf::session_broker::stop ( const std::string & client_uuid)

Stop the client's session unit. Stopping one that is already gone succeeds, so this is safe to call on a teardown path that may run twice.

Definition at line 249 of file session_broker.cpp.

◆ wayland_socket()

std::optional< std::string > platf::session_broker::wayland_socket ( const std::string & client_uuid)

The name of the Wayland socket the session's compositor created.

Hermes cannot list the session's runtime directory once it belongs to another user, so the broker lists it and returns only the name. A name is all that is needed: whatever connects to the socket is launched into the session rather than run by Hermes. Nothing yet is not an error - a compositor that has not finished starting has not made one - so this is meant to be polled.

Definition at line 198 of file session_broker.cpp.