xref: /csrg-svn/usr.bin/tip/aculib/dn11.c (revision 4003)
1*4003Ssam /*	dn11.c	4.6	81/07/11	*/
23897Ssam 
33897Ssam #if DN11
43691Sroot /*
53691Sroot  * Routines for dialing up on DN-11
63691Sroot  */
73691Sroot #include "tip.h"
83897Ssam #include <setjmp.h>
93897Ssam #include <errno.h>
103691Sroot 
113691Sroot int dn_abort();
123691Sroot 
133897Ssam int alarmtr();
143897Ssam 
153897Ssam static jmp_buf jmpbuf;
163909Ssam static int child = -1, dn;
173897Ssam 
183691Sroot dn_dialer(num, acu)
193691Sroot char *num, *acu;
203691Sroot {
213691Sroot 	extern errno;
223897Ssam 	char *p, *q, phone[40];
233909Ssam 	int lt, nw, connected = 1;
243897Ssam 	register int timelim;
253691Sroot 
263901Ssam 	if (boolean(value(VERBOSE)))
273901Ssam 		printf("\nstarting call...");
283691Sroot 	if ((dn = open(acu, 1)) < 0) {
29*4003Ssam 		if (errno == EBUSY)
303901Ssam 			printf("line busy...");
313897Ssam 		else
323901Ssam 			printf("acu open error...");
333691Sroot 		return(0);
343691Sroot 	}
353897Ssam 	if (setjmp(jmpbuf)) {
363897Ssam 		kill(child, SIGKILL);
373897Ssam 		close(dn);
383691Sroot 		return(0);
393691Sroot 	}
403897Ssam 	signal(SIGALRM, alarmtr);
413897Ssam 	timelim = 5 * strlen(num);
423897Ssam 	alarm(timelim < 30 ? 30 : timelim);
433897Ssam 	if ((child = fork()) == 0) {
443901Ssam 		/*
453901Ssam 		 * ignore this stuff for aborts
463901Ssam 		 */
473691Sroot 		signal(SIGALRM, SIG_IGN);
483901Ssam 		signal(SIGINT, SIG_IGN);
493901Ssam 		signal(SIGQUIT, SIG_IGN);
503897Ssam 		sleep(2);
513897Ssam 		nw = write(dn, num, lt = strlen(num));
52*4003Ssam 		exit(nw != lt);
533691Sroot 	}
543901Ssam 	/*
553901Ssam 	 * open line - will return on carrier
563901Ssam 	 */
57*4003Ssam 	if ((FD = open(DV, 2)) < 0) {
583897Ssam 		if (errno == EIO)
593897Ssam 			printf("lost carrier...");
603897Ssam 		else
613897Ssam 			printf("dialup line open failed...");
623897Ssam 		alarm(0);
633897Ssam 		kill(child, SIGKILL);
643897Ssam 		close(dn);
653897Ssam 		return(0);
663691Sroot 	}
673897Ssam 	ioctl(dn, TIOCHPCL, 0);
683897Ssam 	signal(SIGALRM, SIG_DFL);
693897Ssam 	while ((nw = wait(&lt)) != child && nw != -1)
703691Sroot 		;
713691Sroot 	alarm(0);
723897Ssam 	fflush(stdout);
733897Ssam 	if (lt != 0) {
743897Ssam 		close(FD);
753897Ssam 		close(dn);
763897Ssam 		return(0);
773897Ssam 	}
783897Ssam 	return(1);
793691Sroot }
803691Sroot 
813897Ssam alarmtr()
823897Ssam {
833897Ssam 	alarm(0);
843897Ssam 	signal(SIGINT, SIG_IGN);
853897Ssam 	signal(SIGQUIT, SIG_IGN);
863897Ssam 	longjmp(jmpbuf, 1);
873897Ssam }
883691Sroot 
893897Ssam /*
903897Ssam  * Insurance, for some reason we don't seem to be
913897Ssam  *  hanging up...
923897Ssam  */
933897Ssam dn_disconnect()
943897Ssam {
953901Ssam 	sleep(2);
963897Ssam #ifdef VMUNIX
973897Ssam 	if (FD > 0)
983897Ssam 		ioctl(FD, TIOCCDTR, 0);
993691Sroot #endif
1003897Ssam 	close(FD);
1013897Ssam }
1023897Ssam 
1033897Ssam dn_abort()
1043897Ssam {
1053901Ssam 	sleep(2);
1063909Ssam 	if (child > 0)
1073909Ssam 		kill(child, SIGKILL);
1083909Ssam 	if (dn > 0)
1093909Ssam 		close(dn);
1103897Ssam #ifdef VMUNIX
1113897Ssam 	if (FD > 0)
1123897Ssam 		ioctl(FD, TIOCCDTR, 0);
1133897Ssam #endif
1143897Ssam 	close(FD);
1153897Ssam }
1163897Ssam #endif
117