xref: /csrg-svn/usr.bin/tip/aculib/dn11.c (revision 19817)
1*19817Sdist /*
2*19817Sdist  * Copyright (c) 1983 Regents of the University of California.
3*19817Sdist  * All rights reserved.  The Berkeley software License Agreement
4*19817Sdist  * specifies the terms and conditions for redistribution.
5*19817Sdist  */
6*19817Sdist 
713278Ssam #ifndef lint
8*19817Sdist static char sccsid[] = "@(#)dn11.c	5.1 (Berkeley) 04/30/85";
9*19817Sdist #endif not lint
103897Ssam 
113691Sroot /*
123691Sroot  * Routines for dialing up on DN-11
133691Sroot  */
143691Sroot #include "tip.h"
153691Sroot 
1613278Ssam int dn_abort(), alarmtr();
173897Ssam static jmp_buf jmpbuf;
183909Ssam static int child = -1, dn;
193897Ssam 
203691Sroot dn_dialer(num, acu)
214962Ssam 	char *num, *acu;
223691Sroot {
233691Sroot 	extern errno;
243897Ssam 	char *p, *q, phone[40];
253909Ssam 	int lt, nw, connected = 1;
263897Ssam 	register int timelim;
273691Sroot 
283901Ssam 	if (boolean(value(VERBOSE)))
293901Ssam 		printf("\nstarting call...");
303691Sroot 	if ((dn = open(acu, 1)) < 0) {
314003Ssam 		if (errno == EBUSY)
323901Ssam 			printf("line busy...");
333897Ssam 		else
343901Ssam 			printf("acu open error...");
355134Ssam 		return (0);
363691Sroot 	}
373897Ssam 	if (setjmp(jmpbuf)) {
383897Ssam 		kill(child, SIGKILL);
393897Ssam 		close(dn);
405134Ssam 		return (0);
413691Sroot 	}
423897Ssam 	signal(SIGALRM, alarmtr);
433897Ssam 	timelim = 5 * strlen(num);
443897Ssam 	alarm(timelim < 30 ? 30 : timelim);
453897Ssam 	if ((child = fork()) == 0) {
463901Ssam 		/*
473901Ssam 		 * ignore this stuff for aborts
483901Ssam 		 */
493691Sroot 		signal(SIGALRM, SIG_IGN);
503901Ssam 		signal(SIGINT, SIG_IGN);
513901Ssam 		signal(SIGQUIT, SIG_IGN);
523897Ssam 		sleep(2);
533897Ssam 		nw = write(dn, num, lt = strlen(num));
544003Ssam 		exit(nw != lt);
553691Sroot 	}
563901Ssam 	/*
573901Ssam 	 * open line - will return on carrier
583901Ssam 	 */
594003Ssam 	if ((FD = open(DV, 2)) < 0) {
603897Ssam 		if (errno == EIO)
613897Ssam 			printf("lost carrier...");
623897Ssam 		else
633897Ssam 			printf("dialup line open failed...");
643897Ssam 		alarm(0);
653897Ssam 		kill(child, SIGKILL);
663897Ssam 		close(dn);
675134Ssam 		return (0);
683691Sroot 	}
694418Ssam 	alarm(0);
703897Ssam 	ioctl(dn, TIOCHPCL, 0);
713897Ssam 	signal(SIGALRM, SIG_DFL);
723897Ssam 	while ((nw = wait(&lt)) != child && nw != -1)
733691Sroot 		;
743897Ssam 	fflush(stdout);
754219Ssam 	close(dn);
763897Ssam 	if (lt != 0) {
773897Ssam 		close(FD);
785134Ssam 		return (0);
793897Ssam 	}
805134Ssam 	return (1);
813691Sroot }
823691Sroot 
833897Ssam alarmtr()
843897Ssam {
8513278Ssam 
863897Ssam 	alarm(0);
873897Ssam 	longjmp(jmpbuf, 1);
883897Ssam }
893691Sroot 
903897Ssam /*
913897Ssam  * Insurance, for some reason we don't seem to be
923897Ssam  *  hanging up...
933897Ssam  */
943897Ssam dn_disconnect()
953897Ssam {
9613278Ssam 
973901Ssam 	sleep(2);
983897Ssam 	if (FD > 0)
993897Ssam 		ioctl(FD, TIOCCDTR, 0);
1003897Ssam 	close(FD);
1013897Ssam }
1023897Ssam 
1033897Ssam dn_abort()
1043897Ssam {
10513278Ssam 
1063901Ssam 	sleep(2);
1073909Ssam 	if (child > 0)
1083909Ssam 		kill(child, SIGKILL);
1093909Ssam 	if (dn > 0)
1103909Ssam 		close(dn);
1113897Ssam 	if (FD > 0)
1123897Ssam 		ioctl(FD, TIOCCDTR, 0);
1133897Ssam 	close(FD);
1143897Ssam }
115