xref: /titanic_52/usr/src/cmd/tip/aculib/dn11.c (revision ba4e3c84e6b9390bbf7df80b5f1d11dec34cc525)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1983 Regents of the University of California.
8  * All rights reserved. The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 /*
15  * Routines for dialing up on DN-11
16  */
17 #include "tip.h"
18 
19 void	alarmtr(void);
20 
21 static sigjmp_buf	jmpbuf;
22 static int	child = -1, dn;
23 
24 int
25 dn_dialer(char *num, char *acu)
26 {
27 	int lt, nw;
28 	int timelim;
29 	struct termios buf;
30 
31 	if (boolean(value(VERBOSE)))
32 		(void) printf("\nstarting call...");
33 	if ((dn = open(acu, 1)) < 0) {
34 		if (errno == EBUSY)
35 			(void) printf("line busy...");
36 		else
37 			(void) printf("acu open error...");
38 		return (0);
39 	}
40 	if (sigsetjmp(jmpbuf, 1)) {
41 		(void) kill(child, SIGKILL);
42 		(void) close(dn);
43 		return (0);
44 	}
45 	(void) signal(SIGALRM, (sig_handler_t)alarmtr);
46 	timelim = 5 * strlen(num);
47 	(void) alarm(timelim < 30 ? 30 : timelim);
48 	if ((child = fork()) == 0) {
49 		/*
50 		 * ignore this stuff for aborts
51 		 */
52 		(void) signal(SIGALRM, SIG_IGN);
53 		(void) signal(SIGINT, SIG_IGN);
54 		(void) signal(SIGQUIT, SIG_IGN);
55 		(void) 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 			(void) printf("lost carrier...");
65 		else
66 			(void) printf("dialup line open failed...");
67 		(void) alarm(0);
68 		(void) kill(child, SIGKILL);
69 		(void) close(dn);
70 		return (0);
71 	}
72 	(void) alarm(0);
73 	(void) ioctl(dn, TCGETS, &buf);
74 	buf.c_cflag |= HUPCL;
75 	(void) ioctl(dn, TCSETSF, &buf);
76 	(void) signal(SIGALRM, SIG_DFL);
77 	while ((nw = wait(&lt)) != child && nw != -1)
78 		;
79 	(void) fflush(stdout);
80 	(void) close(dn);
81 	if (lt != 0) {
82 		(void) close(FD);
83 		return (0);
84 	}
85 	return (1);
86 }
87 
88 void
89 alarmtr(void)
90 {
91 
92 	(void) 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 void
101 dn_disconnect(void)
102 {
103 	int dtr = TIOCM_DTR;
104 
105 	(void) sleep(2);
106 	if (FD > 0)
107 		(void) ioctl(FD, TIOCMBIC, &dtr);
108 	(void) close(FD);
109 }
110 
111 void
112 dn_abort(void)
113 {
114 	int dtr = TIOCM_DTR;
115 
116 	(void) sleep(2);
117 	if (child > 0)
118 		(void) kill(child, SIGKILL);
119 	if (dn > 0)
120 		(void) close(dn);
121 	if (FD > 0)
122 		(void) ioctl(FD, TIOCMBIC, &dtr);
123 	(void) close(FD);
124 }
125