From: Bruno Haible Date: Wed, 2 Aug 2023 18:20:24 +0000 (+0200) Subject: readutmp: In systemd mode, put the X11 display into the ut_host field. X-Git-Tag: v1.0~978 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0d0832a5d5dc6d74e283a988c6ae0c295e089c6a;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index cee07f7cd8..bd82882a99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-08-02 Bruno Haible + + 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 readutmp: Small change to reduce the code size on the coreutils side. diff --git a/lib/readutmp.c b/lib/readutmp.c index ba4b0eadb1..11dd1655c5 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -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)