diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-05-31 22:23:30 -0400 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-07-25 09:46:52 +0200 |
commit | 4ac036ad95f68f0a5032c41459ce39322b1726f8 (patch) | |
tree | dc5d838964953efd050ce20d73a8743ec7d5c17d | |
parent | d7808ce8dab201703e85b7eee3f21ec65a14537f (diff) |
loginctl: use $XDG_SESSION_ID for "our" session
Instead of always letting logind guess what the caller's session is, let's
give it the value from $XDG_SESSION_ID when it is present in the caller's
environment.
Nowadays terminal emulators are often running as services under elogind --user,
and not as part of an actual session, so all loginctl calls which depend on
logind guessing the session will fail. I don't see a reason not to honour
$XDG_SESSION_ID.
This applies to LockSession, UnlockSession, TerminateSession, ActivateSession,
SetUserLinger.
Fixes #6032.
-rw-r--r-- | src/login/loginctl.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 9ff1b781d..5945d5160 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -1095,12 +1095,11 @@ static int activate(int argc, char *argv[], void *userdata) { polkit_agent_open_if_enabled(); if (argc < 2) { - /* No argument? Let's convert this into the empty - * session name, which the calls will then resolve to - * the caller's session. */ + /* No argument? Let's either use $XDG_SESSION_ID (if specified), or an empty + * session name, in which case logind will try to guess our session. */ short_argv[0] = argv[0]; - short_argv[1] = (char*) ""; + short_argv[1] = getenv("XDG_SESSION_ID") ?: (char*) ""; short_argv[2] = NULL; argv = short_argv; @@ -1176,8 +1175,11 @@ static int enable_linger(int argc, char *argv[], void *userdata) { b = streq(argv[0], "enable-linger"); if (argc < 2) { + /* No argument? Let's either use $XDG_SESSION_ID (if specified), or an empty + * session name, in which case logind will try to guess our session. */ + short_argv[0] = argv[0]; - short_argv[1] = (char*) ""; + short_argv[1] = getenv("XDG_SESSION_ID") ?: (char*) ""; short_argv[2] = NULL; argv = short_argv; argc = 2; |