Print this page
3910 t_look(3NSL) should never return T_ERROR
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libnsl/dial/interface.c
+++ new/usr/src/lib/libnsl/dial/interface.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22
23 23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
24 24 /* All Rights Reserved */
25 25
26 26 /*
27 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 + * Copyright 2014 Gary Mills
29 30 */
30 31
31 -#pragma ident "%Z%%M% %I% %E% SMI"
32 -
33 32 /*
34 33 * interface( label )
35 34 * provide alternate definitions for the I/O functions through global
36 35 * interfaces.
37 36 */
38 37 #include "mt.h"
39 38 #include "uucp.h"
40 39 #include <unistd.h>
41 40
42 41 #ifdef TLI
43 42 #include <tiuser.h>
44 43 #endif /* TLI */
45 44
46 45 static void sethup(int);
47 46 static int restline(void);
48 47 static int usetup(int, int *, int *);
49 48 static int uteardown(int, int, int);
50 49
51 50 static ssize_t (*Read)() = read,
52 51 (*Write)() = write;
53 52 static int (*Ioctl)(int, int, ...) = ioctl,
54 53 (*Setup)() = usetup;
55 54
56 55 #ifdef TLI
57 56 static void tfaillog(int fd, const char *s);
58 57 static void show_tlook(int);
59 58 static ssize_t tread(int, char *, unsigned);
60 59 static ssize_t twrite(int, char *, unsigned);
61 60 static int tioctl(int, int, ...);
62 61 static int tsetup(int, int *, int *); /* TLI setup without streams module */
63 62 static int tssetup(int, int *, int *); /* TLI setup with streams module */
64 63 static int tteardown(int, int, int); /* TLI teardown, works with either setup */
65 64 #endif /* TLI */
66 65
67 66 /*
68 67 * The IN_label in Interface[] imply different caller routines:
69 68 * e.g. tlicall().
70 69 * If so, the names here and the names in callers.c must match.
71 70 */
72 71 static struct Interface {
73 72 const char *IN_label; /* interface name */
74 73 ssize_t (*IN_read)(); /* read function */
75 74 ssize_t (*IN_write)(); /* write function */
76 75 int (*IN_ioctl)(int, int, ...);
77 76 int (*IN_setup)(); /* setup function, called before */
78 77 /* first i/o operation */
79 78 int (*IN_teardown)(); /* teardown function, called after */
80 79 /* last i/o operation */
81 80 } Interface[] = {
82 81 /* vanilla UNIX */
83 82 { "UNIX", read, write, ioctl, usetup, uteardown },
84 83 #ifdef TLI
85 84 /* AT&T Transport Interface Library WITHOUT streams */
86 85 { "TLI", tread, twrite, tioctl, tsetup, tteardown },
87 86 #ifdef TLIS
88 87 /* AT&T Transport Interface Library WITH streams */
89 88 { "TLIS", read, write, tioctl, tssetup, uteardown },
90 89 #endif /* TLIS */
91 90 #endif /* TLI */
92 91 { 0, 0, 0, 0, 0, 0 }
93 92 };
94 93
95 94
96 95 static int
97 96 interface(const char *label)
98 97 {
99 98 int i;
100 99
101 100 for (i = 0; Interface[i].IN_label; ++i) {
102 101 if (strcmp(Interface[i].IN_label, label) == 0) {
103 102 Read = Interface[i].IN_read;
104 103 Write = Interface[i].IN_write;
105 104 Ioctl = Interface[i].IN_ioctl;
106 105 Setup = Interface[i].IN_setup;
107 106 DEBUG(5, "set interface %s\n", label);
108 107 return (0);
109 108 }
110 109 }
111 110 return (FAIL);
112 111 }
113 112
114 113 /*
115 114 * usetup - vanilla unix setup routine
116 115 */
117 116 static int
118 117 usetup(int role, int *fdreadp, int *fdwritep)
119 118 {
120 119 if (role == SLAVE) {
121 120 *fdreadp = 0;
122 121 *fdwritep = 1;
123 122 /* 2 has been re-opened to RMTDEBUG in main() */
124 123 }
125 124 return (SUCCESS);
126 125 }
127 126
128 127 /*
129 128 * uteardown - vanilla unix teardown routine
130 129 */
131 130 static int
132 131 uteardown(int role, int fdread, int fdwrite)
133 132 {
134 133 char *ttyn;
135 134
136 135 if (role == SLAVE) {
137 136 (void) restline();
138 137 sethup(0);
139 138 }
140 139 if (fdread != -1) {
141 140 ttyn = ttyname(fdread);
142 141 if (ttyn != NULL)
143 142 /* can fail, but who cares? */
144 143 (void) chmod(ttyn, Dev_mode);
145 144 (void) close(fdread);
146 145 (void) close(fdwrite);
147 146 }
148 147 return (SUCCESS);
149 148 }
150 149
151 150 #ifdef TLI
152 151 /*
153 152 * tread - tli read routine
154 153 */
155 154 static ssize_t
156 155 tread(int fd, char *buf, unsigned nbytes)
157 156 {
158 157 int rcvflags;
159 158
160 159 return ((ssize_t)t_rcv(fd, buf, nbytes, &rcvflags));
161 160 }
162 161
163 162 /*
164 163 * twrite - tli write routine
165 164 */
166 165 #define N_CHECK 100
167 166 static ssize_t
168 167 twrite(int fd, char *buf, unsigned nbytes)
169 168 {
170 169 int i, ret;
171 170 static int n_writ, got_info;
172 171 static struct t_info info;
173 172
174 173 if (got_info == 0) {
175 174 if (t_getinfo(fd, &info) != 0) {
176 175 tfaillog(fd, "twrite: t_getinfo\n");
177 176 return (FAIL);
178 177 }
179 178 got_info = 1;
180 179 }
181 180
182 181 /* on every N_CHECKth call, check that are still in DATAXFER state */
183 182 if (++n_writ == N_CHECK) {
184 183 n_writ = 0;
185 184 if (t_getstate(fd) != T_DATAXFER)
186 185 return (FAIL);
187 186 }
188 187
189 188 if (info.tsdu <= 0 || nbytes <= info.tsdu)
190 189 return ((ssize_t)t_snd(fd, buf, nbytes, NULL));
191 190 /* if get here, then there is a limit on transmit size */
192 191 /* (info.tsdu > 0) and buf exceeds it */
193 192 i = ret = 0;
194 193 while (nbytes >= info.tsdu) {
195 194 if ((ret = t_snd(fd, &buf[i], info.tsdu, NULL)) != info.tsdu)
196 195 return ((ssize_t)(ret >= 0 ? (i + ret) : ret));
197 196 i += info.tsdu;
198 197 nbytes -= info.tsdu;
199 198 }
200 199 if (nbytes != 0) {
201 200 if ((ret = t_snd(fd, &buf[i], nbytes, NULL)) != nbytes)
202 201 return ((ssize_t)(ret >= 0 ? (i + ret) : ret));
203 202 i += nbytes;
204 203 }
205 204 return ((ssize_t)i);
206 205 }
207 206
208 207 /*
209 208 * tioctl - stub for tli ioctl routine
210 209 */
211 210 /* ARGSUSED */
212 211 static int
213 212 tioctl(int fd, int request, ...)
214 213 {
215 214 return (SUCCESS);
216 215 }
217 216
218 217 /*
219 218 * tsetup - tli setup routine
220 219 * note blatant assumption that *fdreadp == *fdwritep == 0
221 220 */
222 221 static int
223 222 tsetup(int role, int *fdreadp, int *fdwritep)
224 223 {
225 224 if (role == SLAVE) {
226 225 *fdreadp = 0;
227 226 *fdwritep = 1;
228 227 /* 2 has been re-opened to RMTDEBUG in main() */
229 228 errno = t_errno = 0;
230 229 if (t_sync(*fdreadp) == -1 || t_sync(*fdwritep) == -1) {
231 230 tfaillog(*fdreadp, "tsetup: t_sync\n");
232 231 return (FAIL);
233 232 }
234 233 }
235 234 return (SUCCESS);
236 235 }
237 236
238 237 /*
239 238 * tteardown - tli shutdown routine
240 239 */
241 240 /* ARGSUSED */
242 241 static int
243 242 tteardown(int role, int fdread, int fdwrite)
244 243 {
245 244 (void) t_unbind(fdread);
246 245 (void) t_close(fdread);
247 246 return (SUCCESS);
248 247 }
249 248
250 249 #ifdef TLIS
251 250 /*
252 251 * tssetup - tli, with streams module, setup routine
253 252 * note blatant assumption that *fdreadp == *fdwritep
254 253 */
255 254 static int
256 255 tssetup(int role, int *fdreadp, int *fdwritep)
257 256 {
258 257 if (role == SLAVE) {
259 258 *fdreadp = 0;
260 259 *fdwritep = 1;
261 260 /* 2 has been re-opened to RMTDEBUG in main() */
262 261 DEBUG(5, "tssetup: SLAVE mode: leaving ok\n%s", "");
263 262 return (SUCCESS);
264 263 }
265 264
266 265 DEBUG(4, "tssetup: MASTER mode: leaving ok\n%s", "");
267 266 return (SUCCESS);
268 267 }
269 268
270 269 /*
271 270 * Report why a TLI call failed.
272 271 */
273 272 static void
274 273 tfaillog(int fd, const char *s)
275 274 {
276 275 char fmt[ BUFSIZ ];
277 276
278 277 if (0 < t_errno && t_errno < t_nerr) {
279 278 (void) snprintf(fmt, sizeof (fmt), "%s: %%s\n", s);
↓ open down ↓ |
237 lines elided |
↑ open up ↑ |
280 279 DEBUG(5, fmt, t_errlist[t_errno]);
281 280 logent(s, t_errlist[t_errno]);
282 281 if (t_errno == TSYSERR) {
283 282 (void) strcpy(fmt, "tlicall: system error: %s\n");
284 283 DEBUG(5, fmt, strerror(errno));
285 284 } else if (t_errno == TLOOK) {
286 285 show_tlook(fd);
287 286 }
288 287 } else {
289 288 (void) snprintf(fmt, sizeof (fmt),
290 - "unknown tli error %d", t_errno);
289 + "unknown tli error %d", t_errno);
291 290 logent(s, fmt);
292 291 (void) snprintf(fmt, sizeof (fmt),
293 - "%s: unknown tli error %d", s, t_errno);
292 + "%s: unknown tli error %d", s, t_errno);
294 293 DEBUG(5, fmt, 0);
295 294 (void) snprintf(fmt, sizeof (fmt), "%s: %%s\n", s);
296 295 DEBUG(5, fmt, strerror(errno));
297 296 }
298 297 }
299 298
300 299 static void
301 300 show_tlook(int fd)
302 301 {
303 302 int reason;
304 303 const char *msg;
305 304
306 305 /*
307 306 * Find out the current state of the interface.
308 307 */
309 308 errno = t_errno = 0;
310 309 switch (reason = t_getstate(fd)) {
311 310 case T_UNBND: msg = (const char *)"T_UNBIND"; break;
312 311 case T_IDLE: msg = (const char *)"T_IDLE"; break;
313 312 case T_OUTCON: msg = (const char *)"T_OUTCON"; break;
314 313 case T_INCON: msg = (const char *)"T_INCON"; break;
315 314 case T_DATAXFER: msg = (const char *)"T_DATAXFER"; break;
316 315 case T_OUTREL: msg = (const char *)"T_OUTREL"; break;
317 316 case T_INREL: msg = (const char *)"T_INREL"; break;
318 317 default: msg = NULL; break;
319 318 }
320 319 if (msg == NULL)
321 320 return;
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
322 321 DEBUG(5, "state is %s", msg);
323 322 switch (reason = t_look(fd)) {
324 323 case -1: msg = (const char *)""; break;
325 324 case 0: msg = (const char *)"NO ERROR"; break;
326 325 case T_LISTEN: msg = (const char *)"T_LISTEN"; break;
327 326 case T_CONNECT: msg = (const char *)"T_CONNECT"; break;
328 327 case T_DATA: msg = (const char *)"T_DATA"; break;
329 328 case T_EXDATA: msg = (const char *)"T_EXDATA"; break;
330 329 case T_DISCONNECT: msg = (const char *)"T_DISCONNECT"; break;
331 330 case T_ORDREL: msg = (const char *)"T_ORDREL"; break;
332 - case T_ERROR: msg = (const char *)"T_ERROR"; break;
333 331 case T_UDERR: msg = (const char *)"T_UDERR"; break;
334 332 default: msg = (const char *)"UNKNOWN ERROR"; break;
335 333 }
336 334 DEBUG(4, " reason is %s\n", msg);
337 335
338 336 if (reason == T_DISCONNECT) {
339 337 struct t_discon *dropped;
340 338 if (((dropped =
341 - /* LINTED pointer cast */
342 - (struct t_discon *)t_alloc(fd, T_DIS, T_ALL)) == 0) ||
343 - (t_rcvdis(fd, dropped) == -1)) {
339 + /* LINTED pointer cast */
340 + (struct t_discon *)t_alloc(fd, T_DIS, T_ALL)) == 0) ||
341 + (t_rcvdis(fd, dropped) == -1)) {
344 342 if (dropped)
345 343 (void) t_free((char *)dropped, T_DIS);
346 344 return;
347 345 }
348 346 DEBUG(5, "disconnect reason #%d\n", dropped->reason);
349 347 (void) t_free((char *)dropped, T_DIS);
350 348 }
351 349 }
352 350 #endif /* TLIS */
353 351 #endif /* TLI */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX