8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lastcomm / lastcomm.c
blobc3b1fd6c22523387c665226495dced084c4817af
1 /*
2 * CDDL HEADER START
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.
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]
20 * CDDL HEADER END
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>
30 #include <limits.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <errno.h>
35 #include "lastcomm.h"
37 int
38 main(int argc, char *argv[])
40 int res;
41 int opt;
42 char *filename = NULL;
43 char buf[PATH_MAX];
44 ea_file_t ef;
45 int xflag = 0;
47 while ((opt = getopt(argc, argv, "f:x")) != EOF) {
48 switch (opt) {
49 case 'f':
50 filename = optarg;
51 break;
52 case 'x':
53 xflag = 1;
54 break;
55 default:
56 (void) fprintf(stderr,
57 gettext("Usage:\tlastcomm [-x] [-f filename]"
58 " [command] ... [user] ... [terminal] ...\n"));
59 exit(2);
63 if (xflag) {
65 * User wants to see extended accounting statistics.
67 if (filename) {
68 return (lc_exacct(filename, argc, argv, optind));
69 } else {
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));
74 return (1);
75 } else {
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
84 * accounting.
86 if (acctctl(AC_PROC | AC_FILE_GET, buf, PATH_MAX) < 0)
87 return (lc_pacct("/var/adm/pacct", argc, argv, optind));
88 else
89 return (lc_exacct(buf, argc, argv, optind));
90 } else {
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)
98 (void) ea_close(&ef);
100 if (res < 0)
101 return (lc_pacct(filename, argc, argv, optind));
102 else
103 return (lc_exacct(filename, argc, argv, optind));