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