From 9d0b73a648888ffb1a57f2014ac27a23edd3a95c Mon Sep 17 00:00:00 2001 From: Troy Rollo Date: Wed, 19 Jul 2023 11:04:56 +1000 Subject: [PATCH] login-utils: Report crashes on reboot lines insted of overlapping uptimes --- login-utils/last.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/login-utils/last.c b/login-utils/last.c index 37c6abe972..eaebc1fe6a 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -111,6 +111,7 @@ enum { R_NORMAL, /* Normal */ R_NOW, /* Still logged in */ R_REBOOT, /* Reboot record. */ + R_REBOOT_CRASH, /* Reboot record without matching shutdown */ R_PHANTOM, /* No logout record but session is stale. */ R_TIMECHANGE /* NEW_TIME or OLD_TIME */ }; @@ -469,6 +470,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t switch(what) { case R_CRASH: + case R_REBOOT_CRASH: snprintf(logouttime, sizeof(logouttime), "- crash"); break; case R_DOWN: @@ -786,7 +788,10 @@ static void process_wtmp_file(const struct last_control *ctl, break; case BOOT_TIME: strcpy(ut.ut_line, "system boot"); - quit = list(ctl, &ut, lastdown, R_REBOOT); + if (lastdown > lastboot && lastdown != currentdate) + quit = list(ctl, &ut, lastboot, R_REBOOT_CRASH); + else + quit = list(ctl, &ut, lastdown, R_REBOOT); lastboot = ut.ut_tv.tv_sec; down = 1; break; -- 2.47.2