]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loginctl: use $XDG_SESSION_ID for "our" session
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Jun 2017 02:23:30 +0000 (22:23 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Jun 2017 02:32:14 +0000 (22:32 -0400)
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 systemd --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.

src/login/loginctl.c

index be7acbb54c2ba95a3332c2e02b5383ac20e8826d..04c2a070ac4f06906bf7958c634e6255abceef68 100644 (file)
@@ -1074,12 +1074,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;
@@ -1155,8 +1154,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;