]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: In systemd mode, put the X11 display into the ut_host field.
authorBruno Haible <bruno@clisp.org>
Wed, 2 Aug 2023 18:20:24 +0000 (20:20 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 2 Aug 2023 18:25:45 +0000 (20:25 +0200)
* lib/readutmp.c (read_utmp): In sessions of type "x11", use the X11
display as host.

ChangeLog
lib/readutmp.c

index cee07f7cd8decd5b2bf8bf35740e89936f05ceff..bd82882a992dfca79d54d84df98407006c290ff4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-08-02  Bruno Haible  <bruno@clisp.org>
+
+       readutmp: In systemd mode, put the X11 display into the ut_host field.
+       * lib/readutmp.c (read_utmp): In sessions of type "x11", use the X11
+       display as host.
+
 2023-08-02  Bruno Haible  <bruno@clisp.org>
 
        readutmp: Small change to reduce the code size on the coreutils side.
index ba4b0eadb1a041a5f9116e670ec8ba2f1e8df887..11dd1655c50de5878726a098e0bde2e2799e6683 100644 (file)
@@ -354,7 +354,25 @@ read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
                     host = xstrdup (remote_host);
                 }
               else
-                host = xstrdup ("");
+                {
+                  host = NULL;
+                  /* For backward compatibility, put the X11 display into the
+                     host field.  */
+                  char *type;
+                  if (sd_session_get_type (session, &type) >= 0)
+                    {
+                      if (strcmp (type, "x11") == 0)
+                        {
+                          char *display;
+                          if (sd_session_get_display (session, &display) < 0)
+                            display = NULL;
+                          host = display;
+                        }
+                      free (type);
+                    }
+                  if (host == NULL)
+                    host = xstrdup ("");
+                }
 
               size_t n_filled_after = n_filled + (seat != NULL) + (tty != NULL);
               if (n_filled_after > n_alloc)