Commit | Line | Data |
---|---|---|
f49909f5 | 1 | /*- |
ad787160 C |
2 | * Copyright (c) 1985, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
f49909f5 | 4 | * |
ad787160 C |
5 | * This module is believed to contain source code proprietary to AT&T. |
6 | * Use and redistribution is subject to the Berkeley Software License | |
7 | * Agreement and your Software Agreement with AT&T (Western Electric). | |
f49909f5 KB |
8 | */ |
9 | ||
f76694db | 10 | #ifndef lint |
ad787160 | 11 | static char sccsid[] = "@(#)dn.c 8.1 (Berkeley) 6/6/93"; |
f49909f5 | 12 | #endif /* not lint */ |
f76694db | 13 | |
ddf4e66c | 14 | #include "condevs.h" |
de465ec0 | 15 | #define ACULAST "-<" |
f76694db RC |
16 | |
17 | /*** | |
18 | * dnopn(ph, flds, dev) dial remote machine | |
19 | * | |
20 | * return codes: | |
21 | * file descriptor - succeeded | |
22 | * FAIL - failed | |
23 | */ | |
24 | dnopn(ph, flds, dev) | |
25 | char *ph; | |
26 | char *flds[]; | |
27 | struct Devices *dev; | |
28 | { | |
29 | char dcname[20], dnname[20], phone[MAXPH+2], c = 0; | |
de465ec0 | 30 | #ifdef USG |
f76694db | 31 | struct termio ttbuf; |
de465ec0 | 32 | #endif USG |
f76694db RC |
33 | int dnf, dcf; |
34 | int nw, lt, pid, status; | |
35 | unsigned timelim; | |
de465ec0 JB |
36 | #ifdef TIOCFLUSH |
37 | int zero = 0; | |
38 | #endif TIOCFLUSH | |
f76694db RC |
39 | |
40 | sprintf(dnname, "/dev/%s", dev->D_calldev); | |
41 | errno = 0; | |
42 | ||
43 | if (setjmp(Sjbuf)) { | |
44 | logent(dnname, "CAN'T OPEN"); | |
45 | DEBUG(4, "%s Open timed out\n", dnname); | |
46 | return(CF_NODEV); | |
47 | } | |
48 | signal(SIGALRM, alarmtr); | |
49 | getnextfd(); | |
50 | alarm(10); | |
51 | dnf = open(dnname, 1); | |
52 | alarm(0); | |
53 | next_fd = -1; | |
54 | if (dnf < 0 && errno == EACCES) { | |
55 | logent(dnname, "CAN'T OPEN"); | |
56 | logent("DEVICE", "NO"); | |
57 | return CF_NODEV; | |
58 | } | |
59 | fioclex(dnf); | |
60 | ||
61 | sprintf(dcname, "/dev/%s", dev->D_line); | |
62 | sprintf(phone, "%s%s", ph, ACULAST); | |
63 | DEBUG(4, "dc - %s, ", dcname); | |
64 | DEBUG(4, "acu - %s\n", dnname); | |
65 | pid = 0; | |
66 | if (setjmp(Sjbuf)) { | |
67 | logent("DIALUP DN write", "TIMEOUT"); | |
68 | if (pid) | |
69 | kill(pid, 9); | |
70 | delock(dev->D_line); | |
71 | if (dnf) | |
72 | close(dnf); | |
73 | return CF_DIAL; | |
74 | } | |
75 | signal(SIGALRM, alarmtr); | |
76 | timelim = 5 * strlen(phone); | |
77 | alarm(timelim < 30 ? 30 : timelim); | |
78 | if ((pid = fork()) == 0) { | |
79 | sleep(2); | |
80 | fclose(stdin); | |
81 | fclose(stdout); | |
82 | #ifdef TIOCFLUSH | |
de465ec0 JB |
83 | ioctl(dnf, TIOCFLUSH, &zero); |
84 | #endif TIOCFLUSH | |
f76694db RC |
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\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 | getnextfd(); | |
101 | errno = 0; | |
102 | dcf = open(dcname, 2); | |
103 | next_fd = -1; | |
104 | if (dcf < 0 && errno == EACCES) | |
105 | logent(dcname, "CAN'T OPEN"); | |
106 | DEBUG(4, "dcf is %d\n", dcf); | |
107 | if (dcf < 0) { | |
108 | logent("DIALUP LINE open", _FAILED); | |
109 | alarm(0); | |
110 | kill(pid, 9); | |
111 | close(dnf); | |
112 | delock(dev->D_line); | |
113 | return CF_DIAL; | |
114 | } | |
115 | while ((nw = wait(<)) != pid && nw != -1) | |
116 | ; | |
de465ec0 | 117 | #ifdef USG |
f76694db 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 |
f76694db 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 | * dncls() close dn type call unit | |
140 | * | |
141 | * return codes: None | |
142 | */ | |
143 | dncls(fd) | |
144 | register int fd; | |
145 | { | |
146 | if (fd > 0) { | |
147 | close(fd); | |
148 | sleep(5); | |
149 | delock(devSel); | |
150 | } | |
151 | } |