xref: /csrg-svn/usr.bin/tip/aculib/dn11.c (revision 4418)
1*4418Ssam /*	dn11.c	4.9	81/09/21	*/
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) {
294003Ssam 		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);
50*4418Ssam #ifdef DEBUG
51*4418Ssam 		printf("child: sleep\n");
52*4418Ssam #endif
533897Ssam 		sleep(2);
54*4418Ssam #ifdef DEBUG
55*4418Ssam 		printf("child: write\n");
56*4418Ssam #endif
573897Ssam 		nw = write(dn, num, lt = strlen(num));
58*4418Ssam #ifdef DEBUG
59*4418Ssam 		printf("child: write finished\n");
60*4418Ssam #endif
614003Ssam 		exit(nw != lt);
623691Sroot 	}
633901Ssam 	/*
643901Ssam 	 * open line - will return on carrier
653901Ssam 	 */
66*4418Ssam #ifdef DEBUG
67*4418Ssam 	printf("parent: child %d, open begin\n", child);
68*4418Ssam #endif
694003Ssam 	if ((FD = open(DV, 2)) < 0) {
703897Ssam 		if (errno == EIO)
713897Ssam 			printf("lost carrier...");
723897Ssam 		else
733897Ssam 			printf("dialup line open failed...");
743897Ssam 		alarm(0);
753897Ssam 		kill(child, SIGKILL);
763897Ssam 		close(dn);
773897Ssam 		return(0);
783691Sroot 	}
79*4418Ssam 	alarm(0);
80*4418Ssam #ifdef DEBUG
81*4418Ssam 	printf("parent: open finished\n");
82*4418Ssam #endif
833897Ssam 	ioctl(dn, TIOCHPCL, 0);
843897Ssam 	signal(SIGALRM, SIG_DFL);
85*4418Ssam #ifdef DEBUG
86*4418Ssam 	printf("parent: wait for child\n");
87*4418Ssam #endif
883897Ssam 	while ((nw = wait(&lt)) != child && nw != -1)
89*4418Ssam #ifdef DEBUG
90*4418Ssam 		printf("wait finds child with pid %d\n", nw)
91*4418Ssam #endif
923691Sroot 		;
933897Ssam 	fflush(stdout);
944219Ssam 	close(dn);
953897Ssam 	if (lt != 0) {
963897Ssam 		close(FD);
973897Ssam 		return(0);
983897Ssam 	}
993897Ssam 	return(1);
1003691Sroot }
1013691Sroot 
1023897Ssam alarmtr()
1033897Ssam {
1043897Ssam 	alarm(0);
1053897Ssam 	longjmp(jmpbuf, 1);
1063897Ssam }
1073691Sroot 
1083897Ssam /*
1093897Ssam  * Insurance, for some reason we don't seem to be
1103897Ssam  *  hanging up...
1113897Ssam  */
1123897Ssam dn_disconnect()
1133897Ssam {
1143901Ssam 	sleep(2);
1153897Ssam #ifdef VMUNIX
1163897Ssam 	if (FD > 0)
1173897Ssam 		ioctl(FD, TIOCCDTR, 0);
1183691Sroot #endif
1193897Ssam 	close(FD);
1203897Ssam }
1213897Ssam 
1223897Ssam dn_abort()
1233897Ssam {
1243901Ssam 	sleep(2);
1253909Ssam 	if (child > 0)
1263909Ssam 		kill(child, SIGKILL);
1273909Ssam 	if (dn > 0)
1283909Ssam 		close(dn);
1293897Ssam #ifdef VMUNIX
1303897Ssam 	if (FD > 0)
1313897Ssam 		ioctl(FD, TIOCCDTR, 0);
1323897Ssam #endif
1333897Ssam 	close(FD);
1343897Ssam }
1353897Ssam #endif
136