xref: /openbsd-src/usr.sbin/sa/extern.h (revision de8cc8edbc71bd3e3bc7fbffa27ba0e564c37d8b)
1 /*	$OpenBSD: extern.h,v 1.6 2019/01/17 06:21:46 tedu Exp $ */
2 /*
3  * Copyright (c) 1994 Christopher G. Demetriou
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Christopher G. Demetriou.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 #include <sys/param.h>	/* MAXCOMLEN */
34 #include <db.h>
35 
36 /* structures */
37 
38 struct cmdinfo {
39 	char		ci_comm[MAXCOMLEN+2];	/* command name (+ '*') */
40 	uid_t		ci_uid;			/* user id */
41 	uint64_t	ci_calls;		/* number of calls */
42 	uint64_t	ci_etime;		/* elapsed time */
43 	uint64_t	ci_utime;		/* user time */
44 	uint64_t	ci_stime;		/* system time */
45 	uint64_t	ci_mem;			/* memory use */
46 	uint64_t	ci_io;			/* number of disk i/o ops */
47 	u_int		ci_flags;		/* flags; see below */
48 };
49 #define	CI_UNPRINTABLE	0x0001			/* unprintable chars in name */
50 
51 struct userinfo {
52 	uid_t		ui_uid;			/* user id; for consistency */
53 	uint64_t	ui_calls;		/* number of invocations */
54 	uint64_t	ui_utime;		/* user time */
55 	uint64_t	ui_stime;		/* system time */
56 	uint64_t	ui_mem;			/* memory use */
57 	uint64_t	ui_io;			/* number of disk i/o ops */
58 };
59 
60 /* typedefs */
61 
62 typedef	int (*cmpf_t)(const DBT *, const DBT *);
63 
64 /* external functions in sa.c */
65 int	main(int, char **);
66 
67 /* external functions in pdb.c */
68 int	pacct_init(void);
69 void	pacct_destroy(void);
70 int	pacct_add(const struct cmdinfo *);
71 int	pacct_update(void);
72 void	pacct_print(void);
73 
74 /* external functions in usrdb.c */
75 int	usracct_init(void);
76 void	usracct_destroy(void);
77 int	usracct_add(const struct cmdinfo *);
78 int	usracct_update(void);
79 void	usracct_print(void);
80 
81 /* variables */
82 
83 extern int	aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag;
84 extern int	Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag;
85 extern int	cutoff;
86 extern cmpf_t	sa_cmp;
87 
88 /* some #defines to help with db's stupidity */
89 
90 #define	DB_CLOSE(db) \
91 	((*(db)->close)(db))
92 #define	DB_GET(db, key, data, flags) \
93 	((*(db)->get)((db), (key), (data), (flags)))
94 #define	DB_PUT(db, key, data, flags) \
95 	((*(db)->put)((db), (key), (data), (flags)))
96 #define	DB_SYNC(db, flags) \
97 	((*(db)->sync)((db), (flags)))
98 #define	DB_SEQ(db, key, data, flags) \
99 	((*(db)->seq)((db), (key), (data), (flags)))
100