xref: /csrg-svn/usr.bin/tip/aculib/dn11.c (revision 42770)
119817Sdist /*
235492Sbostic  * Copyright (c) 1983 The Regents of the University of California.
335492Sbostic  * All rights reserved.
435492Sbostic  *
5*42770Sbostic  * %sccs.include.redist.c%
619817Sdist  */
719817Sdist 
813278Ssam #ifndef lint
9*42770Sbostic static char sccsid[] = "@(#)dn11.c	5.3 (Berkeley) 06/01/90";
1035492Sbostic #endif /* not lint */
113897Ssam 
123691Sroot /*
133691Sroot  * Routines for dialing up on DN-11
143691Sroot  */
153691Sroot #include "tip.h"
163691Sroot 
1713278Ssam int dn_abort(), alarmtr();
183897Ssam static jmp_buf jmpbuf;
193909Ssam static int child = -1, dn;
203897Ssam 
213691Sroot dn_dialer(num, acu)
224962Ssam 	char *num, *acu;
233691Sroot {
243691Sroot 	extern errno;
253897Ssam 	char *p, *q, phone[40];
263909Ssam 	int lt, nw, connected = 1;
273897Ssam 	register int timelim;
283691Sroot 
293901Ssam 	if (boolean(value(VERBOSE)))
303901Ssam 		printf("\nstarting call...");
313691Sroot 	if ((dn = open(acu, 1)) < 0) {
324003Ssam 		if (errno == EBUSY)
333901Ssam 			printf("line busy...");
343897Ssam 		else
353901Ssam 			printf("acu open error...");
365134Ssam 		return (0);
373691Sroot 	}
383897Ssam 	if (setjmp(jmpbuf)) {
393897Ssam 		kill(child, SIGKILL);
403897Ssam 		close(dn);
415134Ssam 		return (0);
423691Sroot 	}
433897Ssam 	signal(SIGALRM, alarmtr);
443897Ssam 	timelim = 5 * strlen(num);
453897Ssam 	alarm(timelim < 30 ? 30 : timelim);
463897Ssam 	if ((child = fork()) == 0) {
473901Ssam 		/*
483901Ssam 		 * ignore this stuff for aborts
493901Ssam 		 */
503691Sroot 		signal(SIGALRM, SIG_IGN);
513901Ssam 		signal(SIGINT, SIG_IGN);
523901Ssam 		signal(SIGQUIT, SIG_IGN);
533897Ssam 		sleep(2);
543897Ssam 		nw = write(dn, num, lt = strlen(num));
554003Ssam 		exit(nw != lt);
563691Sroot 	}
573901Ssam 	/*
583901Ssam 	 * open line - will return on carrier
593901Ssam 	 */
604003Ssam 	if ((FD = open(DV, 2)) < 0) {
613897Ssam 		if (errno == EIO)
623897Ssam 			printf("lost carrier...");
633897Ssam 		else
643897Ssam 			printf("dialup line open failed...");
653897Ssam 		alarm(0);
663897Ssam 		kill(child, SIGKILL);
673897Ssam 		close(dn);
685134Ssam 		return (0);
693691Sroot 	}
704418Ssam 	alarm(0);
713897Ssam 	ioctl(dn, TIOCHPCL, 0);
723897Ssam 	signal(SIGALRM, SIG_DFL);
733897Ssam 	while ((nw = wait(&lt)) != child && nw != -1)
743691Sroot 		;
753897Ssam 	fflush(stdout);
764219Ssam 	close(dn);
773897Ssam 	if (lt != 0) {
783897Ssam 		close(FD);
795134Ssam 		return (0);
803897Ssam 	}
815134Ssam 	return (1);
823691Sroot }
833691Sroot 
843897Ssam alarmtr()
853897Ssam {
8613278Ssam 
873897Ssam 	alarm(0);
883897Ssam 	longjmp(jmpbuf, 1);
893897Ssam }
903691Sroot 
913897Ssam /*
923897Ssam  * Insurance, for some reason we don't seem to be
933897Ssam  *  hanging up...
943897Ssam  */
953897Ssam dn_disconnect()
963897Ssam {
9713278Ssam 
983901Ssam 	sleep(2);
993897Ssam 	if (FD > 0)
1003897Ssam 		ioctl(FD, TIOCCDTR, 0);
1013897Ssam 	close(FD);
1023897Ssam }
1033897Ssam 
1043897Ssam dn_abort()
1053897Ssam {
10613278Ssam 
1073901Ssam 	sleep(2);
1083909Ssam 	if (child > 0)
1093909Ssam 		kill(child, SIGKILL);
1103909Ssam 	if (dn > 0)
1113909Ssam 		close(dn);
1123897Ssam 	if (FD > 0)
1133897Ssam 		ioctl(FD, TIOCCDTR, 0);
1143897Ssam 	close(FD);
1153897Ssam }
116