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