From 0d0832a5d5dc6d74e283a988c6ae0c295e089c6a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 2 Aug 2023 20:20:24 +0200 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ lib/readutmp.c | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) 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) -- 2.39.5