summaryrefslogtreecommitdiff
path: root/src/login/logind-session.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-04-28 17:55:36 +0200
committerLennart Poettering <lennart@poettering.net>2019-05-24 15:05:27 +0200
commit3b92c086a8d5338e2164ffa0ae48b3d03d10cfb5 (patch)
treea8aaf4ad9f5778566018a63fd95cf37b69aa06e7 /src/login/logind-session.h
parent469df514c7e10fbfdc3abb243e0458fd44084fc2 (diff)
downloadsystemd-3b92c086a8d5338e2164ffa0ae48b3d03d10cfb5.tar.gz
logind: make "self" and "auto" magic strings when operating on seats + sessions
Most of the operations one can do on sessions so far accepted an empty session name as a shortcut for the caller's session. This is quite useful traditionally, but much less useful than it used to be, since most user code now (rightfully) runs in --user context, not in a session. With this change we tweak the logic a bit: we introduce the two special session and seat names "self" and "auto". The former refers to the session/seat the client is in, and is hence mostly equivalent to te empty string "" as before. However, the latter refers to the session/seat the client is in if that exists, with a fallback of the user's display session if not. Clients can hence reference "auto" instead of the empty string if they really don't want to think much about sessions. Why "self" btw? Previously, we'd already expose a special dbus object with the path /org/freedesktop/login1/session/self (and similar for the seat), matching what the empty string did for bus calls that took a session name. With this scheme we reuse this identifier and introduce "auto" in a similar way. Of course this means real-life seats and sessions can never be named "self" or "auto", but they aren't anyway: valid seat names have to start with "seat" anyway, and sessions are generated server-side as either a numeric value or "c" suffixed with a counter ID. Fixes: #12399
Diffstat (limited to 'src/login/logind-session.h')
-rw-r--r--src/login/logind-session.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index f3c17a8d91..884a8f45b8 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -7,6 +7,7 @@ typedef enum KillWho KillWho;
#include "list.h"
#include "login-util.h"
#include "logind-user.h"
+#include "string-util.h"
typedef enum SessionState {
SESSION_OPENING, /* Session scope is being created */
@@ -183,3 +184,11 @@ int bus_session_method_activate(sd_bus_message *message, void *userdata, sd_bus_
int bus_session_method_lock(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_session_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error);
int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error);
+
+static inline bool SESSION_IS_SELF(const char *name) {
+ return isempty(name) || streq(name, "self");
+}
+
+static inline bool SESSION_IS_AUTO(const char *name) {
+ return streq_ptr(name, "auto");
+}