summaryrefslogtreecommitdiffstats
path: root/login-utils/last.c
diff options
context:
space:
mode:
authorSami Kerola2017-01-16 23:31:36 +0100
committerSami Kerola2017-01-16 23:31:36 +0100
commit78acfddd1df9e571dbe3bdc351b56bb0e53ca5e8 (patch)
treea11eeacd3cf22840af4a2978f971bf078d66364b /login-utils/last.c
parentlibfdisk: (gpt) make calculations more robust (diff)
downloadkernel-qcow2-util-linux-78acfddd1df9e571dbe3bdc351b56bb0e53ca5e8.tar.gz
kernel-qcow2-util-linux-78acfddd1df9e571dbe3bdc351b56bb0e53ca5e8.tar.xz
kernel-qcow2-util-linux-78acfddd1df9e571dbe3bdc351b56bb0e53ca5e8.zip
last: use --time-format instruction when printing wtmp creation time
This makes --time-format=iso timestamp to look the same as login/logout times. When --time-format=noformat is used the file creation time not printed. There is no change to default format. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/last.c')
-rw-r--r--login-utils/last.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/login-utils/last.c b/login-utils/last.c
index 7c243f147..5ebd5e2ba 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -345,7 +345,8 @@ static int time_formatter(int fmt, char *dst, size_t dlen, time_t *when)
break;
}
case LAST_TIMEFTM_CTIME:
- ret = snprintf(dst, dlen, "%s", ctime(when));
+ snprintf(dst, dlen, "%s", ctime(when));
+ ret = rtrim_whitespace((unsigned char *) dst);
break;
case LAST_TIMEFTM_ISO8601:
ret = strtime_iso(when, ISO_8601_DATE|ISO_8601_TIME|ISO_8601_TIMEZONE, dst, dlen);
@@ -874,11 +875,19 @@ static void process_wtmp_file(const struct last_control *ctl,
}
}
- {
- char* tmp = xstrdup(filename);
- printf(_("\n%s begins %s"), basename(tmp), ctime(&begintime));
+ if (ctl->time_fmt != LAST_TIMEFTM_NONE) {
+ struct last_timefmt *fmt;
+ char timestr[LAST_TIMESTAMP_LEN];
+ char *tmp = xstrdup(filename);
+
+ fmt = &timefmts[ctl->time_fmt];
+ if (time_formatter(fmt->in_fmt, timestr,
+ sizeof(timestr), &begintime) < 0)
+ errx(EXIT_FAILURE, _("preallocation size exceeded"));
+ printf(_("\n%s begins %s\n"), basename(tmp), timestr);
free(tmp);
}
+
fclose(fp);
for (p = ulist; p; p = next) {