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