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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/types.h>
47 char Comment
[SIZE
]; /* place holder for comments */
51 * nexttok - return next token, essentially a strtok, but it can
52 * deal with null fields and strtok can not
54 * args: str - the string to be examined, NULL if we should
55 * examine the remembered string
56 * delim - the list of valid delimiters
57 * ros - rest of string flag (1 for rest of string, 0 for
63 nexttok(str
, delim
, ros
)
68 static char *savep
; /* the remembered string */
69 register char *p
; /* pointer to start of token */
70 register char *ep
; /* pointer to end of token */
72 p
= (str
== NULL
) ? savep
: str
;
77 ep
= strpbrk(p
, delim
);
89 * parse - parse a line from _sactab. This routine will return if the parse
90 * was successful, otherwise it will output an error and exit.
92 * args: p - pointer to the data read from the file
93 * sp - pointer to a structure in which the separated fields
96 * A line in the file has the following format:
98 * tag:type:flags:restart_count:command_string #comment
105 register struct sactab
*sp
;
107 char scratch
[SIZE
]; /* a scratch buffer */
113 p
= nexttok(p
, DELIM
, FALSE
);
116 error(E_BADFILE
, EXIT
);
119 error("_sactab file is corrupt");
122 if (strlen(p
) > PMTAGSIZE
) {
125 (void) sprintf(scratch
, "tag too long, truncated to <%s>", p
);
128 (void) fprintf(stderr
, "tag too long, truncated to <%s>", p
);
131 (void) strcpy(sp
->sc_tag
, p
);
137 p
= nexttok(NULL
, DELIM
, FALSE
);
140 error(E_BADFILE
, EXIT
);
143 error("_sactab file is corrupt");
146 if (strlen(p
) > PMTYPESIZE
) {
147 p
[PMTYPESIZE
] = '\0';
149 (void) sprintf(scratch
, "type too long, truncated to <%s>", p
);
152 (void) fprintf(stderr
, "type too long, truncated to <%s>", p
);
155 (void) strcpy(sp
->sc_type
, p
);
161 p
= nexttok(NULL
, DELIM
, FALSE
);
164 error(E_BADFILE
, EXIT
);
167 error("_sactab file is corrupt");
174 sp
->sc_flags
|= D_FLAG
;
177 sp
->sc_flags
|= X_FLAG
;
180 (void) sprintf(scratch
, "Unrecognized flag <%c>", *(p
- 1));
192 * get the restart count
195 p
= nexttok(NULL
, DELIM
, FALSE
);
198 error(E_BADFILE
, EXIT
);
201 error("_sactab file is corrupt");
204 sp
->sc_rsmax
= atoi(p
);
207 * get the command string
210 p
= nexttok(NULL
, DELIM
, FALSE
);
213 error(E_BADFILE
, EXIT
);
216 error("_sactab file is corrupt");
219 if ((sp
->sc_cmd
= malloc((unsigned) (strlen(p
) + 1))) == NULL
) {
221 error(E_MALLOC
, EXIT
);
224 error("malloc failed");
227 (void) strcpy(sp
->sc_cmd
, p
);
230 * remember the comment string
233 if ((sp
->sc_comment
= malloc((unsigned) (strlen(Comment
) + 1))) == NULL
) {
235 error(E_MALLOC
, EXIT
);
238 error("malloc failed");
241 (void) strcpy(sp
->sc_comment
, Comment
);
246 * trim - remove comments, trim off trailing white space, done in place
247 * args: p - string to be acted upon
254 register char *tp
; /* temp pointer */
257 * remove comments, if any, but remember them for later
260 tp
= strchr(p
, COMMENT
);
263 (void) strcpy(Comment
, tp
+ 1); /* skip the '#' */
265 tp
= strchr(Comment
, '\n');
271 * remove trailing whitespace, if any
274 for (tp
= p
+ strlen(p
) - 1; tp
>= p
&& isspace(*tp
); --tp
)
281 * pstate - put port monitor state into intelligible form for output
282 * SSTATE is only used by sacadm
284 * args: state - binary representation of state
292 return("NOTRUNNING");
311 error(E_BADSTATE
, EXIT
);
314 error("Improper message from SAC\n");