xref: /titanic_50/usr/src/cmd/tip/cu.c (revision 108322fb1c3ed341aba9c80c9774df0ed9e35768)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1983 Regents of the University of California.
8  * All rights reserved.  The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 #include "tip.h"
15 
16 void	cleanup(void);
17 void	timeout(void);
18 
19 /*
20  * Botch the interface to look like cu's
21  */
22 void
23 cumain(int argc, char *argv[])
24 {
25 	int i;
26 	static char sbuf[12];
27 
28 	if (argc < 2) {
29 usage:
30 		(void) fprintf(stderr,
31 	"usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
32 		exit(8);
33 	}
34 	CU = DV = NOSTR;
35 	for (; argc > 1; argv++, argc--) {
36 		if (argv[1][0] != '-')
37 			PN = argv[1];
38 		else if (argv[1][1] != '\0' && argv[1][2] != '\0') {
39 			(void) fprintf(stderr,
40 			    "cu: extra characters after flag: %s\n",
41 			    argv[1]);
42 			goto usage;
43 		} else switch (argv[1][1]) {
44 
45 		case 't':
46 			HW = 1, DU = -1;
47 			--argc;
48 			continue;
49 
50 		case 'a':
51 			CU = argv[2]; ++argv; --argc;
52 			break;
53 
54 		case 's':
55 			if (argc < 3)
56 				goto usage;
57 			if (speed(atoi(argv[2])) == 0) {
58 				(void) fprintf(stderr,
59 				    "cu: unsupported speed %s\n",
60 				    argv[2]);
61 				exit(3);
62 			}
63 			BR = atoi(argv[2]); ++argv; --argc;
64 			break;
65 
66 		case 'l':
67 			DV = argv[2]; ++argv; --argc;
68 			break;
69 
70 		case '0': case '1': case '2': case '3': case '4':
71 		case '5': case '6': case '7': case '8': case '9':
72 			if (CU)
73 				CU[strlen(CU)-1] = argv[1][1];
74 			if (DV)
75 				DV[strlen(DV)-1] = argv[1][1];
76 			break;
77 
78 		default:
79 			(void) fprintf(stderr, "cu: bad flag %s\n", argv[1]);
80 			goto usage;
81 		}
82 	}
83 	(void) signal(SIGINT, (sig_handler_t)cleanup);
84 	(void) signal(SIGQUIT, (sig_handler_t)cleanup);
85 	(void) signal(SIGHUP, (sig_handler_t)cleanup);
86 	(void) signal(SIGTERM, (sig_handler_t)cleanup);
87 
88 	/*
89 	 * The "cu" host name is used to define the
90 	 * attributes of the generic dialer.
91 	 */
92 	(void) sprintf(sbuf, "cu%d", BR);
93 	if ((i = hunt(sbuf)) == 0) {
94 		(void) printf("all ports busy\n");
95 		exit(3);
96 	}
97 	if (i == -1) {
98 		(void) printf("link down\n");
99 		delock(uucplock);
100 		exit(3);
101 	}
102 	setbuf(stdout, NULL);
103 	loginit();
104 	gid = getgid();
105 	egid = getegid();
106 	uid = getuid();
107 	euid = geteuid();
108 	userperm();
109 	vinit();
110 	setparity("none");
111 	boolean(value(VERBOSE)) = 0;
112 	if (HW)
113 		ttysetup(speed(BR));
114 	if (connect()) {
115 		(void) printf("Connect failed\n");
116 		myperm();
117 		delock(uucplock);
118 		exit(1);
119 	}
120 	if (!HW)
121 		ttysetup(speed(BR));
122 }
123