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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * wracct - write system accounting records
33 #include <sys/types.h>
34 #include <sys/procset.h>
42 #define CMDNAME "wracct"
44 gettext("Usage: wracct -i id_list [-t partial | interval ] " \
46 #define OPTIONS_STRING "i:t:"
51 (void) fprintf(stderr
, USAGE
);
61 l
= strtol(p
, &q
, 10);
62 if (errno
!= 0 || q
== p
|| l
< 0 || *q
!= '\0') {
63 (void) fprintf(stderr
, gettext("%s: illegal argument -- %s\n"),
73 main(int argc
, char *argv
[])
75 idtype_t ent_flag
= -1;
76 int rec_flag
= EW_PARTIAL
;
78 char *id_sequence
= NULL
;
82 while ((c
= getopt(argc
, argv
, OPTIONS_STRING
)) != EOF
) {
85 if (strcmp(optarg
, "partial") == 0) {
86 rec_flag
= EW_PARTIAL
;
87 } else if (strcmp(optarg
, "interval") == 0) {
88 rec_flag
= EW_INTERVAL
;
90 (void) fprintf(stderr
,
91 gettext("%s: wrong record type\n"),
97 id_sequence
= strdup(optarg
);
106 if (optind
>= argc
) {
110 if (strcmp(argv
[optind
], "task") == 0) {
112 } else if (strcmp(argv
[optind
], "process") == 0 ||
113 strcmp(argv
[optind
], "proc") == 0) {
119 if (ent_flag
== P_PID
&& rec_flag
== EW_INTERVAL
) {
120 (void) fprintf(stderr
,
121 gettext("%s: interval process records not supported\n"),
126 if (id_sequence
== NULL
) {
127 (void) fprintf(stderr
,
128 gettext("%s: please use -i option to specify ids\n"),
133 for (idlp
= strtok(id_sequence
, ", \t\n"); idlp
!= NULL
;
134 idlp
= strtok(NULL
, ", \t\n")) {
136 if (wracct(ent_flag
, id
, rec_flag
) < 0) {
138 (void) fprintf(stderr
,
139 "%s: operation failed on %s %d: %s\n",
140 CMDNAME
, (ent_flag
== P_TASKID
) ? "taskid" : "pid",
141 (int)id
, strerror(r
));