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]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
34 * Streams Command strconf: display the configuration of the
35 * stream associated with stdin.
38 * or: strconf -m module
41 * strconf with no options lists the modules on the stream.
42 * -m module echos "yes" and returns 0 if the module is on the stream.
43 * echos "no" and returns 2 if not.
44 * -t lists only the topmost module. returns 0 if there is a
49 * 1 ERR_USAGE bad invocation
50 * 2 ERR_MODULE module not there
51 * 3 ERR_STDIN an ioctl on the stdin stream failed
52 * 4 ERR_MEM couldn't allocate memory
56 #include <sys/stropts.h>
62 #define USAGE "USAGE: %s [ -m module | -t ]\n"
67 #define ERR_USAGE 1 /* bad invocation */
68 #define ERR_MODULE 2 /* module not there */
69 #define ERR_STDIN 3 /* an ioctl on the stdin stream failed */
70 #define ERR_MEM 4 /* couldn't allocate memory */
72 #define NMODULES 16 /* "reasonable" # of modules on a stream */
73 /* (there can be more) */
74 #define MAXMODULES 2048 /* max # of modules */
76 static char *Cmd_namep
; /* how was it invoked? */
77 static int more_modules(struct str_list
*, int);
80 main(int argc
, char **argv
)
82 char *modp
; /* ptr to module name */
83 int i
; /* loop var & junk (what else?) */
84 boolean_t mod_present
; /* B_TRUE if -m module */
85 boolean_t topmost
; /* B_TRUE if -t */
86 struct str_mlist mlist
[NMODULES
]; /* modlist for strlist */
87 struct str_list strlist
; /* mods on stream */
93 mod_present
= topmost
= B_FALSE
;
94 strlist
.sl_nmods
= NMODULES
;
95 strlist
.sl_modlist
= mlist
;
101 while ((i
= getopt(argc
, argv
, OPTLIST
)) != -1) {
103 case 'm': /* module present ? */
105 mod_present
= B_TRUE
;
108 case 't': /* list topmost */
113 (void) fprintf(stderr
, USAGE
, Cmd_namep
);
119 (void) fprintf(stderr
, USAGE
, Cmd_namep
);
124 if (topmost
&& mod_present
) {
125 (void) fprintf(stderr
,
126 "%s: [-t] and [-m] options cannot be used together\n",
128 (void) fprintf(stderr
, USAGE
, Cmd_namep
);
133 * get number of modules on stream
134 * allocate more room if needed
136 if ((i
= ioctl(STDIN_FILENO
, I_LIST
, NULL
)) < 0) {
138 (void) fprintf(stderr
,
139 "%s: I_LIST ioctl failed\n", Cmd_namep
);
142 if (i
> strlist
.sl_nmods
)
143 if (more_modules(&strlist
, i
) != SUCCESS
)
147 * get list of modules on stream
149 strlist
.sl_nmods
= i
;
150 if (ioctl(STDIN_FILENO
, I_LIST
, &strlist
) < 0) {
152 (void) fprintf(stderr
, "%s: I_LIST ioctl failed\n", Cmd_namep
);
157 * list topmost module
160 if (strlist
.sl_nmods
>= 2) {
161 (void) puts(strlist
.sl_modlist
[0].l_name
);
168 * check if module is present
171 for (i
= 0; i
< strlist
.sl_nmods
; i
++) {
172 if (strncmp(modp
, strlist
.sl_modlist
[i
].l_name
,
183 * print names of all modules and topmost driver on stream
185 for (i
= 0; i
< strlist
.sl_nmods
; i
++)
186 (void) puts(strlist
.sl_modlist
[i
].l_name
);
191 * more_modules(listp, n) allocate space for 'n' modules in 'listp'
193 * returns: SUCCESS or FAILURE
197 more_modules(struct str_list
*listp
, int n
)
200 struct str_mlist
*modp
;
202 if (n
> MAXMODULES
) {
203 (void) fprintf(stderr
,
204 "%s: too many modules (%d) -- max is %d\n",
205 Cmd_namep
, n
, MAXMODULES
);
209 if ((modp
= calloc(n
, sizeof (struct str_mlist
))) == NULL
) {
211 (void) fprintf(stderr
,
212 "%s: failed to allocate space for module list\n",
217 for (i
= 0; i
< listp
->sl_nmods
; ++i
)
218 (void) strncpy(modp
[i
].l_name
, listp
->sl_modlist
[i
].l_name
,
221 listp
->sl_modlist
= modp
;