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 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
38 #include <sys/types.h>
43 #include <sys/stropts.h>
49 #define NSTRPUSH 9 /* should agree with the tunable in */
50 /* /etc/master.d/kernel */
53 * check_device - check to see if the device exists,
54 * - and if it is a character device
55 * - return 0 if everything is ok. Otherwise, return -1
58 check_device(char *device
)
62 if ((device
== NULL
) || (*device
== '\0')) {
63 log("error -- device field is missing");
67 log("error -- must specify full path name for \"%s\".", device
);
70 if (access(device
, 0) == 0) {
71 if (stat(device
,&statbuf
) < 0) {
72 log("stat(%s) failed: %s", device
, strerror(errno
));
75 if ((statbuf
.st_mode
& S_IFMT
) != S_IFCHR
) {
76 log("error -- \"%s\" not character special device",
82 log("error -- device \"%s\" does not exist", device
);
89 * check_cmd - check to see if the cmd file exists,
90 * - and if it is executable
91 * - return 0 if everything is ok. Otherwise, return -1
100 if ((cmd
== NULL
) || (*cmd
== '\0')) {
101 log("error -- server command is missing");
104 (void)strcpy(tp
,cmd
);
105 (void)strtok(tp
, " \t");
107 log("error -- must specify full path name for \"%s\".", tp
);
110 if (access(tp
, 0) == 0) {
111 if (stat(tp
,&statbuf
) < 0) {
112 log("stat(%s) failed.", tp
);
115 if (!(statbuf
.st_mode
& 0111)) {
116 log("error -- \"%s\" not executable\n", tp
);
119 if ((statbuf
.st_mode
& S_IFMT
) != S_IFREG
) {
120 log("error -- \"%s\" not a regular file", tp
);
125 log("error -- \"%s\" does not exist", tp
);
132 * strcheck(sp, flag) - check string
133 * - if flag == ALNUM, all char. are expected to
135 * - if flag == NUM, all char. are expected to
136 * be digits and the number must be >= 0
137 * - return 0 if successful, -1 if failed.
141 char *sp
; /* string ptr */
142 int flag
; /* either NUM or ALNUM */
146 for (cp
= sp
; *cp
; cp
++) {
152 else { /* (flag == ALNUM) */
153 for (cp
= sp
; *cp
; cp
++) {
163 * vml(modules) - validate a list of modules
164 * - return 0 if successful, -1 if failed
172 struct str_mlist newmods
[NSTRPUSH
]; /* modlist for newlist */
173 struct str_list newlist
; /* modules to be pushed */
175 if ((modules
== NULL
) || (*modules
== '\0'))
178 newlist
.sl_modlist
= newmods
;
179 newlist
.sl_nmods
= NSTRPUSH
;
180 if ((modp
= malloc(strlen(modules
) + 1)) == NULL
) {
181 log("vml: malloc failed");
185 (void)strcpy(modp
, modules
);
187 * pull mod names out of comma-separated list
189 for ( i
= 0, modp
= strtok(modp
, ",");
190 modp
!= NULL
; i
++, modp
= strtok(NULL
, ",") ) {
191 if ( i
>= NSTRPUSH
) {
192 log("too many modules in <%s>", modules
);
196 (void)strncpy(newlist
.sl_modlist
[i
].l_name
,
198 newlist
.sl_modlist
[i
].l_name
[FMNAMESZ
] = '\0';
203 newlist
.sl_nmods
= i
;
206 * Is it a valid list of modules?
208 if ((fd
= open(USERDEV
, O_RDWR
)) == -1) {
209 if (errno
== EBUSY
) {
210 log("Warning - can't validate module list, /dev/sad/user busy");
213 log("open /dev/sad/user failed: %s", strerror(errno
));
216 if ( (i
= ioctl(fd
, SAD_VML
, &newlist
)) < 0 ) {
217 log("Validate modules ioctl failed, modules = <%s>: %s",
218 modules
, strerror(errno
));
223 log("Error - invalid STREAMS module list <%s>.", modules
);
232 * copystr(s1, s2) - copy string s2 to string s1
233 * - also put '\' in front of ':'
250 cons_printf(const char *fmt
, ...)
252 char buf
[MAXPATHLEN
* 2]; /* enough space for msg including a path */
257 (void) vsnprintf(buf
, sizeof (buf
), fmt
, ap
);
260 if ((fd
= open(CONSOLE
, O_WRONLY
|O_NOCTTY
)) != -1)
261 (void) write(fd
, buf
, strlen(buf
) + 1);