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 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
37 * listdgrp Writes on the standard output stream a list of devices
38 * that belong to the specified device group
41 #include <sys/types.h>
53 * TRUE Boolean TRUE value (if not already defined)
54 * FALSE Boolean not-TRUE value (if not already defined)
67 * M_USAGE Command usage error
68 * M_NODGRP Device group not found
69 * M_DGRPTAB Device-group table not found
70 * M_ERROR Internal error
73 #define M_USAGE "usage: listdgrp dgroup"
74 #define M_NODGRP "Device group not found: %s"
75 #define M_DGRPTAB "Cannot open device-group table: %s"
76 #define M_ERROR "Internal error, errno=%d"
81 * EX_OK Exiting okay, no problem
82 * EX_ERROR Some problem with the command
83 * EX_NODGRPTAB Device group table could not be opened
84 * EX_NODGROUP Device group couldn't be found
89 #define EX_NODGRPTAB 2
95 * stdmsg(r,l,s,t) Write a message in standard format
96 * r Recoverability flag
102 #define stdmsg(r,l,s,t) (void) fmtmsg(MM_PRINT|MM_UTIL|r,l,s,t,MM_NULLACT,MM_NULLTAG)
112 * lbl Buffer for the message label
115 static char lbl
[MM_MXLABELLN
+1];
116 static char msg
[MM_MXTXTLN
+1];
121 * List the devices that belong to the device group <dgroup>.
122 * It writes the list to the standard output file (stdout)
123 * in a new-line list.
127 * 1 Syntax or other error
128 * 2 Device table can't be opened
129 * 3 Device group doesn't exist
133 main(int argc
, char **argv
)
140 char **devices
; /* List of devices in the group */
141 char **pp
; /* Running pointer to device names */
142 char *cmdname
; /* Simple command name */
143 char *dgrptab
; /* The device-group table name */
144 char *dgroup
; /* Device group to list */
145 int exitcode
; /* Value to return to the caller */
146 int sev
; /* Message severity */
147 int optchar
; /* Option char (from getopt()) */
148 int usageerr
; /* TRUE if syntax error on command */
151 /* Build the message label from the (simple) command name */
152 if ((cmdname
= strrchr(argv
[0], '/')) != (char *) NULL
) cmdname
++;
153 else cmdname
= argv
[0];
154 (void) strlcat(strcpy(lbl
, "UX:"), cmdname
, sizeof(lbl
));
156 /* Only write the text component of a message (this goes away in SVR4.1) */
157 (void) putenv("MSGVERB=text");
160 * Parse the command line:
162 * - Device group to display
166 * Extract options from the command line
169 /* Initializations */
170 usageerr
= FALSE
; /* No errors on the command line (yet) */
173 * Loop until all of the command line options have been parced
174 * (and don't let getopt() write messages)
178 while ((optchar
= getopt(argc
, argv
, "")) != EOF
) switch (optchar
) {
180 /* Default case -- command usage error */
187 /* Check the argument count and extract the device group name */
188 if (usageerr
|| (optind
!= argc
-1)) usageerr
= TRUE
;
189 else dgroup
= argv
[optind
];
191 /* If there is a usage error, write an appropriate message and exit */
193 stdmsg(MM_NRECOV
, lbl
, MM_ERROR
, M_USAGE
);
197 /* Open the device-group file (if there's one to be opened) */
198 if (!_opendgrptab("r")) {
199 if (dgrptab
= _dgrptabpath()) {
200 (void) snprintf(msg
, sizeof(msg
), M_DGRPTAB
, dgrptab
);
201 exitcode
= EX_NODGRPTAB
;
204 (void) sprintf(msg
, M_ERROR
, errno
);
208 stdmsg(MM_NRECOV
, lbl
, sev
, msg
);
214 * Get the list of devices associated with the device group.
215 * If we get one, write the list to the standard output.
216 * Otherwise, write an appropriate error message
220 if (devices
= listdgrp(dgroup
)) {
221 for (pp
= devices
; *pp
; pp
++) (void) puts(*pp
);
224 if (errno
== EINVAL
) {
225 (void) snprintf(msg
, sizeof(msg
), M_NODGRP
, dgroup
);
226 stdmsg(MM_NRECOV
, lbl
, MM_ERROR
, msg
);
227 exitcode
= EX_NODGROUP
;
230 (void) sprintf(msg
, M_ERROR
, errno
);
231 stdmsg(MM_NRECOV
, lbl
, MM_HALT
, msg
);
236 /* Finished (now wasn't that special?) */