xref: /original-bsd/usr.bin/tip/aculib/dn11.c (revision 6c57d260)
1 /*	dn11.c	4.1	81/05/09	*/
2 /*
3  * Routines for dialing up on DN-11
4  */
5 #include "tip.h"
6 
7 int dn_abort();
8 
9 #if DN11
10 dn_dialer(num, acu)
11 char *num, *acu;
12 {
13 	extern errno;
14 	char *p, *q, b[30];
15 	int child = -1, dn, t, connected = 1;
16 
17 	if ((dn = open(acu, 1)) < 0) {
18 		if (errno == 6)
19 			printf("line busy\n");
20 		return(0);
21 	}
22 	if ((child = fork()) == -1) {
23 		printf("can't fork\n");
24 		return(0);
25 	}
26 	if (child == 0) {
27 		signal(SIGALRM, SIG_IGN);
28 		pause();
29 	}
30 	sleep(2);
31 	/*
32 	 * copy phone #, assure EON
33 	 */
34 	for (p = b, q = num; *p = *q; p++, q++)
35 		;
36 	if (*(p-1) != '<') {
37 		if (*(p-1) != '-')
38 			*p++ = '-';
39 		*p++ = '<';
40 	}
41 	close(FD);
42 	t = p-b;
43 	signal(SIGALRM, dn_abort);
44 	alarm(5*t);
45 	t = write(dn, b, t);
46 	alarm(0);
47 	if (t < 0) {
48 		printf("dn11 write error\n");
49 		connected = 0;
50 		goto error;
51 	}
52 	alarm(40);		/* was 5; sometimes missed carrier */
53 	FD = open(DV, 2);
54 	alarm(0);
55 	if (FD < 0) {
56 		if (errno == 4)
57 			printf("lost carrier\n");
58 		connected = 0;
59 		goto error;
60 	}
61 	ioctl(FD, TIOCEXCL, 0);
62 	ioctl(FD, TIOCHPCL, 0);
63 error:
64 	kill(child, SIGKILL);
65 	alarm(10);
66 	while ((t = wait((int *)NULL)) != -1 && t != child)
67 		;
68 	alarm(0);
69 	signal(SIGALRM, SIG_DFL);
70 	return(connected);
71 }
72 
73 dn_disconnect() { }
74 
75 dn_abort() { }
76 #endif
77