1 /* dn11.c 4.9 81/09/21 */ 2 3 #if DN11 4 /* 5 * Routines for dialing up on DN-11 6 */ 7 #include "tip.h" 8 #include <setjmp.h> 9 #include <errno.h> 10 11 int dn_abort(); 12 13 int alarmtr(); 14 15 static jmp_buf jmpbuf; 16 static int child = -1, dn; 17 18 dn_dialer(num, acu) 19 char *num, *acu; 20 { 21 extern errno; 22 char *p, *q, phone[40]; 23 int lt, nw, connected = 1; 24 register int timelim; 25 26 if (boolean(value(VERBOSE))) 27 printf("\nstarting call..."); 28 if ((dn = open(acu, 1)) < 0) { 29 if (errno == EBUSY) 30 printf("line busy..."); 31 else 32 printf("acu open error..."); 33 return(0); 34 } 35 if (setjmp(jmpbuf)) { 36 kill(child, SIGKILL); 37 close(dn); 38 return(0); 39 } 40 signal(SIGALRM, alarmtr); 41 timelim = 5 * strlen(num); 42 alarm(timelim < 30 ? 30 : timelim); 43 if ((child = fork()) == 0) { 44 /* 45 * ignore this stuff for aborts 46 */ 47 signal(SIGALRM, SIG_IGN); 48 signal(SIGINT, SIG_IGN); 49 signal(SIGQUIT, SIG_IGN); 50 #ifdef DEBUG 51 printf("child: sleep\n"); 52 #endif 53 sleep(2); 54 #ifdef DEBUG 55 printf("child: write\n"); 56 #endif 57 nw = write(dn, num, lt = strlen(num)); 58 #ifdef DEBUG 59 printf("child: write finished\n"); 60 #endif 61 exit(nw != lt); 62 } 63 /* 64 * open line - will return on carrier 65 */ 66 #ifdef DEBUG 67 printf("parent: child %d, open begin\n", child); 68 #endif 69 if ((FD = open(DV, 2)) < 0) { 70 if (errno == EIO) 71 printf("lost carrier..."); 72 else 73 printf("dialup line open failed..."); 74 alarm(0); 75 kill(child, SIGKILL); 76 close(dn); 77 return(0); 78 } 79 alarm(0); 80 #ifdef DEBUG 81 printf("parent: open finished\n"); 82 #endif 83 ioctl(dn, TIOCHPCL, 0); 84 signal(SIGALRM, SIG_DFL); 85 #ifdef DEBUG 86 printf("parent: wait for child\n"); 87 #endif 88 while ((nw = wait(<)) != child && nw != -1) 89 #ifdef DEBUG 90 printf("wait finds child with pid %d\n", nw) 91 #endif 92 ; 93 fflush(stdout); 94 close(dn); 95 if (lt != 0) { 96 close(FD); 97 return(0); 98 } 99 return(1); 100 } 101 102 alarmtr() 103 { 104 alarm(0); 105 longjmp(jmpbuf, 1); 106 } 107 108 /* 109 * Insurance, for some reason we don't seem to be 110 * hanging up... 111 */ 112 dn_disconnect() 113 { 114 sleep(2); 115 #ifdef VMUNIX 116 if (FD > 0) 117 ioctl(FD, TIOCCDTR, 0); 118 #endif 119 close(FD); 120 } 121 122 dn_abort() 123 { 124 sleep(2); 125 if (child > 0) 126 kill(child, SIGKILL); 127 if (dn > 0) 128 close(dn); 129 #ifdef VMUNIX 130 if (FD > 0) 131 ioctl(FD, TIOCCDTR, 0); 132 #endif 133 close(FD); 134 } 135 #endif 136