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