diff options
author | Jan Chren <dev.rindeal+github.com@gmail.com> | 2019-05-22 15:25:42 +0200 |
---|---|---|
committer | Jan Chren (rindeal) <dev.rindeal@gmail.com> | 2019-05-22 15:43:07 +0200 |
commit | 151b7d1d940a4dc732f23bbb7535f5c3a13c7657 (patch) | |
tree | ebee5e175d7127aa5f7b2ca1d3219ef0c391a885 | |
parent | aa39dbd1e7a3fe9b6bcb6bcc6897d90b0b5fda73 (diff) |
session/logind: check for XDG_SESSION_ID first
In order to support compositors running as systemd user units without display manager,
a mechanism for specifying session ID exactly must exist.
Checking for `XDG_SESSION_ID` mimics loginctl behaviour https://github.com/systemd/systemd/blob/e95be7def26c6c5feaf08a4135aa4f50c53263a8/src/login/loginctl.c#L856.
-rw-r--r-- | backend/session/logind.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/backend/session/logind.c b/backend/session/logind.c index 276e2c3f..c7fb24c0 100644 --- a/backend/session/logind.c +++ b/backend/session/logind.c @@ -538,15 +538,26 @@ static bool get_display_session(char **session_id) { assert(session_id != NULL); int ret; + char *type = NULL; + char *state = NULL; + char *xdg_session_id = getenv("XDG_SESSION_ID"); + + if (xdg_session_id) { + // This just checks whether the supplied session ID is valid + if (sd_session_is_active(xdg_session_id) < 0) { + wlr_log(WLR_ERROR, "Invalid XDG_SESSION_ID: '%s'", xdg_session_id); + goto error; + } + *session_id = strdup(xdg_session_id); + return true; + } + // If there's a session active for the current process then just use that ret = sd_pid_get_session(getpid(), session_id); if (ret == 0) { return true; } - char *type = NULL; - char *state = NULL; - // Find any active sessions for the user if the process isn't part of an // active session itself ret = sd_uid_get_display(getuid(), session_id); |