1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #include <utmpx.h> 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate static struct utmpx utdummy; /* dummy - used to get member sizes */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #define PACCT "/var/adm/pacct" 36*7c478bd9Sstevel@tonic-gate #define HOLFILE "/etc/acct/holidays" 37*7c478bd9Sstevel@tonic-gate #define NHOLIDAYS 200 /* max number of company holidays per year */ 38*7c478bd9Sstevel@tonic-gate #define NSYS 200 /* number of run state changes */ 39*7c478bd9Sstevel@tonic-gate #define NFILE 100 /* max number of files that acctmerg handles */ 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #ifdef uts 42*7c478bd9Sstevel@tonic-gate #define CSIZE 10001 43*7c478bd9Sstevel@tonic-gate #define MAXUSERS 5003 44*7c478bd9Sstevel@tonic-gate #define A_SSIZE 60001 /* max num of sessions in 1 acct run */ 45*7c478bd9Sstevel@tonic-gate #define A_TSIZE 10001 /* max num of line names in 1 acct run */ 46*7c478bd9Sstevel@tonic-gate #define A_USIZE 20001 /* max num of distinct login names in 1 acct run */ 47*7c478bd9Sstevel@tonic-gate #else 48*7c478bd9Sstevel@tonic-gate #define CSIZE 5001 49*7c478bd9Sstevel@tonic-gate #define MAXUSERS 3001 50*7c478bd9Sstevel@tonic-gate #define A_SSIZE 6001 /* max num of sessions in 1 acct run */ 51*7c478bd9Sstevel@tonic-gate #define A_TSIZE 1001 /* max num of line names in 1 acct run */ 52*7c478bd9Sstevel@tonic-gate #define A_USIZE 2001 /* max num of distinct login names in 1 acct run */ 53*7c478bd9Sstevel@tonic-gate #endif 54*7c478bd9Sstevel@tonic-gate #define TSIZE1 100 /* # distinct names, for speed only */ 55*7c478bd9Sstevel@tonic-gate #define USIZE1 100 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate #define MAXIGN 10 58*7c478bd9Sstevel@tonic-gate #define UNUSED -1 59*7c478bd9Sstevel@tonic-gate #define FAIL -1 60*7c478bd9Sstevel@tonic-gate #define SUCCEED 0 61*7c478bd9Sstevel@tonic-gate #define TRUE 1 62*7c478bd9Sstevel@tonic-gate #define FALSE 0 63*7c478bd9Sstevel@tonic-gate #define PRIME 0 64*7c478bd9Sstevel@tonic-gate #define NONPRIME 1 65*7c478bd9Sstevel@tonic-gate #define MEANSIZE 01 66*7c478bd9Sstevel@tonic-gate #define KCOREMIN 02 67*7c478bd9Sstevel@tonic-gate #define HOGFACTOR 04 68*7c478bd9Sstevel@tonic-gate #define SEPTIME 010 69*7c478bd9Sstevel@tonic-gate #define CPUFACTOR 020 70*7c478bd9Sstevel@tonic-gate #define IORW 040 71*7c478bd9Sstevel@tonic-gate #define ROOT 0 72*7c478bd9Sstevel@tonic-gate #define ERR (-1) 73*7c478bd9Sstevel@tonic-gate #define OK 0 74*7c478bd9Sstevel@tonic-gate #define NOGOOD 1 75*7c478bd9Sstevel@tonic-gate #define VALID 0 76*7c478bd9Sstevel@tonic-gate #define INVALID 1 77*7c478bd9Sstevel@tonic-gate /* 78*7c478bd9Sstevel@tonic-gate * The size of LSZ is based on MAX_SRCH_DEPTH because of the 79*7c478bd9Sstevel@tonic-gate * implementation of devtolin() 80*7c478bd9Sstevel@tonic-gate */ 81*7c478bd9Sstevel@tonic-gate #define MAX_SRCH_DEPTH 4 82*7c478bd9Sstevel@tonic-gate #define LSZ (MAX_SRCH_DEPTH * sizeof (utdummy.ut_line)) 83*7c478bd9Sstevel@tonic-gate #define MAX_DEV_PATH (LSZ + 5) /* max len of abs line name path */ 84*7c478bd9Sstevel@tonic-gate #define NSZ (sizeof (utdummy.ut_name)) /* sizeof login name */ 85*7c478bd9Sstevel@tonic-gate #define LINESZ (sizeof (utdummy.ut_line)) /* sizeof device name */ 86*7c478bd9Sstevel@tonic-gate /* 87*7c478bd9Sstevel@tonic-gate * These exist for backward compatibility. Until we can change the 88*7c478bd9Sstevel@tonic-gate * output formats, we need to keep the field widths the same as 89*7c478bd9Sstevel@tonic-gate * they always have been. 90*7c478bd9Sstevel@tonic-gate */ 91*7c478bd9Sstevel@tonic-gate #define OUTPUT_NSZ 8 92*7c478bd9Sstevel@tonic-gate #define OUTPUT_LSZ 12 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate #define MYKIND(flag) ((flag & ACCTF) == 0) 95*7c478bd9Sstevel@tonic-gate #define SU(flag) ((flag & ASU) == ASU) 96*7c478bd9Sstevel@tonic-gate #define TOTAL(a) (a[PRIME] + a[NONPRIME]) 97*7c478bd9Sstevel@tonic-gate #define okay(time) ((time/100>=0) && (time/100<=24) \ 98*7c478bd9Sstevel@tonic-gate && (time%100>=0) && (time%100<60)) 99*7c478bd9Sstevel@tonic-gate #define pf(dble) fprintf(stdout, " %7.2lf", dble) 100*7c478bd9Sstevel@tonic-gate #define ps(s) fprintf(stdout, "%8.8s", s) 101*7c478bd9Sstevel@tonic-gate #define diag(string) fprintf(stderr, "\t%s\n", string) 102*7c478bd9Sstevel@tonic-gate #define DATE_FMT "%a %b %e %H:%M:%S %Y\n" 103*7c478bd9Sstevel@tonic-gate #define DATE_FMT1 " %H:%M:%S" 104*7c478bd9Sstevel@tonic-gate #define CBEMPTY (ctab[i].ct_sess == 0) 105*7c478bd9Sstevel@tonic-gate #define UBEMPTY (ub[i].ut_pc == 0 && ub[i].ut_cpu[0] == 0 && \ 106*7c478bd9Sstevel@tonic-gate ub[i].ut_cpu[1] == 0 && ub[i].ut_kcore[0] ==0 && ub[i].ut_kcore[1] == 0) 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate #define EQN(s1, s2) (strncmp(s1, s2, sizeof(s1)) == 0) 110*7c478bd9Sstevel@tonic-gate #define CPYN(s1, s2) (void) strncpy(s1, s2 ? s2 : "", sizeof(s1)) 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate #define SECSINDAY 86400L 113*7c478bd9Sstevel@tonic-gate #define SECS(tics) ((double) tics)/HZ 114*7c478bd9Sstevel@tonic-gate #define MINS(secs) ((double) secs)/60 115*7c478bd9Sstevel@tonic-gate #define MINT(tics) ((double) tics)/(60*HZ) 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate #include <unistd.h> 118*7c478bd9Sstevel@tonic-gate #if UTS 119*7c478bd9Sstevel@tonic-gate #define KCORE(clicks) ((double) BSIZE * (clicks/1024.0)) 120*7c478bd9Sstevel@tonic-gate #else 121*7c478bd9Sstevel@tonic-gate #define KCORE(clicks) ((double) (sysconf(_SC_PAGESIZE) >> 10) *clicks) 122*7c478bd9Sstevel@tonic-gate #endif 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /* 125*7c478bd9Sstevel@tonic-gate * total accounting (for acct period), also for day 126*7c478bd9Sstevel@tonic-gate */ 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate struct tacct { 129*7c478bd9Sstevel@tonic-gate uid_t ta_uid; /* userid */ 130*7c478bd9Sstevel@tonic-gate char ta_name[NSZ]; /* login name */ 131*7c478bd9Sstevel@tonic-gate float ta_cpu[2]; /* cum. cpu time, p/np (mins) */ 132*7c478bd9Sstevel@tonic-gate float ta_kcore[2]; /* cum kcore-minutes, p/np */ 133*7c478bd9Sstevel@tonic-gate float ta_con[2]; /* cum. connect time, p/np, mins */ 134*7c478bd9Sstevel@tonic-gate float ta_du; /* cum. disk usage */ 135*7c478bd9Sstevel@tonic-gate long ta_pc; /* count of processes */ 136*7c478bd9Sstevel@tonic-gate unsigned short ta_sc; /* count of login sessions */ 137*7c478bd9Sstevel@tonic-gate unsigned short ta_dc; /* count of disk samples */ 138*7c478bd9Sstevel@tonic-gate unsigned short ta_fee; /* fee for special services */ 139*7c478bd9Sstevel@tonic-gate }; 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate /* 143*7c478bd9Sstevel@tonic-gate * connect time record 144*7c478bd9Sstevel@tonic-gate */ 145*7c478bd9Sstevel@tonic-gate struct ctmp { 146*7c478bd9Sstevel@tonic-gate dev_t ct_tty; /* major minor */ 147*7c478bd9Sstevel@tonic-gate uid_t ct_uid; /* userid */ 148*7c478bd9Sstevel@tonic-gate char ct_name[NSZ]; /* login name */ 149*7c478bd9Sstevel@tonic-gate long ct_con[2]; /* connect time (p/np) secs */ 150*7c478bd9Sstevel@tonic-gate time_t ct_start; /* session start time */ 151*7c478bd9Sstevel@tonic-gate }; 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate /* 154*7c478bd9Sstevel@tonic-gate * per process temporary data 155*7c478bd9Sstevel@tonic-gate */ 156*7c478bd9Sstevel@tonic-gate struct ptmp { 157*7c478bd9Sstevel@tonic-gate uid_t pt_uid; /* userid */ 158*7c478bd9Sstevel@tonic-gate char pt_name[NSZ]; /* login name */ 159*7c478bd9Sstevel@tonic-gate ulong_t pt_cpu[2]; /* CPU (sys+usr) P/NP time tics */ 160*7c478bd9Sstevel@tonic-gate unsigned pt_mem; /* avg. memory size (64byte clicks) */ 161*7c478bd9Sstevel@tonic-gate }; 162