Add copyright
[unix-history] / usr / src / usr.bin / tip / aculib / dn11.c
CommitLineData
051b1e55
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
05862919 7#ifndef lint
051b1e55
DF
8static char sccsid[] = "@(#)dn11.c 5.1 (Berkeley) %G%";
9#endif not lint
f0211bf2 10
55e3be1a
BJ
11/*
12 * Routines for dialing up on DN-11
13 */
14#include "tip.h"
55e3be1a 15
05862919 16int dn_abort(), alarmtr();
f0211bf2 17static jmp_buf jmpbuf;
aaf8f928 18static int child = -1, dn;
f0211bf2 19
55e3be1a 20dn_dialer(num, acu)
d8feebc2 21 char *num, *acu;
55e3be1a
BJ
22{
23 extern errno;
f0211bf2 24 char *p, *q, phone[40];
aaf8f928 25 int lt, nw, connected = 1;
f0211bf2 26 register int timelim;
55e3be1a 27
c0ef382b
SL
28 if (boolean(value(VERBOSE)))
29 printf("\nstarting call...");
55e3be1a 30 if ((dn = open(acu, 1)) < 0) {
4b675d70 31 if (errno == EBUSY)
c0ef382b 32 printf("line busy...");
f0211bf2 33 else
c0ef382b 34 printf("acu open error...");
3f48242d 35 return (0);
55e3be1a 36 }
f0211bf2 37 if (setjmp(jmpbuf)) {
f0211bf2
SL
38 kill(child, SIGKILL);
39 close(dn);
3f48242d 40 return (0);
55e3be1a 41 }
f0211bf2
SL
42 signal(SIGALRM, alarmtr);
43 timelim = 5 * strlen(num);
44 alarm(timelim < 30 ? 30 : timelim);
45 if ((child = fork()) == 0) {
c0ef382b
SL
46 /*
47 * ignore this stuff for aborts
48 */
55e3be1a 49 signal(SIGALRM, SIG_IGN);
c0ef382b
SL
50 signal(SIGINT, SIG_IGN);
51 signal(SIGQUIT, SIG_IGN);
f0211bf2
SL
52 sleep(2);
53 nw = write(dn, num, lt = strlen(num));
4b675d70 54 exit(nw != lt);
55e3be1a 55 }
c0ef382b
SL
56 /*
57 * open line - will return on carrier
58 */
4b675d70 59 if ((FD = open(DV, 2)) < 0) {
f0211bf2
SL
60 if (errno == EIO)
61 printf("lost carrier...");
62 else
63 printf("dialup line open failed...");
64 alarm(0);
65 kill(child, SIGKILL);
66 close(dn);
3f48242d 67 return (0);
55e3be1a 68 }
6bab3ab7 69 alarm(0);
f0211bf2
SL
70 ioctl(dn, TIOCHPCL, 0);
71 signal(SIGALRM, SIG_DFL);
72 while ((nw = wait(&lt)) != child && nw != -1)
55e3be1a 73 ;
f0211bf2 74 fflush(stdout);
6680530a 75 close(dn);
f0211bf2
SL
76 if (lt != 0) {
77 close(FD);
3f48242d 78 return (0);
f0211bf2 79 }
3f48242d 80 return (1);
55e3be1a
BJ
81}
82
f0211bf2
SL
83alarmtr()
84{
05862919 85
f0211bf2 86 alarm(0);
f0211bf2
SL
87 longjmp(jmpbuf, 1);
88}
55e3be1a 89
f0211bf2
SL
90/*
91 * Insurance, for some reason we don't seem to be
92 * hanging up...
93 */
94dn_disconnect()
95{
05862919 96
c0ef382b 97 sleep(2);
f0211bf2
SL
98 if (FD > 0)
99 ioctl(FD, TIOCCDTR, 0);
f0211bf2
SL
100 close(FD);
101}
102
103dn_abort()
104{
05862919 105
c0ef382b 106 sleep(2);
aaf8f928
SL
107 if (child > 0)
108 kill(child, SIGKILL);
109 if (dn > 0)
110 close(dn);
f0211bf2
SL
111 if (FD > 0)
112 ioctl(FD, TIOCCDTR, 0);
f0211bf2
SL
113 close(FD);
114}