From d4ce90d47cf89d018ac6fcf50481fbafa2682c46 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 16 Aug 2014 10:38:04 +0100 Subject: last: improve code readability by renaming variable names Signed-off-by: Sami Kerola --- login-utils/last.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'login-utils/last.c') diff --git a/login-utils/last.c b/login-utils/last.c index fb82f31c0..54d9e1f8e 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -376,9 +376,9 @@ static void trim_trailing_spaces(char *s) /* * Show one line of information on screen */ -static int list(const struct last_control *ctl, struct utmp *p, time_t t, int what) +static int list(const struct last_control *ctl, struct utmp *p, time_t logout_time, int what) { - time_t secs, tmp, epoch; + time_t secs, utmp_time, now; char logintime[LAST_TIMESTAMP_LEN]; char logouttime[LAST_TIMESTAMP_LEN]; char length[LAST_TIMESTAMP_LEN]; @@ -417,22 +417,25 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t t, int wh /* * Calculate times */ - tmp = p->UL_UT_TIME; + utmp_time = p->UL_UT_TIME; - if (ctl->present && (ctl->present < tmp || (0 < t && t < ctl->present))) - return 0; - - if (time_formatter(ctl, &logintime[0], sizeof(logintime), &tmp, 0) < 0 || - time_formatter(ctl, &logouttime[0], sizeof(logouttime), &t, 1) < 0) + if (ctl->present) { + if (ctl->present < utmp_time) + return 0; + if (0 < logout_time && logout_time < ctl->present) + return 0; + } + if (time_formatter(ctl, &logintime[0], sizeof(logintime), &utmp_time, 0) < 0 || + time_formatter(ctl, &logouttime[0], sizeof(logouttime), &logout_time, 1) < 0) errx(EXIT_FAILURE, _("preallocation size exceeded")); - secs = t - p->UL_UT_TIME; + secs = logout_time - utmp_time; mins = (secs / 60) % 60; hours = (secs / 3600) % 24; days = secs / 86400; - epoch = time(NULL); - if (t == epoch) { + now = time(NULL); + if (logout_time == now) { if (ctl->time_fmt > LAST_TIMEFTM_SHORT_CTIME) { sprintf(logouttime, " still running"); length[0] = 0; -- cgit v1.2.3-55-g7522