From 6c4b4530b469fd93177f9d3c469ed4dcf85cb5ff Mon Sep 17 00:00:00 2001 From: iedowse Date: Fri, 1 Mar 2002 19:46:20 +0000 Subject: Oops, unbreak the -d and - 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. --- usr.bin/last/last.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'usr.bin/last/last.c') 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" : -- cgit v1.1