blob: d946b22c7fd5069a89d0629612fa4bfb8d88d4ed [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00003 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id$
29 */
30
31#include "defs.h"
Roland McGrath34e014a2002-12-16 20:40:59 +000032#include <sys/syscall.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033
Wichert Akkerman42080d82001-04-10 10:32:26 +000034#ifdef HAVE_POLL_H
35#include <poll.h>
36#endif
Pavel Machek245a6ac2000-02-01 16:12:33 +000037#ifdef HAVE_SYS_POLL_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038#include <sys/poll.h>
Pavel Machek245a6ac2000-02-01 16:12:33 +000039#endif
Wichert Akkerman42080d82001-04-10 10:32:26 +000040#ifdef HAVE_STROPTS_H
41#include <stropts.h>
42#endif
43#ifdef HAVE_SYS_CONF_H
44#include <sys/conf.h>
45#endif
46#ifdef HAVE_SYS_STREAM_H
47#include <sys/stream.h>
48#endif
49#ifdef HAVE_SYS_TIHDR_H
50#include <sys/tihdr.h>
51#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052
Roland McGrath561c7992003-04-02 01:10:44 +000053#if defined(HAVE_SYS_STREAM_H) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman42080d82001-04-10 10:32:26 +000054
55#ifndef HAVE_STROPTS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056#define RS_HIPRI 1
57struct strbuf {
Denys Vlasenkoadedb512008-12-30 18:47:55 +000058 int maxlen; /* no. of bytes in buffer */
59 int len; /* no. of bytes returned */
Dmitry V. Levin30145dd2010-09-06 22:08:24 +000060 const char *buf; /* pointer to data */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061};
62#define MORECTL 1
63#define MOREDATA 2
Wichert Akkerman42080d82001-04-10 10:32:26 +000064#endif /* !HAVE_STROPTS_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065
66#ifdef HAVE_SYS_TIUSER_H
67#include <sys/tiuser.h>
68#include <sys/sockmod.h>
69#include <sys/timod.h>
70#endif /* HAVE_SYS_TIUSER_H */
71
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000072#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +000073static const struct xlat msgflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 { RS_HIPRI, "RS_HIPRI" },
75 { 0, NULL },
76};
77
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078
79static void
Denys Vlasenko12014262011-05-30 14:00:14 +020080printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081{
82 if (sbp->maxlen == -1 && getting)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020083 tprints("{maxlen=-1}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020085 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000086 if (getting)
87 tprintf("maxlen=%d, ", sbp->maxlen);
88 tprintf("len=%d, buf=", sbp->len);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000089 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020090 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091 }
92}
93
94static void
Denys Vlasenko12014262011-05-30 14:00:14 +020095printstrbufarg(struct tcb *tcp, int arg, int getting)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000096{
97 struct strbuf buf;
98
99 if (arg == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200100 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101 else if (umove(tcp, arg, &buf) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200102 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000103 else
104 printstrbuf(tcp, &buf, getting);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200105 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106}
107
108int
Denys Vlasenko12014262011-05-30 14:00:14 +0200109sys_putmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000110{
111 int i;
112
113 if (entering(tcp)) {
114 /* fd */
115 tprintf("%ld, ", tcp->u_arg[0]);
116 /* control and data */
117 for (i = 1; i < 3; i++)
118 printstrbufarg(tcp, tcp->u_arg[i], 0);
119 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000120 printflags(msgflags, tcp->u_arg[3], "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121 }
122 return 0;
123}
124
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000125#if defined(SPARC) || defined(SPARC64) || defined(SUNOS4) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126int
Denys Vlasenko12014262011-05-30 14:00:14 +0200127sys_getmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128{
129 int i, flags;
130
131 if (entering(tcp)) {
132 /* fd */
133 tprintf("%lu, ", tcp->u_arg[0]);
134 } else {
135 if (syserror(tcp)) {
136 tprintf("%#lx, %#lx, %#lx",
137 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
138 return 0;
139 }
140 /* control and data */
141 for (i = 1; i < 3; i++)
142 printstrbufarg(tcp, tcp->u_arg[i], 1);
143 /* pointer to flags */
144 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200145 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200147 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200149 tprints("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000150 printflags(msgflags, flags, "RS_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200151 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000152 }
153 /* decode return value */
154 switch (tcp->u_rval) {
155 case MORECTL:
156 tcp->auxstr = "MORECTL";
157 break;
158 case MORECTL|MOREDATA:
159 tcp->auxstr = "MORECTL|MOREDATA";
160 break;
161 case MOREDATA:
162 tcp->auxstr = "MORECTL";
163 break;
164 default:
165 tcp->auxstr = NULL;
166 break;
167 }
168 }
169 return RVAL_HEX | RVAL_STR;
170}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000171#endif /* SPARC || SPARC64 || SUNOS4 || SVR4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172
Roland McGrath34e014a2002-12-16 20:40:59 +0000173#if defined SYS_putpmsg || defined SYS_getpmsg
Roland McGrathd9f816f2004-09-04 03:39:20 +0000174static const struct xlat pmsgflags[] = {
Wichert Akkermand856b992000-10-13 12:47:12 +0000175#ifdef MSG_HIPRI
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176 { MSG_HIPRI, "MSG_HIPRI" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000177#endif
178#ifdef MSG_AND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179 { MSG_ANY, "MSG_ANY" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000180#endif
181#ifdef MSG_BAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 { MSG_BAND, "MSG_BAND" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000183#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184 { 0, NULL },
185};
Roland McGrath34e014a2002-12-16 20:40:59 +0000186#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187
Roland McGrath34e014a2002-12-16 20:40:59 +0000188#ifdef SYS_putpmsg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000189int
Denys Vlasenko12014262011-05-30 14:00:14 +0200190sys_putpmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191{
192 int i;
193
194 if (entering(tcp)) {
195 /* fd */
196 tprintf("%ld, ", tcp->u_arg[0]);
197 /* control and data */
198 for (i = 1; i < 3; i++)
199 printstrbufarg(tcp, tcp->u_arg[i], 0);
200 /* band */
201 tprintf("%ld, ", tcp->u_arg[3]);
202 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000203 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204 }
205 return 0;
206}
Roland McGrath34e014a2002-12-16 20:40:59 +0000207#endif /* SYS_putpmsg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208
Roland McGrath34e014a2002-12-16 20:40:59 +0000209#ifdef SYS_getpmsg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000210int
Denys Vlasenko12014262011-05-30 14:00:14 +0200211sys_getpmsg(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000212{
213 int i, flags;
214
215 if (entering(tcp)) {
216 /* fd */
217 tprintf("%lu, ", tcp->u_arg[0]);
218 } else {
219 if (syserror(tcp)) {
220 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
221 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
222 return 0;
223 }
224 /* control and data */
225 for (i = 1; i < 3; i++)
226 printstrbufarg(tcp, tcp->u_arg[i], 1);
227 /* pointer to band */
228 printnum(tcp, tcp->u_arg[3], "%d");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200229 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000230 /* pointer to flags */
231 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200232 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200234 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200236 tprints("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000237 printflags(pmsgflags, flags, "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200238 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000239 }
240 /* decode return value */
241 switch (tcp->u_rval) {
242 case MORECTL:
243 tcp->auxstr = "MORECTL";
244 break;
245 case MORECTL|MOREDATA:
246 tcp->auxstr = "MORECTL|MOREDATA";
247 break;
248 case MOREDATA:
249 tcp->auxstr = "MORECTL";
250 break;
251 default:
252 tcp->auxstr = NULL;
253 break;
254 }
255 }
256 return RVAL_HEX | RVAL_STR;
257}
Roland McGrath34e014a2002-12-16 20:40:59 +0000258#endif /* SYS_getpmsg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000260#endif /* !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000263#ifdef HAVE_SYS_POLL_H
264
Roland McGrathd9f816f2004-09-04 03:39:20 +0000265static const struct xlat pollflags[] = {
Pavel Machek245a6ac2000-02-01 16:12:33 +0000266#ifdef POLLIN
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267 { POLLIN, "POLLIN" },
268 { POLLPRI, "POLLPRI" },
269 { POLLOUT, "POLLOUT" },
270#ifdef POLLRDNORM
271 { POLLRDNORM, "POLLRDNORM" },
272#endif
273#ifdef POLLWRNORM
274 { POLLWRNORM, "POLLWRNORM" },
275#endif
276#ifdef POLLRDBAND
277 { POLLRDBAND, "POLLRDBAND" },
278#endif
279#ifdef POLLWRBAND
280 { POLLWRBAND, "POLLWRBAND" },
281#endif
282 { POLLERR, "POLLERR" },
283 { POLLHUP, "POLLHUP" },
284 { POLLNVAL, "POLLNVAL" },
Pavel Machek245a6ac2000-02-01 16:12:33 +0000285#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000286 { 0, NULL },
287};
288
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000289static int
Roland McGrathf17106e2007-11-01 21:49:49 +0000290decode_poll(struct tcb *tcp, long pts)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291{
Roland McGrathaa524c82005-06-01 19:22:06 +0000292 struct pollfd fds;
293 unsigned nfds;
294 unsigned long size, start, cur, end, abbrev_end;
295 int failed = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296
Roland McGrathf17106e2007-11-01 21:49:49 +0000297 if (entering(tcp)) {
298 nfds = tcp->u_arg[1];
299 size = sizeof(fds) * nfds;
300 start = tcp->u_arg[0];
301 end = start + size;
302 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
303 tprintf("%#lx, %d, ",
304 tcp->u_arg[0], nfds);
305 return 0;
306 }
307 if (abbrev(tcp)) {
308 abbrev_end = start + max_strlen * sizeof(fds);
309 if (abbrev_end < start)
310 abbrev_end = end;
311 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000312 abbrev_end = end;
Roland McGrathf17106e2007-11-01 21:49:49 +0000313 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200314 tprints("[");
Roland McGrathf17106e2007-11-01 21:49:49 +0000315 for (cur = start; cur < end; cur += sizeof(fds)) {
316 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200317 tprints(", ");
Roland McGrathf17106e2007-11-01 21:49:49 +0000318 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200319 tprints("...");
Roland McGrathf17106e2007-11-01 21:49:49 +0000320 break;
321 }
322 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200323 tprints("?");
Roland McGrathf17106e2007-11-01 21:49:49 +0000324 failed = 1;
325 break;
326 }
327 if (fds.fd < 0) {
328 tprintf("{fd=%d}", fds.fd);
329 continue;
330 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200331 tprints("{fd=");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300332 printfd(tcp, fds.fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200333 tprints(", events=");
Roland McGrathf17106e2007-11-01 21:49:49 +0000334 printflags(pollflags, fds.events, "POLL???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200335 tprints("}");
Roland McGrathf17106e2007-11-01 21:49:49 +0000336 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200337 tprints("]");
Roland McGrathf17106e2007-11-01 21:49:49 +0000338 if (failed)
339 tprintf(" %#lx", start);
340 tprintf(", %d, ", nfds);
341 return 0;
Roland McGrathaa524c82005-06-01 19:22:06 +0000342 } else {
Roland McGrathf17106e2007-11-01 21:49:49 +0000343 static char outstr[1024];
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200344 char *outptr;
345#define end_outstr (outstr + sizeof(outstr))
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000346 const char *flagstr;
Roland McGrathf17106e2007-11-01 21:49:49 +0000347
348 if (syserror(tcp))
349 return 0;
350 if (tcp->u_rval == 0) {
351 tcp->auxstr = "Timeout";
352 return RVAL_STR;
353 }
354
355 nfds = tcp->u_arg[1];
356 size = sizeof(fds) * nfds;
357 start = tcp->u_arg[0];
358 end = start + size;
359 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
360 return 0;
361 if (abbrev(tcp)) {
362 abbrev_end = start + max_strlen * sizeof(fds);
363 if (abbrev_end < start)
364 abbrev_end = end;
365 } else {
366 abbrev_end = end;
367 }
368
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200369 outptr = outstr;
Roland McGrathf17106e2007-11-01 21:49:49 +0000370
371 for (cur = start; cur < end; cur += sizeof(fds)) {
372 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200373 if (outptr < end_outstr - 2)
374 *outptr++ = '?';
Roland McGrathf17106e2007-11-01 21:49:49 +0000375 failed = 1;
376 break;
377 }
378 if (!fds.revents)
379 continue;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200380 if (outptr == outstr) {
381 *outptr++ = '[';
Roland McGrathf17106e2007-11-01 21:49:49 +0000382 } else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200383 if (outptr < end_outstr - 3)
384 outptr = stpcpy(outptr, ", ");
Roland McGrathf17106e2007-11-01 21:49:49 +0000385 }
386 if (cur >= abbrev_end) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200387 if (outptr < end_outstr - 4)
388 outptr = stpcpy(outptr, "...");
Roland McGrathf17106e2007-11-01 21:49:49 +0000389 break;
390 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200391 if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
392 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200393 flagstr = sprintflags("", pollflags, fds.revents);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200394 if (outptr < end_outstr - (strlen(flagstr) + 2)) {
395 outptr = stpcpy(outptr, flagstr);
396 *outptr++ = '}';
Roland McGrathf17106e2007-11-01 21:49:49 +0000397 }
398 }
399 if (failed)
400 return 0;
401
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200402 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
403 *outptr++ = ']';
Roland McGrathf17106e2007-11-01 21:49:49 +0000404
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200405 *outptr = '\0';
Roland McGrathf17106e2007-11-01 21:49:49 +0000406 if (pts) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100407 if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200408 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
409 sprint_timespec(outptr, tcp, pts);
410 }
Roland McGrathf17106e2007-11-01 21:49:49 +0000411 }
412
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200413 if (outptr == outstr)
Roland McGrathf17106e2007-11-01 21:49:49 +0000414 return 0;
415
416 tcp->auxstr = outstr;
417 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200418#undef end_outstr
Roland McGrathaa524c82005-06-01 19:22:06 +0000419 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420}
421
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000422int
423sys_poll(struct tcb *tcp)
424{
Roland McGrathf17106e2007-11-01 21:49:49 +0000425 int rc = decode_poll(tcp, 0);
426 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000427#ifdef INFTIM
428 if (tcp->u_arg[2] == INFTIM)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200429 tprints("INFTIM");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000430 else
431#endif
432 tprintf("%ld", tcp->u_arg[2]);
433 }
434 return rc;
435}
436
437#ifdef LINUX
438int
439sys_ppoll(struct tcb *tcp)
440{
Roland McGrathf17106e2007-11-01 21:49:49 +0000441 int rc = decode_poll(tcp, tcp->u_arg[2]);
442 if (entering(tcp)) {
Roland McGrath6bc09da2007-11-01 21:50:54 +0000443 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200444 tprints(", ");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000445 print_sigset(tcp, tcp->u_arg[3], 0);
446 tprintf(", %lu", tcp->u_arg[4]);
447 }
448 return rc;
449}
450#endif
Roland McGrathaa524c82005-06-01 19:22:06 +0000451
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000452#else /* !HAVE_SYS_POLL_H */
453int
Denys Vlasenko12014262011-05-30 14:00:14 +0200454sys_poll(struct tcb *tcp)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000455{
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000456 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000457}
458#endif
459
Roland McGrath561c7992003-04-02 01:10:44 +0000460#if !defined(LINUX) && !defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461
Roland McGrathd9f816f2004-09-04 03:39:20 +0000462static const struct xlat stream_flush_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463 { FLUSHR, "FLUSHR" },
464 { FLUSHW, "FLUSHW" },
465 { FLUSHRW, "FLUSHRW" },
466#ifdef FLUSHBAND
467 { FLUSHBAND, "FLUSHBAND" },
468#endif
469 { 0, NULL },
470};
471
Roland McGrathd9f816f2004-09-04 03:39:20 +0000472static const struct xlat stream_setsig_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473 { S_INPUT, "S_INPUT" },
474 { S_HIPRI, "S_HIPRI" },
475 { S_OUTPUT, "S_OUTPUT" },
476 { S_MSG, "S_MSG" },
477#ifdef S_ERROR
478 { S_ERROR, "S_ERROR" },
479#endif
480#ifdef S_HANGUP
481 { S_HANGUP, "S_HANGUP" },
482#endif
483#ifdef S_RDNORM
484 { S_RDNORM, "S_RDNORM" },
485#endif
486#ifdef S_WRNORM
487 { S_WRNORM, "S_WRNORM" },
488#endif
489#ifdef S_RDBAND
490 { S_RDBAND, "S_RDBAND" },
491#endif
492#ifdef S_WRBAND
493 { S_WRBAND, "S_WRBAND" },
494#endif
495#ifdef S_BANDURG
496 { S_BANDURG, "S_BANDURG" },
497#endif
498 { 0, NULL },
499};
500
Roland McGrathd9f816f2004-09-04 03:39:20 +0000501static const struct xlat stream_read_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502 { RNORM, "RNORM" },
503 { RMSGD, "RMSGD" },
504 { RMSGN, "RMSGN" },
505 { 0, NULL },
506};
507
Roland McGrathd9f816f2004-09-04 03:39:20 +0000508static const struct xlat stream_read_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509#ifdef RPROTDAT
510 { RPROTDAT, "RPROTDAT" },
511#endif
512#ifdef RPROTDIS
513 { RPROTDIS, "RPROTDIS" },
514#endif
515#ifdef RPROTNORM
516 { RPROTNORM, "RPROTNORM" },
517#endif
518 { 0, NULL },
519};
520
521#ifndef RMODEMASK
522#define RMODEMASK (~0)
523#endif
524
525#ifdef I_SWROPT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000526static const struct xlat stream_write_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 { SNDZERO, "SNDZERO" },
528 { SNDPIPE, "SNDPIPE" },
529 { 0, NULL },
530};
531#endif /* I_SWROPT */
532
533#ifdef I_ATMARK
Roland McGrathd9f816f2004-09-04 03:39:20 +0000534static const struct xlat stream_atmark_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535 { ANYMARK, "ANYMARK" },
536 { LASTMARK, "LASTMARK" },
537 { 0, NULL },
538};
539#endif /* I_ATMARK */
540
541#ifdef TI_BIND
Roland McGrathd9f816f2004-09-04 03:39:20 +0000542static const struct xlat transport_user_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 { T_CONN_REQ, "T_CONN_REQ" },
544 { T_CONN_RES, "T_CONN_RES" },
545 { T_DISCON_REQ, "T_DISCON_REQ" },
546 { T_DATA_REQ, "T_DATA_REQ" },
547 { T_EXDATA_REQ, "T_EXDATA_REQ" },
548 { T_INFO_REQ, "T_INFO_REQ" },
549 { T_BIND_REQ, "T_BIND_REQ" },
550 { T_UNBIND_REQ, "T_UNBIND_REQ" },
551 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
552 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
553 { T_ORDREL_REQ, "T_ORDREL_REQ" },
554 { 0, NULL },
555};
556
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200557static const struct xlat transport_user_flags[] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000558 { 0, "0" },
559 { T_MORE, "T_MORE" },
560 { T_EXPEDITED, "T_EXPEDITED" },
561 { T_NEGOTIATE, "T_NEGOTIATE" },
562 { T_CHECK, "T_CHECK" },
563 { T_DEFAULT, "T_DEFAULT" },
564 { T_SUCCESS, "T_SUCCESS" },
565 { T_FAILURE, "T_FAILURE" },
566 { T_CURRENT, "T_CURRENT" },
567 { T_PARTSUCCESS,"T_PARTSUCCESS" },
568 { T_READONLY, "T_READONLY" },
569 { T_NOTSUPPORT, "T_NOTSUPPORT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 { 0, NULL },
571};
John Hughes38ae88d2002-05-23 11:48:58 +0000572
573
Roland McGrath6d2b3492002-12-30 00:51:30 +0000574#ifdef HAVE_STRUCT_T_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +0000575
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200576static const struct xlat xti_level[] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000577 { XTI_GENERIC, "XTI_GENERIC" },
578 { 0, NULL },
579};
580
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200581static const struct xlat xti_generic[] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000582 { XTI_DEBUG, "XTI_DEBUG" },
583 { XTI_LINGER, "XTI_LINGER" },
584 { XTI_RCVBUF, "XTI_RCVBUF" },
585 { XTI_RCVLOWAT, "XTI_RCVLOWAT" },
586 { XTI_SNDBUF, "XTI_SNDBUF" },
587 { XTI_SNDLOWAT, "XTI_SNDLOWAT" },
588 { 0, NULL },
589};
590
591
592
593void
Denys Vlasenko12014262011-05-30 14:00:14 +0200594print_xti_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +0000595{
596 int c = 0;
597 struct t_opthdr hdr;
598
John Hughes2c4e3a82002-05-24 10:19:44 +0000599 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +0000600 if (umove(tcp, addr, &hdr) < 0) break;
601 if (c++) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200602 tprints(", ");
John Hughes38ae88d2002-05-23 11:48:58 +0000603 }
604 else if (len > hdr.len + sizeof hdr) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200605 tprints("[");
John Hughes38ae88d2002-05-23 11:48:58 +0000606 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200607 tprints("{level=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200608 printxval(xti_level, hdr.level, "???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200609 tprints(", name=");
John Hughes38ae88d2002-05-23 11:48:58 +0000610 switch (hdr.level) {
611 case XTI_GENERIC:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200612 printxval(xti_generic, hdr.name, "XTI_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000613 break;
614 default:
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200615 tprintf("%ld", hdr.name);
John Hughes38ae88d2002-05-23 11:48:58 +0000616 break;
617 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200618 tprints(", status=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200619 printxval(transport_user_flags, hdr.status, "T_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000620 addr += sizeof hdr;
621 len -= sizeof hdr;
622 if ((hdr.len -= sizeof hdr) > 0) {
623 if (hdr.len > len) break;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200624 tprints(", val=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200625 if (len == sizeof(int))
626 printnum(tcp, addr, "%d");
John Hughes38ae88d2002-05-23 11:48:58 +0000627 else
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200628 printstr(tcp, addr, hdr.len);
John Hughes38ae88d2002-05-23 11:48:58 +0000629 addr += hdr.len;
630 len -= hdr.len;
631 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200632 tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +0000633 }
634 if (len > 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200635 if (c++) tprints(", ");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200636 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +0000637 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200638 if (c > 1) tprints("]");
John Hughes38ae88d2002-05-23 11:48:58 +0000639}
640
641#endif
642
643
644static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200645print_optmgmt(struct tcb *tcp, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +0000646{
Roland McGrath34e014a2002-12-16 20:40:59 +0000647 /* We don't know how to tell if TLI (socket) or XTI
John Hughes38ae88d2002-05-23 11:48:58 +0000648 optmgmt is being used yet, assume TLI. */
Roland McGrath6d2b3492002-12-30 00:51:30 +0000649#if defined (HAVE_STRUCT_OPTHDR)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200650 print_sock_optmgmt(tcp, addr, len);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000651#elif defined (HAVE_STRUCT_T_OPTHDR)
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200652 print_xti_optmgmt(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +0000653#else
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200654 printstr(tcp, addr, len);
John Hughes38ae88d2002-05-23 11:48:58 +0000655#endif
656}
657
658
659
660
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200661static const struct xlat service_type[] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000662 { T_COTS, "T_COTS" },
663 { T_COTS_ORD, "T_COTS_ORD" },
664 { T_CLTS, "T_CLTS" },
665 { 0, NULL },
666};
667
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200668static const struct xlat ts_state[] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000669 { TS_UNBND, "TS_UNBND" },
670 { TS_WACK_BREQ, "TS_WACK_BREQ" },
671 { TS_WACK_UREQ, "TS_WACK_UREQ" },
672 { TS_IDLE, "TS_IDLE" },
673 { TS_WACK_OPTREQ,"TS_WACK_OPTREQ"},
674 { TS_WACK_CREQ, "TS_WACK_CREQ" },
675 { TS_WCON_CREQ, "TS_WCON_CREQ" },
676 { TS_WRES_CIND, "TS_WRES_CIND" },
677 { TS_WACK_CRES, "TS_WACK_CRES" },
678 { TS_DATA_XFER, "TS_DATA_XFER" },
679 { TS_WIND_ORDREL,"TS_WIND_ORDREL"},
680 { TS_WREQ_ORDREL,"TS_WREQ_ORDREL"},
681 { TS_WACK_DREQ6,"TS_WACK_DREQ6" },
682 { TS_WACK_DREQ7,"TS_WACK_DREQ7" },
683 { TS_WACK_DREQ9,"TS_WACK_DREQ9" },
684 { TS_WACK_DREQ10,"TS_WACK_DREQ10"},
685 { TS_WACK_DREQ11,"TS_WACK_DREQ11"},
686 { 0, NULL },
687};
688
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200689static const struct xlat provider_flags[] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000690 { 0, "0" },
691 { SENDZERO, "SENDZERO" },
692 { EXPINLINE, "EXPINLINE" },
693 { XPG4_1, "XPG4_1" },
694 { 0, NULL },
695};
696
697
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200698static const struct xlat tli_errors[] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000699 { TBADADDR, "TBADADDR" },
700 { TBADOPT, "TBADOPT" },
701 { TACCES, "TACCES" },
702 { TBADF, "TBADF" },
703 { TNOADDR, "TNOADDR" },
704 { TOUTSTATE, "TOUTSTATE" },
705 { TBADSEQ, "TBADSEQ" },
706 { TSYSERR, "TSYSERR" },
707 { TLOOK, "TLOOK" },
708 { TBADDATA, "TBADDATA" },
709 { TBUFOVFLW, "TBUFOVFLW" },
710 { TFLOW, "TFLOW" },
711 { TNODATA, "TNODATA" },
712 { TNODIS, "TNODIS" },
713 { TNOUDERR, "TNOUDERR" },
714 { TBADFLAG, "TBADFLAG" },
715 { TNOREL, "TNOREL" },
716 { TNOTSUPPORT, "TNOTSUPPORT" },
717 { TSTATECHNG, "TSTATECHNG" },
718 { TNOSTRUCTYPE, "TNOSTRUCTYPE" },
719 { TBADNAME, "TBADNAME" },
720 { TBADQLEN, "TBADQLEN" },
721 { TADDRBUSY, "TADDRBUSY" },
722 { TINDOUT, "TINDOUT" },
723 { TPROVMISMATCH,"TPROVMISMATCH" },
724 { TRESQLEN, "TRESQLEN" },
725 { TRESADDR, "TRESADDR" },
726 { TQFULL, "TQFULL" },
727 { TPROTO, "TPROTO" },
728 { 0, NULL },
729};
730
731
732static int
Denys Vlasenko12014262011-05-30 14:00:14 +0200733print_transport_message(struct tcb *tcp, int expect, long addr, int len)
John Hughes38ae88d2002-05-23 11:48:58 +0000734{
735 union T_primitives m;
736 int c = 0;
737
738 if (len < sizeof m.type) goto dump;
739
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200740 if (umove(tcp, addr, &m.type) < 0) goto dump;
John Hughes38ae88d2002-05-23 11:48:58 +0000741
742#define GET(type, struct) \
743 do { \
744 if (len < sizeof m.struct) goto dump; \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200745 if (umove(tcp, addr, &m.struct) < 0) goto dump; \
746 tprints("{"); \
John Hughes38ae88d2002-05-23 11:48:58 +0000747 if (expect != type) { \
748 ++c; \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200749 tprints(#type); \
John Hughes38ae88d2002-05-23 11:48:58 +0000750 } \
751 } \
752 while (0)
753
754#define COMMA() \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200755 do { if (c++) tprints(", "); } while (0)
Roland McGrath34e014a2002-12-16 20:40:59 +0000756
John Hughes38ae88d2002-05-23 11:48:58 +0000757
758#define STRUCT(struct, elem, print) \
759 do { \
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200760 COMMA(); \
John Hughes38ae88d2002-05-23 11:48:58 +0000761 if (m.struct.elem##_length < 0 || \
762 m.struct.elem##_offset < sizeof m.struct || \
763 m.struct.elem##_offset + m.struct.elem##_length > len) \
764 { \
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200765 tprintf(#elem "_length=%ld, " #elem "_offset=%ld",\
John Hughes38ae88d2002-05-23 11:48:58 +0000766 m.struct.elem##_length, \
767 m.struct.elem##_offset); \
768 } \
769 else { \
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200770 tprints(#elem "="); \
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200771 print(tcp, \
John Hughes38ae88d2002-05-23 11:48:58 +0000772 addr + m.struct.elem##_offset, \
773 m.struct.elem##_length); \
774 } \
775 } \
776 while (0)
777
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200778#define ADDR(struct, elem) STRUCT(struct, elem, printstr)
Roland McGrath34e014a2002-12-16 20:40:59 +0000779
John Hughes38ae88d2002-05-23 11:48:58 +0000780 switch (m.type) {
781#ifdef T_CONN_REQ
782 case T_CONN_REQ: /* connect request */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200783 GET(T_CONN_REQ, conn_req);
784 ADDR(conn_req, DEST);
785 ADDR(conn_req, OPT);
John Hughes38ae88d2002-05-23 11:48:58 +0000786 break;
787#endif
788#ifdef T_CONN_RES
789 case T_CONN_RES: /* connect response */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200790 GET(T_CONN_RES, conn_res);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000791#ifdef HAVE_STRUCT_T_CONN_RES_QUEUE_PTR
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200792 COMMA();
793 tprintf("QUEUE=%p", m.conn_res.QUEUE_ptr);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000794#elif defined HAVE_STRUCT_T_CONN_RES_ACCEPTOR_ID
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200795 COMMA();
796 tprintf("ACCEPTOR=%#lx", m.conn_res.ACCEPTOR_id);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000797#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200798 ADDR(conn_res, OPT);
799 COMMA();
800 tprintf("SEQ=%ld", m.conn_res.SEQ_number);
John Hughes38ae88d2002-05-23 11:48:58 +0000801 break;
802#endif
803#ifdef T_DISCON_REQ
804 case T_DISCON_REQ: /* disconnect request */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200805 GET(T_DISCON_REQ, discon_req);
806 COMMA();
807 tprintf("SEQ=%ld", m.discon_req.SEQ_number);
John Hughes38ae88d2002-05-23 11:48:58 +0000808 break;
809#endif
810#ifdef T_DATA_REQ
811 case T_DATA_REQ: /* data request */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200812 GET(T_DATA_REQ, data_req);
813 COMMA();
814 tprintf("MORE=%ld", m.data_req.MORE_flag);
John Hughes38ae88d2002-05-23 11:48:58 +0000815 break;
816#endif
817#ifdef T_EXDATA_REQ
818 case T_EXDATA_REQ: /* expedited data req */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200819 GET(T_EXDATA_REQ, exdata_req);
820 COMMA();
821 tprintf("MORE=%ld", m.exdata_req.MORE_flag);
John Hughes38ae88d2002-05-23 11:48:58 +0000822 break;
823#endif
824#ifdef T_INFO_REQ
825 case T_INFO_REQ: /* information req */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200826 GET(T_INFO_REQ, info_req);
John Hughes38ae88d2002-05-23 11:48:58 +0000827 break;
828#endif
829#ifdef T_BIND_REQ
830 case T_BIND_REQ: /* bind request */
831#ifdef O_T_BIND_REQ
832 case O_T_BIND_REQ: /* Ugly xti/tli hack */
833#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200834 GET(T_BIND_REQ, bind_req);
835 ADDR(bind_req, ADDR);
836 COMMA();
837 tprintf("CONIND=%ld", m.bind_req.CONIND_number);
John Hughes38ae88d2002-05-23 11:48:58 +0000838 break;
839#endif
840#ifdef T_UNBIND_REQ
841 case T_UNBIND_REQ: /* unbind request */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200842 GET(T_UNBIND_REQ, unbind_req);
John Hughes38ae88d2002-05-23 11:48:58 +0000843 break;
844#endif
845#ifdef T_UNITDATA_REQ
846 case T_UNITDATA_REQ: /* unitdata requset */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200847 GET(T_UNITDATA_REQ, unitdata_req);
848 ADDR(unitdata_req, DEST);
849 ADDR(unitdata_req, OPT);
John Hughes38ae88d2002-05-23 11:48:58 +0000850 break;
851#endif
852#ifdef T_OPTMGMT_REQ
853 case T_OPTMGMT_REQ: /* manage opt req */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200854 GET(T_OPTMGMT_REQ, optmgmt_req);
855 COMMA();
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200856 tprints("MGMT=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200857 printflags(transport_user_flags, m.optmgmt_req.MGMT_flags,
Roland McGrathb2dee132005-06-01 19:02:36 +0000858 "T_???");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200859 STRUCT(optmgmt_req, OPT, print_optmgmt);
John Hughes38ae88d2002-05-23 11:48:58 +0000860 break;
861#endif
862#ifdef T_ORDREL_REQ
863 case T_ORDREL_REQ: /* orderly rel req */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200864 GET(T_ORDREL_REQ, ordrel_req);
John Hughes38ae88d2002-05-23 11:48:58 +0000865 break;
866#endif
867#ifdef T_CONN_IND
868 case T_CONN_IND: /* connect indication */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200869 GET(T_CONN_IND, conn_ind);
870 ADDR(conn_ind, SRC);
871 ADDR(conn_ind, OPT);
872 tprintf(", SEQ=%ld", m.conn_ind.SEQ_number);
John Hughes38ae88d2002-05-23 11:48:58 +0000873 break;
874#endif
875#ifdef T_CONN_CON
876 case T_CONN_CON: /* connect corfirm */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200877 GET(T_CONN_CON, conn_con);
878 ADDR(conn_con, RES);
879 ADDR(conn_con, OPT);
John Hughes38ae88d2002-05-23 11:48:58 +0000880 break;
881#endif
882#ifdef T_DISCON_IND
883 case T_DISCON_IND: /* discon indication */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200884 GET(T_DISCON_IND, discon_ind);
885 COMMA();
886 tprintf("DISCON=%ld, SEQ=%ld",
John Hughes38ae88d2002-05-23 11:48:58 +0000887 m.discon_ind.DISCON_reason, m.discon_ind.SEQ_number);
888 break;
889#endif
890#ifdef T_DATA_IND
891 case T_DATA_IND: /* data indication */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200892 GET(T_DATA_IND, data_ind);
893 COMMA();
894 tprintf("MORE=%ld", m.data_ind.MORE_flag);
John Hughes38ae88d2002-05-23 11:48:58 +0000895 break;
896#endif
897#ifdef T_EXDATA_IND
898 case T_EXDATA_IND: /* expedited data ind */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200899 GET(T_EXDATA_IND, exdata_ind);
900 COMMA();
901 tprintf("MORE=%ld", m.exdata_ind.MORE_flag);
John Hughes38ae88d2002-05-23 11:48:58 +0000902 break;
903#endif
904#ifdef T_INFO_ACK
905 case T_INFO_ACK: /* info ack */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200906 GET(T_INFO_ACK, info_ack);
907 COMMA();
908 tprintf("TSDU=%ld, ETSDU=%ld, CDATA=%ld, DDATA=%ld, "
John Hughes38ae88d2002-05-23 11:48:58 +0000909 "ADDR=%ld, OPT=%ld, TIDU=%ld, SERV=",
910 m.info_ack.TSDU_size, m.info_ack.ETSDU_size,
911 m.info_ack.CDATA_size, m.info_ack.DDATA_size,
912 m.info_ack.ADDR_size, m.info_ack.OPT_size,
913 m.info_ack.TIDU_size);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200914 printxval(service_type, m.info_ack.SERV_type, "T_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200915 tprints(", CURRENT=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200916 printxval(ts_state, m.info_ack.CURRENT_state, "TS_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200917 tprints(", PROVIDER=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200918 printflags(provider_flags, m.info_ack.PROVIDER_flag, "???");
John Hughes38ae88d2002-05-23 11:48:58 +0000919 break;
920#endif
921#ifdef T_BIND_ACK
922 case T_BIND_ACK: /* bind ack */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200923 GET(T_BIND_ACK, bind_ack);
924 ADDR(bind_ack, ADDR);
925 tprintf(", CONIND=%ld", m.bind_ack.CONIND_number);
John Hughes38ae88d2002-05-23 11:48:58 +0000926 break;
927#endif
928#ifdef T_ERROR_ACK
929 case T_ERROR_ACK: /* error ack */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200930 GET(T_ERROR_ACK, error_ack);
931 COMMA();
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200932 tprints("ERROR=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200933 printxval(transport_user_options,
John Hughes38ae88d2002-05-23 11:48:58 +0000934 m.error_ack.ERROR_prim, "TI_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200935 tprints(", TLI=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200936 printxval(tli_errors, m.error_ack.TLI_error, "T???");
937 tprintf("UNIX=%s", strerror(m.error_ack.UNIX_error));
John Hughes38ae88d2002-05-23 11:48:58 +0000938 break;
939#endif
940#ifdef T_OK_ACK
941 case T_OK_ACK: /* ok ack */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200942 GET(T_OK_ACK, ok_ack);
943 COMMA();
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200944 tprints("CORRECT=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200945 printxval(transport_user_options,
John Hughes38ae88d2002-05-23 11:48:58 +0000946 m.ok_ack.CORRECT_prim, "TI_???");
947 break;
948#endif
949#ifdef T_UNITDATA_IND
950 case T_UNITDATA_IND: /* unitdata ind */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200951 GET(T_UNITDATA_IND, unitdata_ind);
952 ADDR(unitdata_ind, SRC);
953 ADDR(unitdata_ind, OPT);
John Hughes38ae88d2002-05-23 11:48:58 +0000954 break;
955#endif
956#ifdef T_UDERROR_IND
957 case T_UDERROR_IND: /* unitdata error ind */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200958 GET(T_UDERROR_IND, uderror_ind);
959 ADDR(uderror_ind, DEST);
960 ADDR(uderror_ind, OPT);
961 tprintf(", ERROR=%ld", m.uderror_ind.ERROR_type);
John Hughes38ae88d2002-05-23 11:48:58 +0000962 break;
963#endif
964#ifdef T_OPTMGMT_ACK
965 case T_OPTMGMT_ACK: /* manage opt ack */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200966 GET(T_OPTMGMT_ACK, optmgmt_ack);
967 COMMA();
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200968 tprints("MGMT=");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200969 printflags(transport_user_flags, m.optmgmt_ack.MGMT_flags,
Roland McGrathb2dee132005-06-01 19:02:36 +0000970 "T_???");
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200971 STRUCT(optmgmt_ack, OPT, print_optmgmt);
John Hughes38ae88d2002-05-23 11:48:58 +0000972 break;
973#endif
974#ifdef T_ORDREL_IND
975 case T_ORDREL_IND: /* orderly rel ind */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200976 GET(T_ORDREL_IND, ordrel_ind);
John Hughes38ae88d2002-05-23 11:48:58 +0000977 break;
978#endif
979#ifdef T_ADDR_REQ
980 case T_ADDR_REQ: /* address req */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200981 GET(T_ADDR_REQ, addr_req);
John Hughes38ae88d2002-05-23 11:48:58 +0000982 break;
983#endif
984#ifdef T_ADDR_ACK
985 case T_ADDR_ACK: /* address response */
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200986 GET(T_ADDR_ACK, addr_ack);
987 ADDR(addr_ack, LOCADDR);
988 ADDR(addr_ack, REMADDR);
John Hughes38ae88d2002-05-23 11:48:58 +0000989 break;
990#endif
991 default:
992 dump:
993 c = -1;
994 printstr(tcp, addr, len);
995 break;
996 }
997
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200998 if (c >= 0) tprints("}");
John Hughes38ae88d2002-05-23 11:48:58 +0000999
1000#undef ADDR
1001#undef COMMA
1002#undef STRUCT
Roland McGrath34e014a2002-12-16 20:40:59 +00001003
John Hughes38ae88d2002-05-23 11:48:58 +00001004 return 0;
1005}
1006
1007
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001008#endif /* TI_BIND */
1009
John Hughes38ae88d2002-05-23 11:48:58 +00001010
Dmitry V. Levine5e60852009-12-31 22:50:49 +00001011static int internal_stream_ioctl(struct tcb *tcp, int arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012{
1013 struct strioctl si;
Roland McGrath1c04b0b2004-01-13 10:18:46 +00001014 struct ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001015 int in_and_out;
John Hughes38ae88d2002-05-23 11:48:58 +00001016 int timod = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017#ifdef SI_GETUDATA
1018 struct si_udata udata;
1019#endif /* SI_GETUDATA */
1020
1021 if (!arg)
1022 return 0;
1023 if (umove(tcp, arg, &si) < 0) {
1024 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001025 tprints(", {...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001026 return 1;
1027 }
1028 if (entering(tcp)) {
Roland McGrath2843a4e2003-11-14 02:54:03 +00001029 iop = ioctl_lookup(si.ic_cmd);
1030 if (iop) {
1031 tprintf(", {ic_cmd=%s", iop->symbol);
1032 while ((iop = ioctl_next_match(iop)))
1033 tprintf(" or %s", iop->symbol);
1034 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001035 tprintf(", {ic_cmd=%#x", si.ic_cmd);
1036 if (si.ic_timout == INFTIM)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001037 tprints(", ic_timout=INFTIM, ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038 else
1039 tprintf(" ic_timout=%d, ", si.ic_timout);
1040 }
1041 in_and_out = 1;
1042 switch (si.ic_cmd) {
1043#ifdef SI_GETUDATA
1044 case SI_GETUDATA:
1045 in_and_out = 0;
1046 break;
1047#endif /* SI_GETUDATA */
1048 }
1049 if (in_and_out) {
1050 if (entering(tcp))
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001051 tprints("/* in */ ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001052 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001053 tprints(", /* out */ ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001054 }
1055 if (in_and_out || entering(tcp))
1056 tprintf("ic_len=%d, ic_dp=", si.ic_len);
1057 switch (si.ic_cmd) {
1058#ifdef TI_BIND
1059 case TI_BIND:
1060 /* in T_BIND_REQ, out T_BIND_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001061 ++timod;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001062 if (entering(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001063 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001064 T_BIND_REQ,
1065 si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001066 }
1067 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001068 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001069 T_BIND_ACK,
1070 si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071 }
1072 break;
1073#endif /* TI_BIND */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001074#ifdef TI_UNBIND
1075 case TI_UNBIND:
1076 /* in T_UNBIND_REQ, out T_OK_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001077 ++timod;
1078 if (entering(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001079 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001080 T_UNBIND_REQ,
1081 si.ic_dp, si.ic_len);
1082 }
1083 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001084 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001085 T_OK_ACK,
1086 si.ic_dp, si.ic_len);
1087 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001088 break;
1089#endif /* TI_UNBIND */
1090#ifdef TI_GETINFO
1091 case TI_GETINFO:
1092 /* in T_INFO_REQ, out T_INFO_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001093 ++timod;
1094 if (entering(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001095 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001096 T_INFO_REQ,
1097 si.ic_dp, si.ic_len);
1098 }
1099 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001100 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001101 T_INFO_ACK,
1102 si.ic_dp, si.ic_len);
1103 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001104 break;
1105#endif /* TI_GETINFO */
1106#ifdef TI_OPTMGMT
1107 case TI_OPTMGMT:
1108 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001109 ++timod;
1110 if (entering(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001111 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001112 T_OPTMGMT_REQ,
1113 si.ic_dp, si.ic_len);
1114 }
1115 else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001116 print_transport_message(tcp,
John Hughes38ae88d2002-05-23 11:48:58 +00001117 T_OPTMGMT_ACK,
1118 si.ic_dp, si.ic_len);
1119 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001120 break;
1121#endif /* TI_OPTMGMT */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001122#ifdef SI_GETUDATA
1123 case SI_GETUDATA:
1124 if (entering(tcp))
1125 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001126 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001127 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001128 else {
1129 tprintf("{tidusize=%d, addrsize=%d, ",
1130 udata.tidusize, udata.addrsize);
1131 tprintf("optsize=%d, etsdusize=%d, ",
1132 udata.optsize, udata.etsdusize);
1133 tprintf("servtype=%d, so_state=%d, ",
1134 udata.servtype, udata.so_state);
1135 tprintf("so_options=%d", udata.so_options);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001136 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001137 }
1138 break;
1139#endif /* SI_GETUDATA */
1140 default:
Michal Ludvig10a88d02002-10-07 14:31:00 +00001141 printstr(tcp, (long) si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001142 break;
1143 }
John Hughes38ae88d2002-05-23 11:48:58 +00001144 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001145 tprints("}");
Dmitry V. Levin21a75342008-09-03 01:22:18 +00001146 if (timod && tcp->u_rval && !syserror(tcp)) {
Denys Vlasenkob63256e2011-06-07 12:13:24 +02001147 tcp->auxstr = xlookup(tli_errors, tcp->u_rval);
John Hughes38ae88d2002-05-23 11:48:58 +00001148 return RVAL_STR + 1;
1149 }
1150 }
Roland McGrath34e014a2002-12-16 20:40:59 +00001151
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001152 return 1;
1153}
1154
1155int
Denys Vlasenko12014262011-05-30 14:00:14 +02001156stream_ioctl(struct tcb *tcp, int code, int arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001157{
1158#ifdef I_LIST
1159 int i;
1160#endif
1161 int val;
1162#ifdef I_FLUSHBAND
1163 struct bandinfo bi;
1164#endif
1165 struct strpeek sp;
1166 struct strfdinsert sfi;
1167 struct strrecvfd srf;
1168#ifdef I_LIST
1169 struct str_list sl;
1170#endif
1171
1172 /* I_STR is a special case because the data is read & written. */
1173 if (code == I_STR)
1174 return internal_stream_ioctl(tcp, arg);
1175 if (entering(tcp))
1176 return 0;
1177
1178 switch (code) {
1179 case I_PUSH:
1180 case I_LOOK:
1181 case I_FIND:
1182 /* arg is a string */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001183 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001184 printpath(tcp, arg);
1185 return 1;
1186 case I_POP:
1187 /* doesn't take an argument */
1188 return 1;
1189 case I_FLUSH:
1190 /* argument is an option */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001191 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001192 printxval(stream_flush_options, arg, "FLUSH???");
1193 return 1;
1194#ifdef I_FLUSHBAND
1195 case I_FLUSHBAND:
1196 /* argument is a pointer to a bandinfo struct */
1197 if (umove(tcp, arg, &bi) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001198 tprints(", {...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001199 else {
1200 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
Roland McGrathb2dee132005-06-01 19:02:36 +00001201 printflags(stream_flush_options, bi.bi_flag, "FLUSH???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001202 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001203 }
1204 return 1;
1205#endif /* I_FLUSHBAND */
1206 case I_SETSIG:
1207 /* argument is a set of flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001208 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001209 printflags(stream_setsig_flags, arg, "S_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001210 return 1;
1211 case I_GETSIG:
1212 /* argument is a pointer to a set of flags */
1213 if (syserror(tcp))
1214 return 0;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001215 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001216 if (umove(tcp, arg, &val) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001217 tprints("?");
Roland McGrathb2dee132005-06-01 19:02:36 +00001218 else
1219 printflags(stream_setsig_flags, val, "S_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001220 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001221 return 1;
1222 case I_PEEK:
1223 /* argument is a pointer to a strpeek structure */
1224 if (syserror(tcp) || !arg)
1225 return 0;
1226 if (umove(tcp, arg, &sp) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001227 tprints(", {...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001228 return 1;
1229 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001230 tprints(", {ctlbuf=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001231 printstrbuf(tcp, &sp.ctlbuf, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001232 tprints(", databuf=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001233 printstrbuf(tcp, &sp.databuf, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001234 tprints(", flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001235 printflags(msgflags, sp.flags, "RS_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001236 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001237 return 1;
1238 case I_SRDOPT:
1239 /* argument is an option with flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001240 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001241 printxval(stream_read_options, arg & RMODEMASK, "R???");
1242 addflags(stream_read_flags, arg & ~RMODEMASK);
1243 return 1;
1244 case I_GRDOPT:
1245 /* argument is an pointer to an option with flags */
1246 if (syserror(tcp))
1247 return 0;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001248 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001249 if (umove(tcp, arg, &val) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001250 tprints("?");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001251 else {
1252 printxval(stream_read_options,
1253 arg & RMODEMASK, "R???");
1254 addflags(stream_read_flags, arg & ~RMODEMASK);
1255 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001256 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001257 return 1;
1258 case I_NREAD:
1259#ifdef I_GETBAND
1260 case I_GETBAND:
1261#endif
1262#ifdef I_SETCLTIME
1263 case I_SETCLTIME:
1264#endif
1265#ifdef I_GETCLTIME
1266 case I_GETCLTIME:
1267#endif
1268 /* argument is a pointer to a decimal integer */
1269 if (syserror(tcp))
1270 return 0;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001271 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001272 printnum(tcp, arg, "%d");
1273 return 1;
1274 case I_FDINSERT:
1275 /* argument is a pointer to a strfdinsert structure */
1276 if (syserror(tcp) || !arg)
1277 return 0;
1278 if (umove(tcp, arg, &sfi) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001279 tprints(", {...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001280 return 1;
1281 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001282 tprints(", {ctlbuf=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001283 printstrbuf(tcp, &sfi.ctlbuf, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001284 tprints(", databuf=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001285 printstrbuf(tcp, &sfi.databuf, 1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001286 tprints(", flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001287 printflags(msgflags, sfi.flags, "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001288 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
1289 return 1;
1290#ifdef I_SWROPT
1291 case I_SWROPT:
1292 /* argument is a set of flags */
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001293 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001294 printflags(stream_write_flags, arg, "SND???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001295 return 1;
1296#endif /* I_SWROPT */
1297#ifdef I_GWROPT
1298 case I_GWROPT:
1299 /* argument is an pointer to an option with flags */
1300 if (syserror(tcp))
1301 return 0;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001302 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001303 if (umove(tcp, arg, &val) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001304 tprints("?");
Roland McGrathb2dee132005-06-01 19:02:36 +00001305 else
1306 printflags(stream_write_flags, arg, "SND???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001307 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001308 return 1;
1309#endif /* I_GWROPT */
1310 case I_SENDFD:
1311#ifdef I_CKBAND
1312 case I_CKBAND:
1313#endif
1314#ifdef I_CANPUT
1315 case I_CANPUT:
1316#endif
1317 case I_LINK:
1318 case I_UNLINK:
1319 case I_PLINK:
1320 case I_PUNLINK:
1321 /* argument is a decimal integer */
1322 tprintf(", %d", arg);
1323 return 1;
1324 case I_RECVFD:
1325 /* argument is a pointer to a strrecvfd structure */
1326 if (syserror(tcp) || !arg)
1327 return 0;
1328 if (umove(tcp, arg, &srf) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001329 tprints(", {...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001330 return 1;
1331 }
1332 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
1333 (unsigned long) srf.uid, (unsigned long) srf.gid);
1334 return 1;
1335#ifdef I_LIST
1336 case I_LIST:
1337 if (syserror(tcp))
1338 return 0;
1339 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001340 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001341 return 1;
1342 }
1343 if (umove(tcp, arg, &sl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001344 tprints(", {...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001345 return 1;
1346 }
1347 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
1348 for (i = 0; i < tcp->u_rval; i++) {
1349 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001350 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001351 printpath(tcp, (int) sl.sl_modlist[i].l_name);
1352 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001353 tprints("]}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001354 return 1;
1355#endif /* I_LIST */
1356#ifdef I_ATMARK
1357 case I_ATMARK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001358 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001359 printxval(stream_atmark_options, arg, "???MARK");
1360 return 1;
1361#endif /* I_ATMARK */
1362 default:
1363 return 0;
1364 }
1365}
1366
Roland McGrath561c7992003-04-02 01:10:44 +00001367#endif /* !LINUX && !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001368
Roland McGrath561c7992003-04-02 01:10:44 +00001369#endif /* HAVE_SYS_STREAM_H || LINUX || FREEBSD */