From 151dd072b37babc2e909a9a6a46631cb47e50b8f Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 19 Oct 2022 14:50:33 -0400 Subject: manager: Fix btmp record accounting Before a user logs in they don't have a display. btmp records currently need a display though, and they get written when the user can't log in. Furthermore, the display from X11 point of view is somewhat archaic. We use wayland by default now. In lieu of a display, this commit gives the btmp record the seat id instead. --- daemon/gdm-manager.c | 11 +++++++++-- daemon/gdm-session-record.c | 14 ++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'daemon') diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c index 1c8e5992..de3ac966 100644 --- a/daemon/gdm-manager.c +++ b/daemon/gdm-manager.c @@ -653,13 +653,14 @@ add_session_record (GdmManager *manager, SessionRecord record) { const char *username; - char *display_name, *hostname, *display_device; + char *display_name, *hostname, *display_device, *display_seat_id; gboolean recorded = FALSE; display_name = NULL; username = NULL; hostname = NULL; display_device = NULL; + display_seat_id = NULL; username = gdm_session_get_username (session); @@ -671,10 +672,15 @@ add_session_record (GdmManager *manager, "display-name", &display_name, "display-hostname", &hostname, "display-device", &display_device, + "display-seat-id", &display_seat_id, NULL); if (display_name == NULL && display_device == NULL) { - goto out; + if (display_seat_id == NULL) + goto out; + + display_name = g_strdup ("login screen"); + display_device = g_strdup (display_seat_id); } switch (record) { @@ -706,6 +712,7 @@ out: g_free (display_name); g_free (hostname); g_free (display_device); + g_free (display_seat_id); return recorded; } diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c index 3b41f9c1..ca2fc2bc 100644 --- a/daemon/gdm-session-record.c +++ b/daemon/gdm-session-record.c @@ -149,15 +149,21 @@ record_set_line (UTMP *u, { /* * Set ut_line to the device name associated with this display - * but remove the "/dev/" prefix. If no device, then use the - * $DISPLAY value. + * but remove the "/dev/" prefix if there is one. Otherwise, if it + * seems like the display device is a seat id, just use it wholesale. + * If there's no device at all, but $DISPLAY is set, just fall back to + * using that. */ - if (display_device != NULL - && g_str_has_prefix (display_device, "/dev/")) { + if (display_device != NULL && g_str_has_prefix (display_device, "/dev/")) { memccpy (u->ut_line, display_device + strlen ("/dev/"), '\0', sizeof (u->ut_line)); + } else if (display_device != NULL && g_str_has_prefix (display_device, "seat")) { + memccpy (u->ut_line, + display_device, + '\0', + sizeof (u->ut_line)); } else if (x11_display_name != NULL) { memccpy (u->ut_line, x11_display_name, -- cgit v1.2.1