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.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/types.h>
45 * ttyadm - format ttymon specific information and
48 * Usage: ttyadm [options] -d device -s service -l ttylabel
66 static int check_label();
68 extern int check_device();
69 extern int check_cmd();
73 main(int argc
, char *argv
[])
75 int c
; /* option letter */
76 int errflg
= 0; /* error indicator */
83 char ttyflags
[BUFSIZ
], *tf
;
85 int dflag
= 0; /* -d seen */
86 int sflag
= 0; /* -s seen */
87 int lflag
= 0; /* -l seen */
88 int mflag
= 0; /* -m seen */
90 extern void copystr();
93 extern int strcheck();
97 if ((ptr
= ALLOC_PMTAB
) == PNULL
) {
98 (void)fprintf(stderr
, "calloc failed\n");
103 ptr
->p_termtype
= "";
105 ptr
->p_prompt
= "login\\: ";
108 while ((c
= getopt(argc
, argv
, "IT:S:Vd:s:chbr:t:l:m:p:i:")) != -1) {
111 if ((argc
> 2) || (optind
< argc
))
113 (void)fprintf(stdout
,"%d\n", PMTAB_VERS
);
115 break; /*NOTREACHED*/
117 ptr
->p_device
= optarg
;
135 if (strcheck(optarg
,NUM
) != 0) {
136 (void)fprintf(stderr
,
137 "Invalid argument for \"-r\" -- positive number expected.\n");
142 ptr
->p_termtype
= optarg
;
148 ptr
->p_softcar
= "y";
152 ptr
->p_softcar
= "n";
159 ptr
->p_server
= optarg
;
164 if (strcheck(optarg
,NUM
) != 0) {
165 (void)fprintf(stderr
,
166 "Invalid argument for \"-t\" -- positive number expected.\n");
171 ptr
->p_ttylabel
= optarg
;
175 ptr
->p_modules
= optarg
;
179 ptr
->p_prompt
= prompt
;
180 copystr(ptr
->p_prompt
,optarg
);
184 copystr(ptr
->p_dmsg
,optarg
);
194 if ((!dflag
) || (!sflag
) || (!lflag
))
197 if (check_device(ptr
->p_device
) != 0)
199 if (check_cmd(ptr
->p_server
) != 0)
201 if (check_label(ptr
->p_ttylabel
) != 0)
203 if (mflag
&& (vml(ptr
->p_modules
) != 0))
207 (void)fprintf(stdout
, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:",
208 ptr
->p_device
, ttyflags
, count
, ptr
->p_server
,
209 timeout
, ptr
->p_ttylabel
, ptr
->p_modules
,
210 ptr
->p_prompt
, ptr
->p_dmsg
, ptr
->p_termtype
,
216 * usage - print out a usage message
222 (void)fprintf(stderr
, "Usage:\tttyadm [ options ] -d device -s service -l ttylabel\n");
223 (void)fprintf(stderr
, "\tttyadm -V\n");
224 (void)fprintf(stderr
, "\n\tValid options are:\n");
225 (void)fprintf(stderr
, "\t-c\n");
226 (void)fprintf(stderr
, "\t-h\n");
227 (void)fprintf(stderr
, "\t-b\n");
228 (void)fprintf(stderr
, "\t-I\n");
229 (void)fprintf(stderr
, "\t-S y|n\n");
230 (void)fprintf(stderr
, "\t-T term\n");
231 (void)fprintf(stderr
, "\t-r count\n");
232 (void)fprintf(stderr
, "\t-t timeout\n");
233 (void)fprintf(stderr
, "\t-p prompt\n");
234 (void)fprintf(stderr
, "\t-m modules\n");
235 (void)fprintf(stderr
, "\t-i msg\n");
240 * check_label - if ttylabel exists in /etc/ttydefs, return 0
241 * - otherwise, return -1
245 check_label(ttylabel
)
249 extern int find_label();
251 if ((ttylabel
== NULL
) || (*ttylabel
== '\0')) {
252 (void)fprintf(stderr
, "error -- ttylabel is missing");
255 if ((fp
= fopen(TTYDEFS
, "r")) == NULL
) {
256 (void)fprintf(stderr
, "error -- \"%s\" does not exist, can't verify ttylabel <%s>\n", TTYDEFS
, ttylabel
);
259 if (find_label(fp
,ttylabel
)) {
264 (void)fprintf(stderr
,"error -- can't find ttylabel <%s> in \"%s\"\n",
270 * log - print a message to stderr
273 log(const char *msg
, ...)
277 (void) vfprintf(stderr
, msg
, ap
);
279 (void) fprintf(stderr
, "\n");