4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include "statcommon.h"
28 #include <sys/types.h>
32 #include <bsm/audit.h>
33 #include <bsm/libbsm.h>
37 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
38 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */
43 * Display header every HEADER_MOD lines printed
45 #define DFLT_HEADER_MOD (20)
58 static int header_mod
= DFLT_HEADER_MOD
;
60 static uint_t timestamp_fmt
= NODATE
;
62 static void display_stats();
63 static void eauditon();
64 static void parse_args();
65 static void usage_exit();
66 static int strisdigit();
76 (void) setlocale(LC_ALL
, "");
77 (void) textdomain(TEXT_DOMAIN
);
79 (void) setbuf(stdout
, (char *)0);
80 (void) setbuf(stderr
, (char *)0);
82 parse_args(argc
, argv
);
85 eauditon(A_GETSTAT
, (caddr_t
)&s
, NULL
);
86 if (timestamp_fmt
!= NODATE
)
87 print_timestamp(timestamp_fmt
);
92 if (flags
& VFLG
|| flags
& NFLG
)
93 eauditon(A_GETSTAT
, (caddr_t
)&s
, NULL
);
96 (void) printf("version = %d\n", s
.as_version
);
99 (void) printf("number of kernel events = %d\n", s
.as_numevent
);
106 eauditon(A_GETSTAT
, (caddr_t
)&s
, NULL
);
107 if (timestamp_fmt
!= NODATE
)
108 print_timestamp(timestamp_fmt
);
109 display_stats(&s
, i
);
110 if ((flags
& CFLG
) && count
)
113 (void) sleep(interval
);
121 display_stats(s
, cnt
)
124 int offset
[12]; /* used to line the header up correctly */
128 "%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u%n",
129 s
->as_generated
, &(offset
[0]),
130 s
->as_nonattrib
, &(offset
[1]),
131 s
->as_kernel
, &(offset
[2]),
132 s
->as_audit
, &(offset
[3]),
133 s
->as_auditctl
, &(offset
[4]),
134 s
->as_enqueue
, &(offset
[5]),
135 s
->as_written
, &(offset
[6]),
136 s
->as_wblocked
, &(offset
[7]),
137 s
->as_rblocked
, &(offset
[8]),
138 s
->as_dropped
, &(offset
[9]),
139 s
->as_totalsize
/ ONEK
, &(offset
[10]),
140 s
->as_memused
/ ONEK
, &(offset
[11]));
142 /* print a properly aligned header every HEADER_MOD lines */
143 if (header_mod
&& (!cnt
|| ((timestamp_fmt
!= NODATE
) ?
144 !(cnt
% (header_mod
/ 2)) : !(cnt
% header_mod
)))) {
146 "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n",
147 offset
[0] - 1, "gen",
148 offset
[1] - offset
[0] - 1, "nona",
149 offset
[2] - offset
[1] - 1, "kern",
150 offset
[3] - offset
[2] - 1, "aud",
151 offset
[4] - offset
[3] - 1, "ctl",
152 offset
[5] - offset
[4] - 1, "enq",
153 offset
[6] - offset
[5] - 1, "wrtn",
154 offset
[7] - offset
[6] - 1, "wblk",
155 offset
[8] - offset
[7] - 1, "rblk",
156 offset
[9] - offset
[8] - 1, "drop",
157 offset
[10] - offset
[9] - 1, "tot",
158 offset
[11] - offset
[10], "mem");
166 eauditon(cmd
, data
, length
)
171 if (auditon(cmd
, data
, length
) == -1) {
172 perror("auditstat: auditon");
179 parse_args(argc
, argv
)
185 while ((c
= getopt(argc
, argv
, "c:h:i:vnT:")) != -1) {
191 if (strisdigit(optarg
)) {
192 (void) fprintf(stderr
,
193 "auditstat: invalid count specified.\n");
196 count
= atoi(optarg
);
202 if (strisdigit(optarg
)) {
203 (void) fprintf(stderr
,
204 "auditstat: invalid header arg specified.\n");
207 header_mod
= atoi(optarg
);
213 if (strisdigit(optarg
)) {
214 (void) fprintf(stderr
,
215 "auditstat: invalid interval specified.\n");
218 interval
= atoi(optarg
);
233 timestamp_fmt
= UDATE
;
234 else if (*optarg
== 'd')
235 timestamp_fmt
= DDATE
;
254 (void) fprintf(stderr
,
255 "auditstat: usage: auditstat [-c count] [-h lines] "
256 "[-T d|u] [-i interval] [-n] [-v]\n");