=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/last/last.c,v retrieving revision 1.4 retrieving revision 1.5 diff -c -r1.4 -r1.5 *** src/usr.bin/last/last.c 1997/07/20 07:54:09 1.4 --- src/usr.bin/last/last.c 1997/07/20 09:07:17 1.5 *************** *** 1,4 **** ! /* $OpenBSD: last.c,v 1.4 1997/07/20 07:54:09 jdm Exp $ */ /* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: last.c,v 1.5 1997/07/20 09:07:17 jdm Exp $ */ /* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */ /* *************** *** 44,50 **** #if 0 static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; #endif ! static char rcsid[] = "$OpenBSD: last.c,v 1.4 1997/07/20 07:54:09 jdm Exp $"; #endif /* not lint */ #include --- 44,50 ---- #if 0 static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; #endif ! static char rcsid[] = "$OpenBSD: last.c,v 1.5 1997/07/20 09:07:17 jdm Exp $"; #endif /* not lint */ #include *************** *** 101,106 **** --- 101,107 ---- time_t dateconv __P((char *)); int want __P((struct utmp *, int)); void wtmp __P((void)); + void checkargs __P((void)); int main(argc, argv) *************** *** 165,175 **** --- 166,219 ---- addarg(USER_TYPE, *argv); } } + + checkargs(); wtmp(); exit(0); } /* + * checkargs -- + * if snaptime is set, print warning if usernames, or -t or -h + * flags are also provided + */ + + void + checkargs() + { + ARG *step; + int ttyflag = 0; + + if (!snaptime) + return; + + if (!arglist) + return; + + for (step = arglist; step; step = step->next) + switch (step->type) { + case HOST_TYPE: + (void)fprintf(stderr, "Warning: Ignoring hostname " + "flag\n"); + break; + case TTY_TYPE: + if (!ttyflag) { /* don't print this twice */ + (void)fprintf(stderr, "Warning: Ignoring " + "tty flag\n"); + ttyflag = 1; + } + break; + case USER_TYPE: + (void)fprintf(stderr, "Warning: Ignoring " + "username[s]\n"); + break; + default: + /* PRINT NOTHING */ + } + } + + + /* * wtmp -- * read through the wtmp file */ *************** *** 217,226 **** return; /* * don't print shutdown/reboot entries ! * unless flagged for and not in snapshot ! * mode */ ! if (!snaptime && want(bp, NO)) { ct = ctime(&bp->ut_time); printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", UT_NAMESIZE, UT_NAMESIZE, --- 261,269 ---- return; /* * don't print shutdown/reboot entries ! * unless flagged for */ ! if (want(bp, NO)) { ct = ctime(&bp->ut_time); printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", UT_NAMESIZE, UT_NAMESIZE, *************** *** 239,245 **** */ if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|') && !bp->ut_line[1]) { ! if (want(bp, NO) && !snaptime) { ct = ctime(&bp->ut_time); printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, --- 282,288 ---- */ if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|') && !bp->ut_line[1]) { ! if (want(bp, NO)) { ct = ctime(&bp->ut_time); printf("%-*.*s %-*.*s %-*.*s %10.10s %5.5s \n", UT_NAMESIZE, UT_NAMESIZE, bp->ut_name, *************** *** 266,272 **** * or in snapshot mode and in snapshot range */ if (bp->ut_name[0] && ! ((!snaptime && want(bp, YES)) || (bp->ut_time < snaptime && (T->logout > snaptime || !T->logout || T->logout < 0)))) { --- 309,315 ---- * or in snapshot mode and in snapshot range */ if (bp->ut_name[0] && ! ((want(bp, YES)) || (bp->ut_time < snaptime && (T->logout > snaptime || !T->logout || T->logout < 0)))) { *************** *** 327,332 **** --- 370,379 ---- bp->ut_line[3] = '\0'; else if (!strncmp(bp->ut_line, "uucp", sizeof("uucp") - 1)) bp->ut_line[4] = '\0'; + + if (snaptime) /* if snaptime is set, return NO */ + return (NO); + if (!arglist) return (YES); *************** *** 344,350 **** if (!strncmp(step->name, bp->ut_name, UT_NAMESIZE)) return (YES); break; ! } return (NO); } --- 391,398 ---- if (!strncmp(step->name, bp->ut_name, UT_NAMESIZE)) return (YES); break; ! } ! return (NO); } *************** *** 445,451 **** /* * dateconv -- * Convert the snapshot time in command line given in the format ! * [[CC]YY]MMDDhhmm[.SS]] to a time_t. * Derived from atime_arg1() in usr.bin/touch/touch.c */ time_t --- 493,499 ---- /* * dateconv -- * Convert the snapshot time in command line given in the format ! * [[CC]YY][MMDD]hhmm[.SS]] to a time_t. * Derived from atime_arg1() in usr.bin/touch/touch.c */ time_t *************** *** 463,469 **** if ((t = localtime(&timet)) == NULL) err(1, "localtime"); ! /* [[CC]YY]MMDDhhmm[.SS] */ if ((p = strchr(arg, '.')) == NULL) t->tm_sec = 0; /* Seconds defaults to 0. */ else { --- 511,517 ---- if ((t = localtime(&timet)) == NULL) err(1, "localtime"); ! /* [[CC]YY][MMDD]hhmm[.SS] */ if ((p = strchr(arg, '.')) == NULL) t->tm_sec = 0; /* Seconds defaults to 0. */ else { *************** *** 511,517 **** timet = mktime(t); if (timet == -1) terr: errx(1, ! "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); return timet; } --- 559,565 ---- timet = mktime(t); if (timet == -1) terr: errx(1, ! "out of range or illegal time specification: [[CC]YY][MMDD]hhmm[.SS]"); return timet; }