From 8f1686cbe121e981760119cb11c2ddd1a95f25d1 Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Tue, 28 Jun 2016 13:01:26 +0200 Subject: [PATCH] wtmp: Fix logout times in login-history Logout times for users are correct if user logs off and then shutdown from GDM, however logout times are wrong if user shutdowns directly from the user session, because DEAD_PROCESS record is missing in that case and BOOT_TIME record is used instead. Wtmp contains also shutdown/reboot records. Set logout time to the time from those record instead of BOOT_TIME. https://bugs.freedesktop.org/show_bug.cgi?id=94497 --- src/wtmp-helper.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wtmp-helper.c b/src/wtmp-helper.c index 83ac43b..4986e16 100644 --- a/src/wtmp-helper.c +++ b/src/wtmp-helper.c @@ -107,9 +107,17 @@ wtmp_helper_entry_generator (GHashTable *users, while ((wtmp_entry = getutxent ())) { UserAccounting *accounting; UserPreviousLogin *previous_login; + gboolean shutdown_or_reboot = FALSE; - if (wtmp_entry->ut_type == BOOT_TIME) { - /* Set boot time for missing logout records */ + if (g_str_equal (wtmp_entry->ut_line, "~")) { + if (g_str_equal (wtmp_entry->ut_user, "shutdown") || + g_str_equal (wtmp_entry->ut_user, "reboot")) { + shutdown_or_reboot = TRUE; + } + } + + if (wtmp_entry->ut_type == BOOT_TIME || shutdown_or_reboot) { + /* Set shutdown, reboot, or boot time for missing logout records */ g_hash_table_iter_init (&iter, logout_hash); while (g_hash_table_iter_next (&iter, &key, &value)) { previous_login = (UserPreviousLogin *) value; -- 2.7.4