summaryrefslogtreecommitdiffstats
path: root/usr.bin/last
diff options
context:
space:
mode:
authoriedowse <iedowse@FreeBSD.org>2002-03-01 19:46:20 +0000
committeriedowse <iedowse@FreeBSD.org>2002-03-01 19:46:20 +0000
commit6c4b4530b469fd93177f9d3c469ed4dcf85cb5ff (patch)
treef1adfdccf468d2e208e5db8c37b26278d672ea6e /usr.bin/last
parent23d1651a467ffeaadd348dc6a49aabdcf2e0dbb1 (diff)
downloadFreeBSD-src-6c4b4530b469fd93177f9d3c469ed4dcf85cb5ff.zip
FreeBSD-src-6c4b4530b469fd93177f9d3c469ed4dcf85cb5ff.tar.gz
Oops, unbreak the -d and -<n> options. The `snapfound' variable
needs to be retained across entries, and we need to exit(), not return from doentry() when `maxrec' reaches 0. Move the code for processing `maxrec' into printentry() for simplicity.
Diffstat (limited to 'usr.bin/last')
-rw-r--r--usr.bin/last/last.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c
index 4a2ec8f..f548651 100644
--- a/usr.bin/last/last.c
+++ b/usr.bin/last/last.c
@@ -91,6 +91,7 @@ static const char *file = _PATH_WTMP; /* wtmp file */
static int sflag = 0; /* show delta in seconds */
static int width = 5; /* show seconds in delta */
static int d_first;
+static int snapfound = 0; /* found snapshot entry? */
static time_t snaptime; /* if != 0, we will only
* report users logged in
* at this snapshot time
@@ -236,7 +237,6 @@ doentry(bp)
struct utmp *bp;
{
struct ttytab *tt, *ttx; /* ttylist entry */
- int snapfound = 0; /* found snapshot entry? */
/*
* if the terminal line is '~', the machine stopped.
@@ -263,11 +263,8 @@ doentry(bp)
/*
* don't print shutdown/reboot entries unless flagged for
*/
- if (!snaptime && want(bp)) {
+ if (!snaptime && want(bp))
printentry(bp, NULL);
- if (maxrec != -1 && !--maxrec)
- exit(0);
- }
return;
}
/*
@@ -276,11 +273,8 @@ doentry(bp)
*/
if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|') &&
!bp->ut_line[1]) {
- if (want(bp) && !snaptime) {
+ if (want(bp) && !snaptime)
printentry(bp, NULL);
- if (maxrec && !--maxrec)
- exit(0);
- }
return;
}
/* find associated tty */
@@ -315,8 +309,6 @@ doentry(bp)
else if (!strncmp(bp->ut_line, "uucp", sizeof("uucp") - 1))
bp->ut_line[4] = '\0';
printentry(bp, tt);
- if (maxrec != -1 && !--maxrec)
- return;
}
tt->logout = bp->ut_time;
}
@@ -338,6 +330,8 @@ printentry(bp, tt)
time_t delta; /* time difference */
time_t t;
+ if (maxrec != -1 && !maxrec--)
+ exit(0);
t = _int_to_time(bp->ut_time);
tm = localtime(&t);
(void) strftime(ct, sizeof(ct), d_first ? "%a %e %b %R" :
OpenPOWER on IntegriCloud