10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
230Sstevel@tonic-gate /* All Rights Reserved */
240Sstevel@tonic-gate
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
27*428Ssl108498 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
280Sstevel@tonic-gate * Use is subject to license terms.
290Sstevel@tonic-gate */
30*428Ssl108498 #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate * acctcon1 [-p] [-t] [-l file] [-o file] <wtmpx-file >ctmp-file
330Sstevel@tonic-gate * -p print input only, no processing
340Sstevel@tonic-gate * -t test mode: use latest time found in input, rather than
350Sstevel@tonic-gate * current time when computing times of lines still on
360Sstevel@tonic-gate * (only way to get repeatable data from old files)
370Sstevel@tonic-gate * -l file causes output of line usage summary
380Sstevel@tonic-gate * -o file causes first/last/reboots report to be written to file
390Sstevel@tonic-gate * reads input (normally /var/adm/wtmpx), produces
400Sstevel@tonic-gate * list of sessions, sorted by ending time in ctmp.h/ascii format
410Sstevel@tonic-gate * A_TSIZE is max # distinct ttys
420Sstevel@tonic-gate */
430Sstevel@tonic-gate
440Sstevel@tonic-gate #include <sys/types.h>
450Sstevel@tonic-gate #include "acctdef.h"
460Sstevel@tonic-gate #include <stdio.h>
470Sstevel@tonic-gate #include <ctype.h>
480Sstevel@tonic-gate #include <time.h>
490Sstevel@tonic-gate #include <utmpx.h>
500Sstevel@tonic-gate #include <locale.h>
51*428Ssl108498 #include <stdlib.h>
520Sstevel@tonic-gate
530Sstevel@tonic-gate int a_tsize = A_TSIZE;
540Sstevel@tonic-gate int tsize = -1; /* used slots in tbuf table */
550Sstevel@tonic-gate struct utmpx wb; /* record structure read into */
560Sstevel@tonic-gate struct ctmp cb; /* record structure written out of */
570Sstevel@tonic-gate
580Sstevel@tonic-gate struct tbuf {
590Sstevel@tonic-gate char tline[LSZ]; /* /dev/... */
600Sstevel@tonic-gate char tname[NSZ]; /* user name */
610Sstevel@tonic-gate time_t ttime; /* start time */
620Sstevel@tonic-gate dev_t tdev; /* device */
630Sstevel@tonic-gate int tlsess; /* # complete sessions */
640Sstevel@tonic-gate int tlon; /* # times on (ut_type of 7) */
650Sstevel@tonic-gate int tloff; /* # times off (ut_type != 7) */
660Sstevel@tonic-gate long ttotal; /* total time used on this line */
670Sstevel@tonic-gate } * tbuf;
680Sstevel@tonic-gate
690Sstevel@tonic-gate #define DATE_FMT "%a %b %e %H:%M:%S %Y\n"
700Sstevel@tonic-gate int nsys;
710Sstevel@tonic-gate struct sys {
720Sstevel@tonic-gate char sname[LSZ]; /* reasons for ACCOUNTING records */
730Sstevel@tonic-gate char snum; /* number of times encountered */
740Sstevel@tonic-gate } sy[NSYS];
750Sstevel@tonic-gate
760Sstevel@tonic-gate time_t datetime; /* old time if date changed, otherwise 0 */
770Sstevel@tonic-gate time_t firstime;
780Sstevel@tonic-gate time_t lastime;
790Sstevel@tonic-gate int ndates; /* number of times date changed */
800Sstevel@tonic-gate int exitcode;
810Sstevel@tonic-gate char *report = NULL;
820Sstevel@tonic-gate char *replin = NULL;
830Sstevel@tonic-gate int printonly;
840Sstevel@tonic-gate int tflag;
850Sstevel@tonic-gate
860Sstevel@tonic-gate static char time_buf[50];
870Sstevel@tonic-gate uid_t namtouid();
880Sstevel@tonic-gate dev_t lintodev();
890Sstevel@tonic-gate static size_t wread(void);
900Sstevel@tonic-gate static int valid(void);
910Sstevel@tonic-gate static void fixup(FILE *);
920Sstevel@tonic-gate static void loop(void);
930Sstevel@tonic-gate static void bootshut(void);
940Sstevel@tonic-gate static int iline(void);
950Sstevel@tonic-gate static void upall(void);
960Sstevel@tonic-gate static void update(struct tbuf *);
970Sstevel@tonic-gate static void printrep(void);
980Sstevel@tonic-gate static void printlin(void);
990Sstevel@tonic-gate static void prctmp(struct ctmp *);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate int
main(int argc,char ** argv)1020Sstevel@tonic-gate main(int argc, char **argv)
1030Sstevel@tonic-gate {
1040Sstevel@tonic-gate char *prog = argv[0];
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate (void)setlocale(LC_ALL, "");
1070Sstevel@tonic-gate while (--argc > 0 && **++argv == '-')
1080Sstevel@tonic-gate switch(*++*argv) {
1090Sstevel@tonic-gate case 'l':
1100Sstevel@tonic-gate if (--argc > 0)
1110Sstevel@tonic-gate replin = *++argv;
1120Sstevel@tonic-gate continue;
1130Sstevel@tonic-gate case 'o':
1140Sstevel@tonic-gate if (--argc > 0)
1150Sstevel@tonic-gate report = *++argv;
1160Sstevel@tonic-gate continue;
1170Sstevel@tonic-gate case 'p':
1180Sstevel@tonic-gate printonly++;
1190Sstevel@tonic-gate continue;
1200Sstevel@tonic-gate case 't':
1210Sstevel@tonic-gate tflag++;
1220Sstevel@tonic-gate continue;
1230Sstevel@tonic-gate default:
1240Sstevel@tonic-gate fprintf(stderr, "usage: %s [-p] [-t] [-l lineuse] [-o reboot]\n", prog);
1250Sstevel@tonic-gate exit(1);
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate if ((tbuf = (struct tbuf *) calloc(a_tsize,
1300Sstevel@tonic-gate sizeof (struct tbuf))) == NULL) {
1310Sstevel@tonic-gate fprintf(stderr, "acctcon1: Cannot allocate memory\n");
1320Sstevel@tonic-gate exit(3);
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate if (printonly) {
1360Sstevel@tonic-gate while (wread()) {
1370Sstevel@tonic-gate if (valid()) {
1380Sstevel@tonic-gate printf("%.*s\t%.*s\t%lu",
1390Sstevel@tonic-gate sizeof (wb.ut_line),
1400Sstevel@tonic-gate wb.ut_line,
1410Sstevel@tonic-gate sizeof (wb.ut_name),
1420Sstevel@tonic-gate wb.ut_name,
1430Sstevel@tonic-gate wb.ut_xtime);
1440Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &wb.ut_xtime);
1450Sstevel@tonic-gate printf("\t%s", time_buf);
1460Sstevel@tonic-gate } else
1470Sstevel@tonic-gate fixup(stdout);
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate exit(exitcode);
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate while (wread()) {
1540Sstevel@tonic-gate if (firstime == 0)
1550Sstevel@tonic-gate firstime = wb.ut_xtime;
1560Sstevel@tonic-gate if (valid())
1570Sstevel@tonic-gate loop();
1580Sstevel@tonic-gate else
1590Sstevel@tonic-gate fixup(stderr);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate wb.ut_name[0] = '\0';
1620Sstevel@tonic-gate strcpy(wb.ut_line, "acctcon1");
1630Sstevel@tonic-gate wb.ut_type = ACCOUNTING;
1640Sstevel@tonic-gate if (tflag)
1650Sstevel@tonic-gate wb.ut_xtime = lastime;
1660Sstevel@tonic-gate else
1670Sstevel@tonic-gate time(&wb.ut_xtime);
1680Sstevel@tonic-gate loop();
1690Sstevel@tonic-gate if (report != NULL)
1700Sstevel@tonic-gate printrep();
1710Sstevel@tonic-gate if (replin != NULL)
1720Sstevel@tonic-gate printlin();
1730Sstevel@tonic-gate exit(exitcode);
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate static size_t
wread()1770Sstevel@tonic-gate wread()
1780Sstevel@tonic-gate {
1790Sstevel@tonic-gate return (fread(&wb, sizeof(wb), 1, stdin) == 1);
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate /*
1840Sstevel@tonic-gate * valid: check input wtmp record, return 1 if looks OK
1850Sstevel@tonic-gate */
1860Sstevel@tonic-gate static int
valid()1870Sstevel@tonic-gate valid()
1880Sstevel@tonic-gate {
1890Sstevel@tonic-gate int i, c;
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate /* XPG say that user names should not start with a "-". */
1920Sstevel@tonic-gate if ((c = wb.ut_name[0]) == '-')
1930Sstevel@tonic-gate return(0);
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate for (i = 0; i < NSZ; i++) {
1960Sstevel@tonic-gate c = wb.ut_name[i];
1970Sstevel@tonic-gate if (isalnum(c) || c == '$' || c == ' ' || c == '_' || c == '-')
1980Sstevel@tonic-gate continue;
1990Sstevel@tonic-gate else if (c == '\0')
2000Sstevel@tonic-gate break;
2010Sstevel@tonic-gate else
2020Sstevel@tonic-gate return(0);
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate
2050Sstevel@tonic-gate if((wb.ut_type >= EMPTY) && (wb.ut_type <= UTMAXTYPE))
2060Sstevel@tonic-gate return(1);
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate return(0);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate /*
2120Sstevel@tonic-gate * fixup assumes that V6 wtmp (16 bytes long) is mixed in with
2130Sstevel@tonic-gate * V7 records (20 bytes each)
2140Sstevel@tonic-gate *
2150Sstevel@tonic-gate * Starting with Release 5.0 of UNIX, this routine will no
2160Sstevel@tonic-gate * longer reset the read pointer. This has a snowball effect
2170Sstevel@tonic-gate * On the following records until the offset corrects itself.
2180Sstevel@tonic-gate * If a message is printed from here, it should be regarded as
2190Sstevel@tonic-gate * a bad record and not as a V6 record.
2200Sstevel@tonic-gate */
2210Sstevel@tonic-gate static void
fixup(FILE * stream)2220Sstevel@tonic-gate fixup(FILE *stream)
2230Sstevel@tonic-gate {
2240Sstevel@tonic-gate fprintf(stream, "bad wtmpx: offset %lu.\n", ftell(stdin)-sizeof(wb));
2250Sstevel@tonic-gate fprintf(stream, "bad record is: %.*s\t%.*s\t%lu",
2260Sstevel@tonic-gate sizeof (wb.ut_line),
2270Sstevel@tonic-gate wb.ut_line,
2280Sstevel@tonic-gate sizeof (wb.ut_name),
2290Sstevel@tonic-gate wb.ut_name,
2300Sstevel@tonic-gate wb.ut_xtime);
2310Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &wb.ut_xtime);
2320Sstevel@tonic-gate fprintf(stream, "\t%s", time_buf);
2330Sstevel@tonic-gate #ifdef V6
2340Sstevel@tonic-gate fseek(stdin, (long)-4, 1);
2350Sstevel@tonic-gate #endif
2360Sstevel@tonic-gate exitcode = 1;
2370Sstevel@tonic-gate }
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate static void
loop()2400Sstevel@tonic-gate loop()
2410Sstevel@tonic-gate {
2420Sstevel@tonic-gate int timediff;
2430Sstevel@tonic-gate struct tbuf *tp;
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate if(wb.ut_line[0] == '\0' ) /* It's an init admin process */
2460Sstevel@tonic-gate return; /* no connect accounting data here */
2470Sstevel@tonic-gate switch(wb.ut_type) {
2480Sstevel@tonic-gate case OLD_TIME:
2490Sstevel@tonic-gate datetime = wb.ut_xtime;
2500Sstevel@tonic-gate return;
2510Sstevel@tonic-gate case NEW_TIME:
2520Sstevel@tonic-gate if(datetime == 0)
2530Sstevel@tonic-gate return;
2540Sstevel@tonic-gate timediff = wb.ut_xtime - datetime;
2550Sstevel@tonic-gate for (tp = tbuf; tp <= &tbuf[tsize]; tp++)
2560Sstevel@tonic-gate tp->ttime += timediff;
2570Sstevel@tonic-gate datetime = 0;
2580Sstevel@tonic-gate ndates++;
2590Sstevel@tonic-gate return;
2600Sstevel@tonic-gate case BOOT_TIME:
2610Sstevel@tonic-gate upall();
2620Sstevel@tonic-gate case ACCOUNTING:
2630Sstevel@tonic-gate case RUN_LVL:
2640Sstevel@tonic-gate lastime = wb.ut_xtime;
2650Sstevel@tonic-gate bootshut();
2660Sstevel@tonic-gate return;
2670Sstevel@tonic-gate case USER_PROCESS:
2680Sstevel@tonic-gate case LOGIN_PROCESS:
2690Sstevel@tonic-gate case INIT_PROCESS:
2700Sstevel@tonic-gate case DEAD_PROCESS:
2710Sstevel@tonic-gate update(&tbuf[iline()]);
2720Sstevel@tonic-gate return;
2730Sstevel@tonic-gate case EMPTY:
2740Sstevel@tonic-gate return;
2750Sstevel@tonic-gate default:
2760Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &wb.ut_xtime);
2770Sstevel@tonic-gate fprintf(stderr, "acctcon1: invalid type %d for %s %s %s",
2780Sstevel@tonic-gate wb.ut_type,
2790Sstevel@tonic-gate wb.ut_name,
2800Sstevel@tonic-gate wb.ut_line,
2810Sstevel@tonic-gate time_buf);
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate
2850Sstevel@tonic-gate /*
2860Sstevel@tonic-gate * bootshut: record reboot (or shutdown)
2870Sstevel@tonic-gate * bump count, looking up wb.ut_line in sy table
2880Sstevel@tonic-gate */
2890Sstevel@tonic-gate static void
bootshut()2900Sstevel@tonic-gate bootshut()
2910Sstevel@tonic-gate {
2920Sstevel@tonic-gate int i;
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate for (i = 0; i < nsys && !EQN(wb.ut_line, sy[i].sname); i++)
2950Sstevel@tonic-gate ;
2960Sstevel@tonic-gate if (i >= nsys) {
2970Sstevel@tonic-gate if (++nsys > NSYS) {
2980Sstevel@tonic-gate fprintf(stderr,
2990Sstevel@tonic-gate "acctcon1: recompile with larger NSYS\n");
3000Sstevel@tonic-gate nsys = NSYS;
3010Sstevel@tonic-gate return;
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate CPYN(sy[i].sname, wb.ut_line);
3040Sstevel@tonic-gate }
3050Sstevel@tonic-gate sy[i].snum++;
3060Sstevel@tonic-gate }
3070Sstevel@tonic-gate
3080Sstevel@tonic-gate /*
3090Sstevel@tonic-gate * iline: look up/enter current line name in tbuf, return index
3100Sstevel@tonic-gate * (used to avoid system dependencies on naming)
3110Sstevel@tonic-gate */
3120Sstevel@tonic-gate static int
iline()3130Sstevel@tonic-gate iline()
3140Sstevel@tonic-gate {
3150Sstevel@tonic-gate int i;
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate for (i = 0; i <= tsize; i++)
3180Sstevel@tonic-gate if (EQN(wb.ut_line, tbuf[i].tline))
3190Sstevel@tonic-gate return(i);
3200Sstevel@tonic-gate if (++tsize >= a_tsize) {
3210Sstevel@tonic-gate a_tsize = a_tsize + A_TSIZE;
3220Sstevel@tonic-gate if ((tbuf = (struct tbuf *) realloc(tbuf, a_tsize *
3230Sstevel@tonic-gate sizeof (struct tbuf))) == NULL) {
3240Sstevel@tonic-gate fprintf(stderr, "acctcon1: Cannot reallocate memory\n");
3250Sstevel@tonic-gate exit(2);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate CPYN(tbuf[tsize].tline, wb.ut_line);
3300Sstevel@tonic-gate tbuf[tsize].tdev = lintodev(wb.ut_line);
3310Sstevel@tonic-gate return(tsize);
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate static void
upall()3350Sstevel@tonic-gate upall()
3360Sstevel@tonic-gate {
3370Sstevel@tonic-gate struct tbuf *tp;
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate wb.ut_type = INIT_PROCESS; /* fudge a logoff for reboot record */
3400Sstevel@tonic-gate for (tp = tbuf; tp <= &tbuf[tsize]; tp++)
3410Sstevel@tonic-gate update(tp);
3420Sstevel@tonic-gate }
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate /*
3450Sstevel@tonic-gate * update tbuf with new time, write ctmp record for end of session
3460Sstevel@tonic-gate */
3470Sstevel@tonic-gate static void
update(struct tbuf * tp)3480Sstevel@tonic-gate update(struct tbuf *tp)
3490Sstevel@tonic-gate {
3500Sstevel@tonic-gate time_t told, /* last time for tbuf record */
3510Sstevel@tonic-gate tnew; /* time of this record */
3520Sstevel@tonic-gate /* Difference is connect time */
3530Sstevel@tonic-gate
3540Sstevel@tonic-gate told = tp->ttime;
3550Sstevel@tonic-gate tnew = wb.ut_xtime;
3560Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &told);
3570Sstevel@tonic-gate fprintf(stderr, "The old time is: %s", time_buf);
3580Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &tnew);
3590Sstevel@tonic-gate fprintf(stderr, "the new time is: %s", time_buf);
3600Sstevel@tonic-gate if (told > tnew) {
3610Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &told);
3620Sstevel@tonic-gate fprintf(stderr, "acctcon1: bad times: old: %s", time_buf);
3630Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &tnew);
3640Sstevel@tonic-gate fprintf(stderr, "new: %s", time_buf);
3650Sstevel@tonic-gate exitcode = 1;
3660Sstevel@tonic-gate tp->ttime = tnew;
3670Sstevel@tonic-gate return;
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate tp->ttime = tnew;
3700Sstevel@tonic-gate switch(wb.ut_type) {
3710Sstevel@tonic-gate case USER_PROCESS:
3720Sstevel@tonic-gate tp->tlsess++;
3730Sstevel@tonic-gate if(tp->tname[0] != '\0') { /* Someone logged in without */
3740Sstevel@tonic-gate /* logging off. Put out record. */
3750Sstevel@tonic-gate cb.ct_tty = tp->tdev;
3760Sstevel@tonic-gate CPYN(cb.ct_name, tp->tname);
3770Sstevel@tonic-gate cb.ct_uid = namtouid(cb.ct_name);
3780Sstevel@tonic-gate cb.ct_start = told;
3790Sstevel@tonic-gate if (pnpsplit(cb.ct_start, (ulong_t)(tnew-told),
3800Sstevel@tonic-gate cb.ct_con) == 0) {
3810Sstevel@tonic-gate fprintf(stderr, "acctcon1: could not calculate prime/non-prime hours\n");
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate exit(1);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate prctmp(&cb);
3860Sstevel@tonic-gate tp->ttotal += tnew-told;
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate else /* Someone just logged in */
3890Sstevel@tonic-gate tp->tlon++;
3900Sstevel@tonic-gate CPYN(tp->tname, wb.ut_name);
3910Sstevel@tonic-gate break;
3920Sstevel@tonic-gate case INIT_PROCESS:
3930Sstevel@tonic-gate case LOGIN_PROCESS:
3940Sstevel@tonic-gate case DEAD_PROCESS:
3950Sstevel@tonic-gate tp->tloff++;
3960Sstevel@tonic-gate if(tp->tname[0] != '\0') { /* Someone logged off */
3970Sstevel@tonic-gate /* Set up and print ctmp record */
3980Sstevel@tonic-gate cb.ct_tty = tp->tdev;
3990Sstevel@tonic-gate CPYN(cb.ct_name, tp->tname);
4000Sstevel@tonic-gate cb.ct_uid = namtouid(cb.ct_name);
4010Sstevel@tonic-gate cb.ct_start = told;
4020Sstevel@tonic-gate if (pnpsplit(cb.ct_start, (ulong_t)(tnew-told),
4030Sstevel@tonic-gate cb.ct_con) == 0) {
4040Sstevel@tonic-gate fprintf(stderr, "acctcon1: could not calculate prime/non-prime hours\n");
4050Sstevel@tonic-gate exit(1);
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate prctmp(&cb);
4080Sstevel@tonic-gate tp->ttotal += tnew-told;
4090Sstevel@tonic-gate tp->tname[0] = '\0';
4100Sstevel@tonic-gate }
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate static void
printrep()4150Sstevel@tonic-gate printrep()
4160Sstevel@tonic-gate {
4170Sstevel@tonic-gate int i;
4180Sstevel@tonic-gate
4190Sstevel@tonic-gate freopen(report, "w", stdout);
4200Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &firstime);
4210Sstevel@tonic-gate printf("from %s", time_buf);
4220Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &lastime);
4230Sstevel@tonic-gate printf("to %s", time_buf);
4240Sstevel@tonic-gate if (ndates)
4250Sstevel@tonic-gate printf("%d\tdate change%c\n",ndates,(ndates>1 ? 's' : '\0'));
4260Sstevel@tonic-gate for (i = 0; i < nsys; i++)
4270Sstevel@tonic-gate printf("%d\t%.*s\n", sy[i].snum,
4280Sstevel@tonic-gate sizeof (sy[i].sname), sy[i].sname);
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate /*
4320Sstevel@tonic-gate * print summary of line usage
4330Sstevel@tonic-gate * accuracy only guaranteed for wtmpx file started fresh
4340Sstevel@tonic-gate */
4350Sstevel@tonic-gate static void
printlin()4360Sstevel@tonic-gate printlin()
4370Sstevel@tonic-gate {
4380Sstevel@tonic-gate struct tbuf *tp;
4390Sstevel@tonic-gate double timet, timei;
4400Sstevel@tonic-gate double ttime;
4410Sstevel@tonic-gate int tsess, ton, toff;
4420Sstevel@tonic-gate
4430Sstevel@tonic-gate freopen(replin, "w", stdout);
4440Sstevel@tonic-gate ttime = 0.0;
4450Sstevel@tonic-gate tsess = ton = toff = 0;
4460Sstevel@tonic-gate timet = MINS(lastime-firstime);
4470Sstevel@tonic-gate printf("TOTAL DURATION IS %.0f MINUTES\n", timet);
4480Sstevel@tonic-gate printf("LINE MINUTES PERCENT # SESS # ON # OFF\n");
4490Sstevel@tonic-gate for (tp = tbuf; tp <= &tbuf[tsize]; tp++) {
4500Sstevel@tonic-gate timei = MINS(tp->ttotal);
4510Sstevel@tonic-gate ttime += timei;
4520Sstevel@tonic-gate tsess += tp->tlsess;
4530Sstevel@tonic-gate ton += tp->tlon;
4540Sstevel@tonic-gate toff += tp->tloff;
4550Sstevel@tonic-gate printf("%-*.*s %-7.0f %-7.0f %-6d %-4d %-5d\n",
4560Sstevel@tonic-gate OUTPUT_LSZ,
4570Sstevel@tonic-gate OUTPUT_LSZ,
4580Sstevel@tonic-gate tp->tline,
4590Sstevel@tonic-gate timei,
4600Sstevel@tonic-gate (timet > 0.)? 100*timei/timet : 0.,
4610Sstevel@tonic-gate tp->tlsess,
4620Sstevel@tonic-gate tp->tlon,
4630Sstevel@tonic-gate tp->tloff);
4640Sstevel@tonic-gate }
4650Sstevel@tonic-gate printf("TOTALS %-7.0f -- %-6d %-4d %-5d\n",
4660Sstevel@tonic-gate ttime, tsess, ton, toff);
4670Sstevel@tonic-gate }
4680Sstevel@tonic-gate
4690Sstevel@tonic-gate static void
prctmp(struct ctmp * t)4700Sstevel@tonic-gate prctmp(struct ctmp *t)
4710Sstevel@tonic-gate {
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate printf("%u\t%ld\t%.*s\t%lu\t%lu\t%lu",
4740Sstevel@tonic-gate t->ct_tty,
4750Sstevel@tonic-gate t->ct_uid,
4760Sstevel@tonic-gate OUTPUT_NSZ,
4770Sstevel@tonic-gate t->ct_name,
4780Sstevel@tonic-gate t->ct_con[0],
4790Sstevel@tonic-gate t->ct_con[1],
4800Sstevel@tonic-gate t->ct_start);
4810Sstevel@tonic-gate cftime(time_buf, DATE_FMT, &t->ct_start);
4820Sstevel@tonic-gate printf("\t%s", time_buf);
4830Sstevel@tonic-gate }
484