xref: /original-bsd/usr.bin/tip/aculib/dn11.c (revision de38840f)
1 /*	dn11.c	4.6	81/07/11	*/
2 
3 #if DN11
4 /*
5  * Routines for dialing up on DN-11
6  */
7 #include "tip.h"
8 #include <setjmp.h>
9 #include <errno.h>
10 
11 int dn_abort();
12 
13 int alarmtr();
14 
15 static jmp_buf jmpbuf;
16 static int child = -1, dn;
17 
18 dn_dialer(num, acu)
19 char *num, *acu;
20 {
21 	extern errno;
22 	char *p, *q, phone[40];
23 	int lt, nw, connected = 1;
24 	register int timelim;
25 
26 	if (boolean(value(VERBOSE)))
27 		printf("\nstarting call...");
28 	if ((dn = open(acu, 1)) < 0) {
29 		if (errno == EBUSY)
30 			printf("line busy...");
31 		else
32 			printf("acu open error...");
33 		return(0);
34 	}
35 	if (setjmp(jmpbuf)) {
36 		kill(child, SIGKILL);
37 		close(dn);
38 		return(0);
39 	}
40 	signal(SIGALRM, alarmtr);
41 	timelim = 5 * strlen(num);
42 	alarm(timelim < 30 ? 30 : timelim);
43 	if ((child = fork()) == 0) {
44 		/*
45 		 * ignore this stuff for aborts
46 		 */
47 		signal(SIGALRM, SIG_IGN);
48 		signal(SIGINT, SIG_IGN);
49 		signal(SIGQUIT, SIG_IGN);
50 		sleep(2);
51 		nw = write(dn, num, lt = strlen(num));
52 		exit(nw != lt);
53 	}
54 	/*
55 	 * open line - will return on carrier
56 	 */
57 	if ((FD = open(DV, 2)) < 0) {
58 		if (errno == EIO)
59 			printf("lost carrier...");
60 		else
61 			printf("dialup line open failed...");
62 		alarm(0);
63 		kill(child, SIGKILL);
64 		close(dn);
65 		return(0);
66 	}
67 	ioctl(dn, TIOCHPCL, 0);
68 	signal(SIGALRM, SIG_DFL);
69 	while ((nw = wait(&lt)) != child && nw != -1)
70 		;
71 	alarm(0);
72 	fflush(stdout);
73 	if (lt != 0) {
74 		close(FD);
75 		close(dn);
76 		return(0);
77 	}
78 	return(1);
79 }
80 
81 alarmtr()
82 {
83 	alarm(0);
84 	signal(SIGINT, SIG_IGN);
85 	signal(SIGQUIT, SIG_IGN);
86 	longjmp(jmpbuf, 1);
87 }
88 
89 /*
90  * Insurance, for some reason we don't seem to be
91  *  hanging up...
92  */
93 dn_disconnect()
94 {
95 	sleep(2);
96 #ifdef VMUNIX
97 	if (FD > 0)
98 		ioctl(FD, TIOCCDTR, 0);
99 #endif
100 	close(FD);
101 }
102 
103 dn_abort()
104 {
105 	sleep(2);
106 	if (child > 0)
107 		kill(child, SIGKILL);
108 	if (dn > 0)
109 		close(dn);
110 #ifdef VMUNIX
111 	if (FD > 0)
112 		ioctl(FD, TIOCCDTR, 0);
113 #endif
114 	close(FD);
115 }
116 #endif
117