xref: /titanic_52/usr/src/cmd/tip/aculib/dn11.c (revision 84ab085a13f931bc78e7415e7ce921dbaa14fcb3)
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 #ident	"%Z%%M%	%I%	%E% SMI"	/* from UCB 4.14 6/25/83 */
11 
12 /*
13  * Routines for dialing up on DN-11
14  */
15 #include "tip.h"
16 
17 int dn_abort();
18 void alarmtr();
19 static sigjmp_buf jmpbuf;
20 static int child = -1, dn;
21 
22 dn_dialer(num, acu)
23 	char *num, *acu;
24 {
25 	extern errno;
26 	char *p, *q, phone[40];
27 	int lt, nw, connected = 1;
28 	register int timelim;
29 	struct termios buf;
30 
31 	if (boolean(value(VERBOSE)))
32 		printf("\nstarting call...");
33 	if ((dn = open(acu, 1)) < 0) {
34 		if (errno == EBUSY)
35 			printf("line busy...");
36 		else
37 			printf("acu open error...");
38 		return (0);
39 	}
40 	if (sigsetjmp(jmpbuf, 1)) {
41 		kill(child, SIGKILL);
42 		close(dn);
43 		return (0);
44 	}
45 	signal(SIGALRM, alarmtr);
46 	timelim = 5 * strlen(num);
47 	alarm(timelim < 30 ? 30 : timelim);
48 	if ((child = fork()) == 0) {
49 		/*
50 		 * ignore this stuff for aborts
51 		 */
52 		signal(SIGALRM, SIG_IGN);
53 		signal(SIGINT, SIG_IGN);
54 		signal(SIGQUIT, SIG_IGN);
55 		sleep(2);
56 		nw = write(dn, num, lt = strlen(num));
57 		exit(nw != lt);
58 	}
59 	/*
60 	 * open line - will return on carrier
61 	 */
62 	if ((FD = open(DV, 2)) < 0) {
63 		if (errno == EIO)
64 			printf("lost carrier...");
65 		else
66 			printf("dialup line open failed...");
67 		alarm(0);
68 		kill(child, SIGKILL);
69 		close(dn);
70 		return (0);
71 	}
72 	alarm(0);
73 	ioctl(dn, TCGETS, &buf);
74 	buf.c_cflag |= HUPCL;
75 	ioctl(dn, TCSETSF, &buf);
76 	signal(SIGALRM, SIG_DFL);
77 	while ((nw = wait(&lt)) != child && nw != -1)
78 		;
79 	fflush(stdout);
80 	close(dn);
81 	if (lt != 0) {
82 		close(FD);
83 		return (0);
84 	}
85 	return (1);
86 }
87 
88 void
89 alarmtr()
90 {
91 
92 	alarm(0);
93 	siglongjmp(jmpbuf, 1);
94 }
95 
96 /*
97  * Insurance, for some reason we don't seem to be
98  *  hanging up...
99  */
100 dn_disconnect()
101 {
102 	int dtr = TIOCM_DTR;
103 
104 	sleep(2);
105 	if (FD > 0)
106 		ioctl(FD, TIOCMBIC, &dtr);
107 	close(FD);
108 }
109 
110 dn_abort()
111 {
112 	int dtr = TIOCM_DTR;
113 
114 	sleep(2);
115 	if (child > 0)
116 		kill(child, SIGKILL);
117 	if (dn > 0)
118 		close(dn);
119 	if (FD > 0)
120 		ioctl(FD, TIOCMBIC, &dtr);
121 	close(FD);
122 }
123