1 /* $NetBSD: dn11.c,v 1.3 1994/12/08 09:31:40 jtc Exp $ */ 2 3 /* 4 * Copyright (c) 1983, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)dn11.c 8.1 (Berkeley) 6/6/93"; 39 #endif 40 static char rcsid[] = "$NetBSD: dn11.c,v 1.3 1994/12/08 09:31:40 jtc Exp $"; 41 #endif /* not lint */ 42 43 /* 44 * Routines for dialing up on DN-11 45 */ 46 #include "tip.h" 47 48 int dn_abort(); 49 void alarmtr(); 50 static jmp_buf jmpbuf; 51 static int child = -1, dn; 52 53 dn_dialer(num, acu) 54 char *num, *acu; 55 { 56 extern errno; 57 char *p, *q, phone[40]; 58 int lt, nw, connected = 1; 59 register int timelim; 60 61 if (boolean(value(VERBOSE))) 62 printf("\nstarting call..."); 63 if ((dn = open(acu, 1)) < 0) { 64 if (errno == EBUSY) 65 printf("line busy..."); 66 else 67 printf("acu open error..."); 68 return (0); 69 } 70 if (setjmp(jmpbuf)) { 71 kill(child, SIGKILL); 72 close(dn); 73 return (0); 74 } 75 signal(SIGALRM, alarmtr); 76 timelim = 5 * strlen(num); 77 alarm(timelim < 30 ? 30 : timelim); 78 if ((child = fork()) == 0) { 79 /* 80 * ignore this stuff for aborts 81 */ 82 signal(SIGALRM, SIG_IGN); 83 signal(SIGINT, SIG_IGN); 84 signal(SIGQUIT, SIG_IGN); 85 sleep(2); 86 nw = write(dn, num, lt = strlen(num)); 87 exit(nw != lt); 88 } 89 /* 90 * open line - will return on carrier 91 */ 92 if ((FD = open(DV, 2)) < 0) { 93 if (errno == EIO) 94 printf("lost carrier..."); 95 else 96 printf("dialup line open failed..."); 97 alarm(0); 98 kill(child, SIGKILL); 99 close(dn); 100 return (0); 101 } 102 alarm(0); 103 ioctl(dn, TIOCHPCL, 0); 104 signal(SIGALRM, SIG_DFL); 105 while ((nw = wait(<)) != child && nw != -1) 106 ; 107 fflush(stdout); 108 close(dn); 109 if (lt != 0) { 110 close(FD); 111 return (0); 112 } 113 return (1); 114 } 115 116 void 117 alarmtr() 118 { 119 alarm(0); 120 longjmp(jmpbuf, 1); 121 } 122 123 /* 124 * Insurance, for some reason we don't seem to be 125 * hanging up... 126 */ 127 dn_disconnect() 128 { 129 130 sleep(2); 131 if (FD > 0) 132 ioctl(FD, TIOCCDTR, 0); 133 close(FD); 134 } 135 136 dn_abort() 137 { 138 139 sleep(2); 140 if (child > 0) 141 kill(child, SIGKILL); 142 if (dn > 0) 143 close(dn); 144 if (FD > 0) 145 ioctl(FD, TIOCCDTR, 0); 146 close(FD); 147 } 148