Annotation of src/usr.bin/last/last.c, Revision 1.30
1.30 ! otto 1: /* $OpenBSD: last.c,v 1.29 2003/11/09 20:13:57 otto Exp $ */
1.1 deraadt 2: /* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */
3:
4: /*
5: * Copyright (c) 1987, 1993, 1994
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
1.26 millert 16: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: */
32:
33: #ifndef lint
34: static char copyright[] =
35: "@(#) Copyright (c) 1987, 1993, 1994\n\
36: The Regents of the University of California. All rights reserved.\n";
37: #endif /* not lint */
38:
39: #ifndef lint
40: #if 0
41: static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94";
42: #endif
1.30 ! otto 43: static char rcsid[] = "$OpenBSD: last.c,v 1.29 2003/11/09 20:13:57 otto Exp $";
1.1 deraadt 44: #endif /* not lint */
45:
46: #include <sys/param.h>
47: #include <sys/stat.h>
48:
49: #include <err.h>
50: #include <fcntl.h>
51: #include <paths.h>
52: #include <signal.h>
53: #include <stdio.h>
54: #include <stdlib.h>
55: #include <string.h>
56: #include <time.h>
57: #include <tzfile.h>
58: #include <unistd.h>
59: #include <utmp.h>
60:
61: #define NO 0 /* false/no */
62: #define YES 1 /* true/yes */
1.18 mickey 63: #define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
1.1 deraadt 64:
65: static struct utmp buf[1024]; /* utmp read buffer */
66:
67: typedef struct arg {
68: char *name; /* argument */
69: #define HOST_TYPE -2
70: #define TTY_TYPE -3
71: #define USER_TYPE -4
72: int type; /* type of arg */
73: struct arg *next; /* linked list pointer */
74: } ARG;
75: ARG *arglist; /* head of linked list */
76:
77: typedef struct ttytab {
78: time_t logout; /* log out time */
79: char tty[UT_LINESIZE + 1]; /* terminal name */
80: struct ttytab *next; /* linked list pointer */
81: } TTY;
82: TTY *ttylist; /* head of linked list */
83:
84: static time_t currentout; /* current logout value */
85: static long maxrec; /* records to display */
86: static char *file = _PATH_WTMP; /* wtmp file */
1.6 mickey 87: static int fulltime = 0; /* Display seconds? */
1.7 deraadt 88: static time_t snaptime; /* if != 0, we will only
89: * report users logged in
90: * at this snapshot time
1.4 jdm 91: */
1.9 downsj 92: static int calculate = 0;
93: static int seconds = 0;
1.1 deraadt 94:
1.19 millert 95: void addarg(int, char *);
96: TTY *addtty(char *);
97: void hostconv(char *);
98: void onintr(int);
99: char *ttyconv(char *);
100: time_t dateconv(char *);
101: int want(struct utmp *, int);
102: void wtmp(void);
103: void checkargs(void);
1.22 deraadt 104: void usage(void);
1.1 deraadt 105:
1.28 deraadt 106: #define NAME_WIDTH 9
1.14 fgsch 107: #define HOST_WIDTH 24
1.13 deraadt 108:
1.1 deraadt 109: int
1.27 deraadt 110: main(int argc, char *argv[])
1.1 deraadt 111: {
112: extern int optind;
113: extern char *optarg;
114: int ch;
115: char *p;
116:
117: maxrec = -1;
1.4 jdm 118: snaptime = 0;
1.9 downsj 119: while ((ch = getopt(argc, argv, "0123456789cf:h:st:d:T")) != -1)
1.1 deraadt 120: switch (ch) {
121: case '0': case '1': case '2': case '3': case '4':
122: case '5': case '6': case '7': case '8': case '9':
123: /*
124: * kludge: last was originally designed to take
125: * a number after a dash.
126: */
127: if (maxrec == -1) {
128: p = argv[optind - 1];
129: if (p[0] == '-' && p[1] == ch && !p[2])
130: maxrec = atol(++p);
131: else
132: maxrec = atol(argv[optind] + 1);
133: if (!maxrec)
134: exit(0);
135: }
136: break;
1.9 downsj 137: case 'c':
138: calculate++;
139: break;
1.1 deraadt 140: case 'f':
141: file = optarg;
142: break;
143: case 'h':
144: hostconv(optarg);
145: addarg(HOST_TYPE, optarg);
146: break;
1.9 downsj 147: case 's':
148: seconds++;
149: break;
1.1 deraadt 150: case 't':
151: addarg(TTY_TYPE, ttyconv(optarg));
152: break;
1.4 jdm 153: case 'd':
154: snaptime = dateconv(optarg);
155: break;
1.6 mickey 156: case 'T':
1.9 downsj 157: fulltime = 1;
1.6 mickey 158: break;
1.1 deraadt 159: case '?':
160: default:
1.22 deraadt 161: usage();
1.1 deraadt 162: }
163:
164: if (argc) {
165: setlinebuf(stdout);
166: for (argv += optind; *argv; ++argv) {
167: #define COMPATIBILITY
168: #ifdef COMPATIBILITY
169: /* code to allow "last p5" to work */
170: addarg(TTY_TYPE, ttyconv(*argv));
171: #endif
172: addarg(USER_TYPE, *argv);
173: }
174: }
1.18 mickey 175:
1.5 jdm 176: checkargs();
1.1 deraadt 177: wtmp();
178: exit(0);
179: }
180:
181: /*
1.5 jdm 182: * checkargs --
1.18 mickey 183: * if snaptime is set, print warning if usernames, or -t or -h
1.5 jdm 184: * flags are also provided
185: */
186:
187: void
1.27 deraadt 188: checkargs(void)
1.5 jdm 189: {
1.18 mickey 190: ARG *step;
191: int ttyflag = 0;
1.5 jdm 192:
1.18 mickey 193: if (!snaptime)
1.5 jdm 194: return;
1.18 mickey 195:
1.5 jdm 196: if (!arglist)
197: return;
198:
199: for (step = arglist; step; step = step->next)
200: switch (step->type) {
201: case HOST_TYPE:
1.7 deraadt 202: (void)fprintf(stderr,
203: "Warning: Ignoring hostname flag\n");
1.5 jdm 204: break;
205: case TTY_TYPE:
1.18 mickey 206: if (!ttyflag) { /* don't print this twice */
1.7 deraadt 207: (void)fprintf(stderr,
208: "Warning: Ignoring tty flag\n");
1.5 jdm 209: ttyflag = 1;
210: }
211: break;
212: case USER_TYPE:
1.7 deraadt 213: (void)fprintf(stderr,
214: "Warning: Ignoring username[s]\n");
1.5 jdm 215: break;
216: default:
1.20 millert 217: break;
1.5 jdm 218: /* PRINT NOTHING */
219: }
1.18 mickey 220: }
1.5 jdm 221:
222:
223: /*
1.1 deraadt 224: * wtmp --
225: * read through the wtmp file
226: */
227: void
1.27 deraadt 228: wtmp(void)
1.1 deraadt 229: {
1.6 mickey 230: struct utmp *bp; /* current structure */
231: TTY *T; /* tty list entry */
232: struct stat stb; /* stat of file for size */
1.8 deraadt 233: time_t delta; /* time difference */
1.30 ! otto 234: time_t total = 0;
1.8 deraadt 235: off_t bl;
1.6 mickey 236: int timesize; /* how long time string gonna be */
1.1 deraadt 237: int bytes, wfd;
238: char *ct, *crmsg;
1.18 mickey 239: int snapfound = 0; /* found snapshot entry? */
1.1 deraadt 240: if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1)
241: err(1, "%s", file);
242: bl = (stb.st_size + sizeof(buf) - 1) / sizeof(buf);
243:
1.6 mickey 244: if (fulltime)
245: timesize = 8; /* HH:MM:SS */
246: else
247: timesize = 5; /* HH:MM */
248:
1.1 deraadt 249: (void)time(&buf[0].ut_time);
250: (void)signal(SIGINT, onintr);
251: (void)signal(SIGQUIT, onintr);
252:
253: while (--bl >= 0) {
1.11 millert 254: if (lseek(wfd, bl * sizeof(buf), SEEK_SET) == -1 ||
1.1 deraadt 255: (bytes = read(wfd, buf, sizeof(buf))) == -1)
256: err(1, "%s", file);
257: for (bp = &buf[bytes / sizeof(buf[0]) - 1]; bp >= buf; --bp) {
258: /*
259: * if the terminal line is '~', the machine stopped.
260: * see utmp(5) for more info.
261: */
262: if (bp->ut_line[0] == '~' && !bp->ut_line[1]) {
263: /* everybody just logged out */
264: for (T = ttylist; T; T = T->next)
265: T->logout = -bp->ut_time;
266: currentout = -bp->ut_time;
267: crmsg = strncmp(bp->ut_name, "shutdown",
268: UT_NAMESIZE) ? "crash" : "shutdown";
1.18 mickey 269: /*
270: * if we're in snapshot mode, we want to
1.4 jdm 271: * exit if this shutdown/reboot appears
272: * while we we are tracking the active
273: * range
274: */
275: if (snaptime && snapfound)
276: return;
1.18 mickey 277: /*
1.4 jdm 278: * don't print shutdown/reboot entries
1.18 mickey 279: * unless flagged for
280: */
1.5 jdm 281: if (want(bp, NO)) {
1.9 downsj 282: if (seconds) {
1.15 deraadt 283: printf("%-*.*s %-*.*s %-*.*s %ld \n",
284: NAME_WIDTH, UT_NAMESIZE,
285: bp->ut_name, UT_LINESIZE,
286: UT_LINESIZE, bp->ut_line,
287: HOST_WIDTH, UT_HOSTSIZE,
1.16 pvalchev 288: bp->ut_host, (long)bp->ut_time);
1.9 downsj 289: } else {
290: ct = ctime(&bp->ut_time);
1.28 deraadt 291: printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s \n",
1.15 deraadt 292: NAME_WIDTH, UT_NAMESIZE,
293: bp->ut_name, UT_LINESIZE,
294: UT_LINESIZE, bp->ut_line,
295: HOST_WIDTH, UT_HOSTSIZE,
296: bp->ut_host, ct, timesize,
297: timesize, ct + 11);
1.9 downsj 298: }
1.1 deraadt 299: if (maxrec != -1 && !--maxrec)
300: return;
301: }
302: continue;
303: }
304: /*
305: * if the line is '{' or '|', date got set; see
306: * utmp(5) for more info.
307: */
308: if ((bp->ut_line[0] == '{' || bp->ut_line[0] == '|')
309: && !bp->ut_line[1]) {
1.5 jdm 310: if (want(bp, NO)) {
1.9 downsj 311: if (seconds) {
1.28 deraadt 312: printf("%-*.*s %-*.*s %-*.*s %ld \n",
313: NAME_WIDTH, UT_NAMESIZE, bp->ut_name,
314: UT_LINESIZE, UT_LINESIZE, bp->ut_line,
315: HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,
316: (long)bp->ut_time);
1.18 mickey 317: } else {
1.9 downsj 318: ct = ctime(&bp->ut_time);
1.28 deraadt 319: printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s \n",
320: NAME_WIDTH, UT_NAMESIZE, bp->ut_name,
321: UT_LINESIZE, UT_LINESIZE, bp->ut_line,
322: HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,
323: ct, timesize, timesize, ct + 11);
1.18 mickey 324: }
1.1 deraadt 325: if (maxrec && !--maxrec)
326: return;
327: }
328: continue;
329: }
330: /* find associated tty */
331: for (T = ttylist;; T = T->next) {
332: if (!T) {
333: /* add new one */
334: T = addtty(bp->ut_line);
335: break;
336: }
337: if (!strncmp(T->tty, bp->ut_line, UT_LINESIZE))
338: break;
339: }
1.18 mickey 340: /*
1.4 jdm 341: * print record if not in snapshot mode and wanted
342: * or in snapshot mode and in snapshot range
343: */
344: if (bp->ut_name[0] &&
1.28 deraadt 345: ((want(bp, YES)) || (bp->ut_time < snaptime &&
346: (T->logout > snaptime || !T->logout ||
347: T->logout < 0)))) {
1.4 jdm 348: snapfound = 1;
1.9 downsj 349: if (seconds) {
1.28 deraadt 350: printf("%-*.*s %-*.*s %-*.*s %ld ",
351: NAME_WIDTH, UT_NAMESIZE, bp->ut_name,
352: UT_LINESIZE, UT_LINESIZE, bp->ut_line,
353: HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,
354: (long)bp->ut_time);
1.9 downsj 355: } else {
356: ct = ctime(&bp->ut_time);
1.28 deraadt 357: printf("%-*.*s %-*.*s %-*.*s %10.10s %*.*s ",
358: NAME_WIDTH, UT_NAMESIZE, bp->ut_name,
359: UT_LINESIZE, UT_LINESIZE, bp->ut_line,
360: HOST_WIDTH, UT_HOSTSIZE, bp->ut_host,
361: ct, timesize, timesize, ct + 11);
1.9 downsj 362: }
1.1 deraadt 363: if (!T->logout)
364: puts(" still logged in");
365: else {
366: if (T->logout < 0) {
367: T->logout = -T->logout;
368: printf("- %s", crmsg);
1.9 downsj 369: } else {
1.18 mickey 370: if (seconds)
1.9 downsj 371: printf("- %ld",
1.16 pvalchev 372: (long)T->logout);
1.9 downsj 373: else
374: printf("- %*.*s",
375: timesize, timesize,
376: ctime(&T->logout)+11);
1.1 deraadt 377: }
378: delta = T->logout - bp->ut_time;
1.9 downsj 379: if (seconds)
1.16 pvalchev 380: printf(" (%ld)\n", (long)delta);
1.9 downsj 381: else {
382: if (delta < SECSPERDAY)
383: printf(" (%*.*s)\n",
384: timesize, timesize,
385: asctime(gmtime(&delta))+11);
386: else
387: printf(" (%ld+%*.*s)\n",
388: delta / SECSPERDAY,
389: timesize, timesize,
390: asctime(gmtime(&delta))+11);
391: }
392: if (calculate)
393: total += delta;
1.1 deraadt 394: }
395: if (maxrec != -1 && !--maxrec)
396: return;
397: }
398: T->logout = bp->ut_time;
399: }
1.9 downsj 400: }
401: if (calculate) {
402: if ((total / SECSPERDAY) > 0) {
403: int days = (total / SECSPERDAY);
404: total -= (days * SECSPERDAY);
405:
406: printf("\nTotal time: %d days, %*.*s\n",
1.28 deraadt 407: days, timesize, timesize,
408: asctime(gmtime(&total))+11);
1.9 downsj 409: } else
410: printf("\nTotal time: %*.*s\n",
1.28 deraadt 411: timesize, timesize,
412: asctime(gmtime(&total))+11);
1.1 deraadt 413: }
414: ct = ctime(&buf[0].ut_time);
1.10 deraadt 415: printf("\nwtmp begins %10.10s %*.*s %4.4s\n", ct, timesize, timesize,
416: ct + 11, ct + 20);
1.1 deraadt 417: }
418:
419: /*
420: * want --
421: * see if want this entry
422: */
423: int
1.27 deraadt 424: want(struct utmp *bp, int check)
1.1 deraadt 425: {
426: ARG *step;
427:
1.15 deraadt 428: if (check) {
1.1 deraadt 429: /*
430: * when uucp and ftp log in over a network, the entry in
431: * the utmp file is the name plus their process id. See
432: * etc/ftpd.c and usr.bin/uucp/uucpd.c for more information.
433: */
434: if (!strncmp(bp->ut_line, "ftp", sizeof("ftp") - 1))
435: bp->ut_line[3] = '\0';
436: else if (!strncmp(bp->ut_line, "uucp", sizeof("uucp") - 1))
437: bp->ut_line[4] = '\0';
1.15 deraadt 438: }
1.5 jdm 439:
1.18 mickey 440: if (snaptime) /* if snaptime is set, return NO */
1.5 jdm 441: return (NO);
442:
1.1 deraadt 443: if (!arglist)
444: return (YES);
445:
446: for (step = arglist; step; step = step->next)
447: switch(step->type) {
448: case HOST_TYPE:
449: if (!strncasecmp(step->name, bp->ut_host, UT_HOSTSIZE))
450: return (YES);
451: break;
452: case TTY_TYPE:
453: if (!strncmp(step->name, bp->ut_line, UT_LINESIZE))
454: return (YES);
455: break;
456: case USER_TYPE:
457: if (!strncmp(step->name, bp->ut_name, UT_NAMESIZE))
458: return (YES);
459: break;
1.5 jdm 460: }
461:
1.1 deraadt 462: return (NO);
463: }
464:
465: /*
466: * addarg --
467: * add an entry to a linked list of arguments
468: */
469: void
1.27 deraadt 470: addarg(int type, char *arg)
1.1 deraadt 471: {
472: ARG *cur;
473:
474: if (!(cur = (ARG *)malloc((u_int)sizeof(ARG))))
475: err(1, "malloc failure");
476: cur->next = arglist;
477: cur->type = type;
478: cur->name = arg;
479: arglist = cur;
480: }
481:
482: /*
483: * addtty --
484: * add an entry to a linked list of ttys
485: */
486: TTY *
1.27 deraadt 487: addtty(char *ttyname)
1.1 deraadt 488: {
489: TTY *cur;
490:
491: if (!(cur = (TTY *)malloc((u_int)sizeof(TTY))))
492: err(1, "malloc failure");
493: cur->next = ttylist;
494: cur->logout = currentout;
495: memmove(cur->tty, ttyname, UT_LINESIZE);
496: return (ttylist = cur);
497: }
498:
499: /*
500: * hostconv --
501: * convert the hostname to search pattern; if the supplied host name
502: * has a domain attached that is the same as the current domain, rip
503: * off the domain suffix since that's what login(1) does.
504: */
505: void
1.27 deraadt 506: hostconv(char *arg)
1.1 deraadt 507: {
508: static int first = 1;
509: static char *hostdot, name[MAXHOSTNAMELEN];
510: char *argdot;
511:
512: if (!(argdot = strchr(arg, '.')))
513: return;
514: if (first) {
515: first = 0;
516: if (gethostname(name, sizeof(name)))
517: err(1, "gethostname");
518: hostdot = strchr(name, '.');
519: }
520: if (hostdot && !strcasecmp(hostdot, argdot))
521: *argdot = '\0';
522: }
523:
524: /*
525: * ttyconv --
526: * convert tty to correct name.
527: */
528: char *
1.27 deraadt 529: ttyconv(char *arg)
1.1 deraadt 530: {
531: char *mval;
1.21 deraadt 532: size_t len = 8;
1.1 deraadt 533:
534: /*
535: * kludge -- we assume that all tty's end with
536: * a two character suffix.
537: */
538: if (strlen(arg) == 2) {
539: /* either 6 for "ttyxx" or 8 for "console" */
1.21 deraadt 540: if (!(mval = malloc(len)))
1.1 deraadt 541: err(1, "malloc failure");
542: if (!strcmp(arg, "co"))
1.21 deraadt 543: (void)strlcpy(mval, "console", len);
544: else
545: snprintf(mval, len, "tty%s", arg);
1.1 deraadt 546: return (mval);
547: }
548: if (!strncmp(arg, _PATH_DEV, sizeof(_PATH_DEV) - 1))
549: return (arg + 5);
550: return (arg);
551: }
1.4 jdm 552:
1.18 mickey 553: /*
1.4 jdm 554: * dateconv --
1.18 mickey 555: * Convert the snapshot time in command line given in the format
1.23 deraadt 556: * [[[CC]YY]MMDD]hhmm[.SS]] to a time_t.
1.18 mickey 557: * Derived from atime_arg1() in usr.bin/touch/touch.c
1.4 jdm 558: */
559: time_t
1.27 deraadt 560: dateconv(char *arg)
1.4 jdm 561: {
1.7 deraadt 562: time_t timet;
563: struct tm *t;
564: int yearset;
565: char *p;
566:
567: /* Start with the current time. */
568: if (time(&timet) < 0)
569: err(1, "time");
570: if ((t = localtime(&timet)) == NULL)
571: err(1, "localtime");
572:
1.23 deraadt 573: /* [[[CC]YY]MMDD]hhmm[.SS] */
1.7 deraadt 574: if ((p = strchr(arg, '.')) == NULL)
1.18 mickey 575: t->tm_sec = 0; /* Seconds defaults to 0. */
1.7 deraadt 576: else {
577: if (strlen(p + 1) != 2)
578: goto terr;
579: *p++ = '\0';
580: t->tm_sec = ATOI2(p);
581: }
582:
583: yearset = 0;
584: switch (strlen(arg)) {
1.22 deraadt 585: case 12: /* CCYYMMDDhhmm */
1.7 deraadt 586: t->tm_year = ATOI2(arg);
587: t->tm_year *= 100;
588: yearset = 1;
1.29 otto 589: /* FALLTHROUGH */
1.22 deraadt 590: case 10: /* YYMMDDhhmm */
1.7 deraadt 591: if (yearset) {
592: yearset = ATOI2(arg);
593: t->tm_year += yearset;
594: } else {
595: yearset = ATOI2(arg);
596: if (yearset < 69)
597: t->tm_year = yearset + 2000;
598: else
599: t->tm_year = yearset + 1900;
600: }
1.28 deraadt 601: t->tm_year -= 1900; /* Convert to UNIX time. */
1.7 deraadt 602: /* FALLTHROUGH */
603: case 8: /* MMDDhhmm */
604: t->tm_mon = ATOI2(arg);
1.18 mickey 605: --t->tm_mon; /* Convert from 01-12 to 00-11 */
1.7 deraadt 606: t->tm_mday = ATOI2(arg);
607: t->tm_hour = ATOI2(arg);
608: t->tm_min = ATOI2(arg);
609: break;
610: case 4: /* hhmm */
611: t->tm_hour = ATOI2(arg);
612: t->tm_min = ATOI2(arg);
613: break;
614: default:
615: goto terr;
616: }
1.18 mickey 617: t->tm_isdst = -1; /* Figure out DST. */
1.7 deraadt 618: timet = mktime(t);
619: if (timet == -1)
1.28 deraadt 620: terr: errx(1, "out of range or illegal time specification: "
621: "[[[CC]YY]MMDD]hhmm[.SS]");
1.22 deraadt 622: return (timet);
1.4 jdm 623: }
624:
1.1 deraadt 625:
626: /*
627: * onintr --
628: * on interrupt, we inform the user how far we've gotten
629: */
630: void
1.27 deraadt 631: onintr(int signo)
1.1 deraadt 632: {
1.25 deraadt 633: char str[1024], *ct;
1.1 deraadt 634:
1.25 deraadt 635: ct = ctime(&buf[0].ut_time); /* XXX signal race */
636: snprintf(str, sizeof str, "\ninterrupted %10.10s %8.8s \n",
637: ct, ct + 11);
638: write(STDOUT_FILENO, str, strlen(str));
1.1 deraadt 639: if (signo == SIGINT)
1.25 deraadt 640: _exit(1);
1.22 deraadt 641: }
642:
643: void
644: usage(void)
645: {
646: extern char *__progname;
647:
648: fprintf(stderr,
649: "usage: %s [-#] [-csT] [-f file] [-t tty] [-h host]"
1.23 deraadt 650: " [-d [[[CC]YY]MMDD]hhmm[.SS]] [user ...]\n", __progname);
1.22 deraadt 651: exit(1);
1.1 deraadt 652: }