]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login-utils: Report crashes on reboot lines insted of overlapping uptimes
authorTroy Rollo <linux@troy.rollo.name>
Wed, 19 Jul 2023 01:04:56 +0000 (11:04 +1000)
committerTroy Rollo <linux@troy.rollo.name>
Wed, 19 Jul 2023 01:04:56 +0000 (11:04 +1000)
login-utils/last.c

index 37c6abe972cb58e520442f8c886a5311235d9e28..eaebc1fe6a0930ca508d4b52d9bac9ca16b41cdb 100644 (file)
@@ -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;