Commit | Line | Data |
---|---|---|
f49909f5 | 1 | /*- |
17e8cbca KB |
2 | * Copyright (c) 1985, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
f49909f5 KB |
4 | * |
5 | * %sccs.include.proprietary.c% | |
6 | */ | |
7 | ||
4788e774 | 8 | #ifndef lint |
17e8cbca | 9 | static char sccsid[] = "@(#)df2.c 8.1 (Berkeley) %G%"; |
f49909f5 | 10 | #endif /* not lint */ |
4788e774 | 11 | |
ddf4e66c | 12 | #include "condevs.h" |
4788e774 RC |
13 | |
14 | /* | |
15 | * df2opn(ph, flds, dev) dial remote machine | |
16 | * | |
17 | * return codes: | |
18 | * file descriptor - succeeded | |
19 | * FAIL - failed | |
20 | */ | |
21 | df2opn(ph, flds, dev) | |
22 | char *ph; | |
23 | char *flds[]; | |
24 | struct Devices *dev; | |
25 | { | |
26 | char dcname[20], dnname[20], phone[MAXPH+2], c = 0; | |
de465ec0 | 27 | #ifdef USG |
4788e774 | 28 | struct termio ttbuf; |
de465ec0 | 29 | #endif USG |
4788e774 RC |
30 | int dcf, dnf; |
31 | int nw, lt, pid, st, status; | |
32 | unsigned timelim; | |
de465ec0 JB |
33 | #ifdef TIOCFLUSH |
34 | int zero = 0; | |
35 | #endif TIOCFLUSH | |
4788e774 RC |
36 | |
37 | sprintf(dnname, "/dev/%s", dev->D_calldev); | |
38 | if (setjmp(Sjbuf)) { | |
39 | logent(dnname, "CAN'T OPEN"); | |
40 | DEBUG(4, "%s Open timed out\n", dnname); | |
41 | return CF_NODEV; | |
42 | } | |
43 | signal(SIGALRM, alarmtr); | |
44 | getnextfd(); | |
45 | errno = 0; | |
46 | alarm(10); | |
47 | dnf = open(dnname, 2 ); | |
48 | alarm(0); | |
49 | next_fd = -1; | |
50 | if (dnf < 0 && errno == EACCES) { | |
51 | logent(dnname, "CAN'T OPEN"); | |
52 | delock(dev->D_line); | |
53 | logent("DEVICE", "NO"); | |
54 | return CF_NODEV; | |
55 | } | |
56 | fioclex(dnf); | |
57 | ||
58 | sprintf(dcname, "/dev/%s", dev->D_line); | |
59 | fixline(dnf, dev->D_speed); | |
60 | sprintf(phone, "\02%s", ph); | |
61 | DEBUG(4, "dc - %s, ", dcname); | |
62 | DEBUG(4, "acu - %s\n", dnname); | |
63 | pid = 0; | |
64 | if (setjmp(Sjbuf)) { | |
65 | logent("DIALUP DN write", "TIMEOUT"); | |
66 | if (pid) | |
67 | kill(pid, 9); | |
68 | delock(dev->D_line); | |
69 | if (dnf) | |
70 | close(dnf); | |
71 | return CF_DIAL; | |
72 | } | |
73 | signal(SIGALRM, alarmtr); | |
74 | timelim = 5 * strlen(phone); | |
75 | alarm(timelim < 30 ? 30 : timelim); | |
76 | if ((pid = fork()) == 0) { | |
77 | sleep(2); | |
78 | fclose(stdin); | |
79 | fclose(stdout); | |
80 | #ifdef TIOCFLUSH | |
de465ec0 | 81 | ioctl(dnf, TIOCFLUSH, &zero); |
4788e774 RC |
82 | #endif TIOCFLUSH |
83 | write(dnf, "\01", 1); | |
84 | sleep(1); | |
85 | nw = write(dnf, phone, lt = strlen(phone)); | |
86 | if (nw != lt) { | |
87 | logent("DIALUP ACU write", _FAILED); | |
88 | exit(1); | |
89 | } | |
90 | DEBUG(4, "ACU write ok%s\n", CNULL); | |
91 | exit(0); | |
92 | } | |
93 | /* open line - will return on carrier */ | |
94 | /* RT needs a sleep here because it returns immediately from open */ | |
95 | ||
96 | #if RT | |
97 | sleep(15); | |
98 | #endif | |
99 | ||
100 | if (read(dnf, &c, 1) != 1 || c != 'A') | |
101 | dcf = -1; | |
102 | else | |
103 | dcf = 0; | |
104 | DEBUG(4, "dcf is %d\n", dcf); | |
105 | if (dcf < 0) { | |
106 | logent("DIALUP LINE open", _FAILED); | |
107 | alarm(0); | |
108 | kill(pid, 9); | |
109 | close(dnf); | |
110 | delock(dev->D_line); | |
111 | return CF_DIAL; | |
112 | } | |
113 | dcf = dnf; | |
114 | dnf = 0; | |
115 | while ((nw = wait(<)) != pid && nw != -1) | |
116 | ; | |
de465ec0 | 117 | #ifdef USG |
4788e774 RC |
118 | ioctl(dcf, TCGETA, &ttbuf); |
119 | if(!(ttbuf.c_cflag & HUPCL)) { | |
120 | ttbuf.c_cflag |= HUPCL; | |
121 | ioctl(dcf, TCSETA, &ttbuf); | |
122 | } | |
de465ec0 | 123 | #endif USG |
4788e774 RC |
124 | alarm(0); |
125 | fflush(stdout); | |
126 | fixline(dcf, dev->D_speed); | |
127 | DEBUG(4, "Fork Stat %o\n", lt); | |
128 | if (lt != 0) { | |
129 | close(dcf); | |
130 | if (dnf) | |
131 | close(dnf); | |
132 | delock(dev->D_line); | |
133 | return CF_DIAL; | |
134 | } | |
135 | return dcf; | |
136 | } | |
137 | ||
138 | /* | |
139 | * df2cls() close the DF02/DF03 call unit | |
140 | * | |
141 | * return codes: none | |
142 | */ | |
143 | df2cls(fd) | |
144 | register int fd; | |
145 | { | |
146 | if (fd > 0) { | |
147 | close(fd); | |
148 | sleep(5); | |
149 | delock(devSel); | |
150 | } | |
151 | } |