xref: /csrg-svn/usr.bin/tip/aculib/dn11.c (revision 13278)
1*13278Ssam #ifndef lint
2*13278Ssam static char sccsid[] = "@(#)dn11.c	4.13 (Berkeley) 06/25/83";
3*13278Ssam #endif
43897Ssam 
53897Ssam #if DN11
63691Sroot /*
73691Sroot  * Routines for dialing up on DN-11
83691Sroot  */
93691Sroot #include "tip.h"
103691Sroot 
11*13278Ssam int dn_abort(), alarmtr();
123897Ssam static jmp_buf jmpbuf;
133909Ssam static int child = -1, dn;
143897Ssam 
153691Sroot dn_dialer(num, acu)
164962Ssam 	char *num, *acu;
173691Sroot {
183691Sroot 	extern errno;
193897Ssam 	char *p, *q, phone[40];
203909Ssam 	int lt, nw, connected = 1;
213897Ssam 	register int timelim;
223691Sroot 
233901Ssam 	if (boolean(value(VERBOSE)))
243901Ssam 		printf("\nstarting call...");
253691Sroot 	if ((dn = open(acu, 1)) < 0) {
264003Ssam 		if (errno == EBUSY)
273901Ssam 			printf("line busy...");
283897Ssam 		else
293901Ssam 			printf("acu open error...");
305134Ssam 		return (0);
313691Sroot 	}
323897Ssam 	if (setjmp(jmpbuf)) {
333897Ssam 		kill(child, SIGKILL);
343897Ssam 		close(dn);
355134Ssam 		return (0);
363691Sroot 	}
373897Ssam 	signal(SIGALRM, alarmtr);
383897Ssam 	timelim = 5 * strlen(num);
393897Ssam 	alarm(timelim < 30 ? 30 : timelim);
403897Ssam 	if ((child = fork()) == 0) {
413901Ssam 		/*
423901Ssam 		 * ignore this stuff for aborts
433901Ssam 		 */
443691Sroot 		signal(SIGALRM, SIG_IGN);
453901Ssam 		signal(SIGINT, SIG_IGN);
463901Ssam 		signal(SIGQUIT, SIG_IGN);
473897Ssam 		sleep(2);
483897Ssam 		nw = write(dn, num, lt = strlen(num));
494003Ssam 		exit(nw != lt);
503691Sroot 	}
513901Ssam 	/*
523901Ssam 	 * open line - will return on carrier
533901Ssam 	 */
544003Ssam 	if ((FD = open(DV, 2)) < 0) {
553897Ssam 		if (errno == EIO)
563897Ssam 			printf("lost carrier...");
573897Ssam 		else
583897Ssam 			printf("dialup line open failed...");
593897Ssam 		alarm(0);
603897Ssam 		kill(child, SIGKILL);
613897Ssam 		close(dn);
625134Ssam 		return (0);
633691Sroot 	}
644418Ssam 	alarm(0);
653897Ssam 	ioctl(dn, TIOCHPCL, 0);
663897Ssam 	signal(SIGALRM, SIG_DFL);
673897Ssam 	while ((nw = wait(&lt)) != child && nw != -1)
683691Sroot 		;
693897Ssam 	fflush(stdout);
704219Ssam 	close(dn);
713897Ssam 	if (lt != 0) {
723897Ssam 		close(FD);
735134Ssam 		return (0);
743897Ssam 	}
755134Ssam 	return (1);
763691Sroot }
773691Sroot 
783897Ssam alarmtr()
793897Ssam {
80*13278Ssam 
813897Ssam 	alarm(0);
823897Ssam 	longjmp(jmpbuf, 1);
833897Ssam }
843691Sroot 
853897Ssam /*
863897Ssam  * Insurance, for some reason we don't seem to be
873897Ssam  *  hanging up...
883897Ssam  */
893897Ssam dn_disconnect()
903897Ssam {
91*13278Ssam 
923901Ssam 	sleep(2);
933897Ssam 	if (FD > 0)
943897Ssam 		ioctl(FD, TIOCCDTR, 0);
953897Ssam 	close(FD);
963897Ssam }
973897Ssam 
983897Ssam dn_abort()
993897Ssam {
100*13278Ssam 
1013901Ssam 	sleep(2);
1023909Ssam 	if (child > 0)
1033909Ssam 		kill(child, SIGKILL);
1043909Ssam 	if (dn > 0)
1053909Ssam 		close(dn);
1063897Ssam 	if (FD > 0)
1073897Ssam 		ioctl(FD, TIOCCDTR, 0);
1083897Ssam 	close(FD);
1093897Ssam }
1103897Ssam #endif
111