119817Sdist /* 2*35492Sbostic * Copyright (c) 1983 The Regents of the University of California. 3*35492Sbostic * All rights reserved. 4*35492Sbostic * 5*35492Sbostic * Redistribution and use in source and binary forms are permitted 6*35492Sbostic * provided that the above copyright notice and this paragraph are 7*35492Sbostic * duplicated in all such forms and that any documentation, 8*35492Sbostic * advertising materials, and other materials related to such 9*35492Sbostic * distribution and use acknowledge that the software was developed 10*35492Sbostic * by the University of California, Berkeley. The name of the 11*35492Sbostic * University may not be used to endorse or promote products derived 12*35492Sbostic * from this software without specific prior written permission. 13*35492Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*35492Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*35492Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1619817Sdist */ 1719817Sdist 1813278Ssam #ifndef lint 19*35492Sbostic static char sccsid[] = "@(#)dn11.c 5.2 (Berkeley) 09/13/88"; 20*35492Sbostic #endif /* not lint */ 213897Ssam 223691Sroot /* 233691Sroot * Routines for dialing up on DN-11 243691Sroot */ 253691Sroot #include "tip.h" 263691Sroot 2713278Ssam int dn_abort(), alarmtr(); 283897Ssam static jmp_buf jmpbuf; 293909Ssam static int child = -1, dn; 303897Ssam 313691Sroot dn_dialer(num, acu) 324962Ssam char *num, *acu; 333691Sroot { 343691Sroot extern errno; 353897Ssam char *p, *q, phone[40]; 363909Ssam int lt, nw, connected = 1; 373897Ssam register int timelim; 383691Sroot 393901Ssam if (boolean(value(VERBOSE))) 403901Ssam printf("\nstarting call..."); 413691Sroot if ((dn = open(acu, 1)) < 0) { 424003Ssam if (errno == EBUSY) 433901Ssam printf("line busy..."); 443897Ssam else 453901Ssam printf("acu open error..."); 465134Ssam return (0); 473691Sroot } 483897Ssam if (setjmp(jmpbuf)) { 493897Ssam kill(child, SIGKILL); 503897Ssam close(dn); 515134Ssam return (0); 523691Sroot } 533897Ssam signal(SIGALRM, alarmtr); 543897Ssam timelim = 5 * strlen(num); 553897Ssam alarm(timelim < 30 ? 30 : timelim); 563897Ssam if ((child = fork()) == 0) { 573901Ssam /* 583901Ssam * ignore this stuff for aborts 593901Ssam */ 603691Sroot signal(SIGALRM, SIG_IGN); 613901Ssam signal(SIGINT, SIG_IGN); 623901Ssam signal(SIGQUIT, SIG_IGN); 633897Ssam sleep(2); 643897Ssam nw = write(dn, num, lt = strlen(num)); 654003Ssam exit(nw != lt); 663691Sroot } 673901Ssam /* 683901Ssam * open line - will return on carrier 693901Ssam */ 704003Ssam if ((FD = open(DV, 2)) < 0) { 713897Ssam if (errno == EIO) 723897Ssam printf("lost carrier..."); 733897Ssam else 743897Ssam printf("dialup line open failed..."); 753897Ssam alarm(0); 763897Ssam kill(child, SIGKILL); 773897Ssam close(dn); 785134Ssam return (0); 793691Sroot } 804418Ssam alarm(0); 813897Ssam ioctl(dn, TIOCHPCL, 0); 823897Ssam signal(SIGALRM, SIG_DFL); 833897Ssam while ((nw = wait(<)) != child && nw != -1) 843691Sroot ; 853897Ssam fflush(stdout); 864219Ssam close(dn); 873897Ssam if (lt != 0) { 883897Ssam close(FD); 895134Ssam return (0); 903897Ssam } 915134Ssam return (1); 923691Sroot } 933691Sroot 943897Ssam alarmtr() 953897Ssam { 9613278Ssam 973897Ssam alarm(0); 983897Ssam longjmp(jmpbuf, 1); 993897Ssam } 1003691Sroot 1013897Ssam /* 1023897Ssam * Insurance, for some reason we don't seem to be 1033897Ssam * hanging up... 1043897Ssam */ 1053897Ssam dn_disconnect() 1063897Ssam { 10713278Ssam 1083901Ssam sleep(2); 1093897Ssam if (FD > 0) 1103897Ssam ioctl(FD, TIOCCDTR, 0); 1113897Ssam close(FD); 1123897Ssam } 1133897Ssam 1143897Ssam dn_abort() 1153897Ssam { 11613278Ssam 1173901Ssam sleep(2); 1183909Ssam if (child > 0) 1193909Ssam kill(child, SIGKILL); 1203909Ssam if (dn > 0) 1213909Ssam close(dn); 1223897Ssam if (FD > 0) 1233897Ssam ioctl(FD, TIOCCDTR, 0); 1243897Ssam close(FD); 1253897Ssam } 126