119817Sdist /* 235492Sbostic * Copyright (c) 1983 The Regents of the University of California. 335492Sbostic * All rights reserved. 435492Sbostic * 542770Sbostic * %sccs.include.redist.c% 619817Sdist */ 719817Sdist 813278Ssam #ifndef lint 9*46867Sbostic static char sccsid[] = "@(#)dn11.c 5.4 (Berkeley) 03/02/91"; 1035492Sbostic #endif /* not lint */ 113897Ssam 123691Sroot /* 133691Sroot * Routines for dialing up on DN-11 143691Sroot */ 153691Sroot #include "tip.h" 163691Sroot 17*46867Sbostic int dn_abort(); 18*46867Sbostic void alarmtr(); 193897Ssam static jmp_buf jmpbuf; 203909Ssam static int child = -1, dn; 213897Ssam 223691Sroot dn_dialer(num, acu) 234962Ssam char *num, *acu; 243691Sroot { 253691Sroot extern errno; 263897Ssam char *p, *q, phone[40]; 273909Ssam int lt, nw, connected = 1; 283897Ssam register int timelim; 293691Sroot 303901Ssam if (boolean(value(VERBOSE))) 313901Ssam printf("\nstarting call..."); 323691Sroot if ((dn = open(acu, 1)) < 0) { 334003Ssam if (errno == EBUSY) 343901Ssam printf("line busy..."); 353897Ssam else 363901Ssam printf("acu open error..."); 375134Ssam return (0); 383691Sroot } 393897Ssam if (setjmp(jmpbuf)) { 403897Ssam kill(child, SIGKILL); 413897Ssam close(dn); 425134Ssam return (0); 433691Sroot } 443897Ssam signal(SIGALRM, alarmtr); 453897Ssam timelim = 5 * strlen(num); 463897Ssam alarm(timelim < 30 ? 30 : timelim); 473897Ssam if ((child = fork()) == 0) { 483901Ssam /* 493901Ssam * ignore this stuff for aborts 503901Ssam */ 513691Sroot signal(SIGALRM, SIG_IGN); 523901Ssam signal(SIGINT, SIG_IGN); 533901Ssam signal(SIGQUIT, SIG_IGN); 543897Ssam sleep(2); 553897Ssam nw = write(dn, num, lt = strlen(num)); 564003Ssam exit(nw != lt); 573691Sroot } 583901Ssam /* 593901Ssam * open line - will return on carrier 603901Ssam */ 614003Ssam if ((FD = open(DV, 2)) < 0) { 623897Ssam if (errno == EIO) 633897Ssam printf("lost carrier..."); 643897Ssam else 653897Ssam printf("dialup line open failed..."); 663897Ssam alarm(0); 673897Ssam kill(child, SIGKILL); 683897Ssam close(dn); 695134Ssam return (0); 703691Sroot } 714418Ssam alarm(0); 723897Ssam ioctl(dn, TIOCHPCL, 0); 733897Ssam signal(SIGALRM, SIG_DFL); 743897Ssam while ((nw = wait(<)) != child && nw != -1) 753691Sroot ; 763897Ssam fflush(stdout); 774219Ssam close(dn); 783897Ssam if (lt != 0) { 793897Ssam close(FD); 805134Ssam return (0); 813897Ssam } 825134Ssam return (1); 833691Sroot } 843691Sroot 85*46867Sbostic void 863897Ssam alarmtr() 873897Ssam { 883897Ssam alarm(0); 893897Ssam longjmp(jmpbuf, 1); 903897Ssam } 913691Sroot 923897Ssam /* 933897Ssam * Insurance, for some reason we don't seem to be 943897Ssam * hanging up... 953897Ssam */ 963897Ssam dn_disconnect() 973897Ssam { 9813278Ssam 993901Ssam sleep(2); 1003897Ssam if (FD > 0) 1013897Ssam ioctl(FD, TIOCCDTR, 0); 1023897Ssam close(FD); 1033897Ssam } 1043897Ssam 1053897Ssam dn_abort() 1063897Ssam { 10713278Ssam 1083901Ssam sleep(2); 1093909Ssam if (child > 0) 1103909Ssam kill(child, SIGKILL); 1113909Ssam if (dn > 0) 1123909Ssam close(dn); 1133897Ssam if (FD > 0) 1143897Ssam ioctl(FD, TIOCCDTR, 0); 1153897Ssam close(FD); 1163897Ssam } 117