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 (c) 1983-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/acctctl.h>
38 main(int argc
, char *argv
[])
42 char *filename
= NULL
;
47 while ((opt
= getopt(argc
, argv
, "f:x")) != EOF
) {
56 (void) fprintf(stderr
,
57 gettext("Usage:\tlastcomm [-x] [-f filename]"
58 " [command] ... [user] ... [terminal] ...\n"));
65 * User wants to see extended accounting statistics.
68 return (lc_exacct(filename
, argc
, argv
, optind
));
70 if (acctctl(AC_PROC
| AC_FILE_GET
, buf
, PATH_MAX
) < 0) {
71 (void) fprintf(stderr
, gettext("lastcomm: "
72 "cannot open extended accounting file: "
73 "%s\n"), strerror(errno
));
76 return (lc_exacct(buf
, argc
, argv
, optind
));
80 if (filename
== NULL
) {
82 * If no option is specified, then first try to open current
83 * extended process accounting file and then old-style process
86 if (acctctl(AC_PROC
| AC_FILE_GET
, buf
, PATH_MAX
) < 0)
87 return (lc_pacct("/var/adm/pacct", argc
, argv
, optind
));
89 return (lc_exacct(buf
, argc
, argv
, optind
));
92 * If accounting file was specified and we don't know its
93 * format, then first try to open it as an extended accounting
94 * file and then as an old-style accounting file.
96 if ((res
= ea_open(&ef
, filename
, EXACCT_CREATOR
,
97 EO_TAIL
| EO_VALID_HDR
, O_RDONLY
, 0)) >= 0)
101 return (lc_pacct(filename
, argc
, argv
, optind
));
103 return (lc_exacct(filename
, argc
, argv
, optind
));