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