Annotation of src/usr.bin/kdump/ktrstruct.c, Revision 1.30
1.30 ! mbuhl 1: /* $OpenBSD: ktrstruct.c,v 1.29 2020/12/21 07:47:37 otto Exp $ */
1.1 guenther 2:
3: /*-
4: * Copyright (c) 1988, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. Neither the name of the University nor the names of its contributors
16: * may be used to endorse or promote products derived from this software
17: * without specific prior written permission.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: * SUCH DAMAGE.
30: */
31:
32: #include <sys/types.h>
33: #include <sys/resource.h>
34: #include <sys/socket.h>
1.22 guenther 35: #include <sys/select.h>
1.1 guenther 36: #include <sys/stat.h>
37: #include <sys/time.h>
1.14 tedu 38: #include <sys/event.h>
1.1 guenther 39: #include <sys/un.h>
1.26 anton 40: #include <sys/fcntl.h>
1.6 guenther 41: #include <ufs/ufs/quota.h>
1.1 guenther 42: #include <netinet/in.h>
43: #include <arpa/inet.h>
44:
45: #include <ctype.h>
46: #include <err.h>
47: #include <limits.h>
1.10 guenther 48: #include <netdb.h>
1.1 guenther 49: #include <poll.h>
50: #include <signal.h>
1.13 guenther 51: #include <stddef.h>
1.1 guenther 52: #include <stdio.h>
53: #include <stdlib.h>
54: #include <stdint.h>
55: #include <string.h>
56: #include <grp.h>
57: #include <pwd.h>
58: #include <unistd.h>
1.18 guenther 59: #include <vis.h>
1.1 guenther 60:
61: #include "kdump.h"
62: #include "kdump_subr.h"
63:
64: #define TIME_FORMAT "%b %e %T %Y"
65:
66: static void
67: ktrsockaddr(struct sockaddr *sa)
68: {
1.18 guenther 69: /*
70: * TODO: Support additional address families
71: * #include <netmpls/mpls.h>
72: * struct sockaddr_mpls *mpls;
73: */
1.1 guenther 74:
75: /*
76: * note: ktrstruct() has already verified that sa points to a
77: * buffer at least sizeof(struct sockaddr) bytes long and exactly
78: * sa->sa_len bytes long.
79: */
80: printf("struct sockaddr { ");
81: sockfamilyname(sa->sa_family);
82: printf(", ");
83:
84: #define check_sockaddr_len(n) \
85: if (sa_##n->s##n##_len < sizeof(struct sockaddr_##n)) { \
86: printf("invalid"); \
87: break; \
88: }
89:
90: switch(sa->sa_family) {
91: case AF_INET: {
92: struct sockaddr_in *sa_in;
1.29 otto 93: char addr[INET_ADDRSTRLEN];
1.1 guenther 94:
95: sa_in = (struct sockaddr_in *)sa;
96: check_sockaddr_len(in);
97: inet_ntop(AF_INET, &sa_in->sin_addr, addr, sizeof addr);
98: printf("%s:%u", addr, ntohs(sa_in->sin_port));
99: break;
100: }
101: case AF_INET6: {
102: struct sockaddr_in6 *sa_in6;
1.29 otto 103: char addr[INET6_ADDRSTRLEN], scope[12] = { 0 };
1.1 guenther 104:
105: sa_in6 = (struct sockaddr_in6 *)sa;
106: check_sockaddr_len(in6);
107: inet_ntop(AF_INET6, &sa_in6->sin6_addr, addr, sizeof addr);
1.29 otto 108: if (sa_in6->sin6_scope_id)
109: snprintf(scope, sizeof(scope), "%%%u",
110: sa_in6->sin6_scope_id);
111: printf("[%s%s]:%u", addr, scope, htons(sa_in6->sin6_port));
1.1 guenther 112: break;
113: }
114: case AF_UNIX: {
115: struct sockaddr_un *sa_un;
1.18 guenther 116: char path[4 * sizeof(sa_un->sun_path) + 1];
117: size_t len;
1.1 guenther 118:
119: sa_un = (struct sockaddr_un *)sa;
1.18 guenther 120: len = sa_un->sun_len;
121: if (len <= offsetof(struct sockaddr_un, sun_path)) {
1.1 guenther 122: printf("invalid");
123: break;
124: }
1.18 guenther 125: len -= offsetof(struct sockaddr_un, sun_path);
126: if (len > sizeof(sa_un->sun_path)) {
127: printf("too long");
128: break;
129: }
130: /* format, stopping at first NUL */
131: len = strnlen(sa_un->sun_path, len);
132: strvisx(path, sa_un->sun_path, len,
133: VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL);
134: printf("\"%s\"", path);
1.1 guenther 135: break;
136: }
137: default:
138: printf("unknown address family");
139: }
140: printf(" }\n");
141: }
142:
143: static void
1.8 guenther 144: print_time(time_t t, int relative, int have_subsec)
1.1 guenther 145: {
146: char timestr[PATH_MAX + 4];
147: struct tm *tm;
148:
1.8 guenther 149: if (t < 0 && have_subsec) {
150: /* negative times with non-zero subsecs require care */
151: printf("-%jd", -(intmax_t)(t + 1));
152: } else
1.1 guenther 153: printf("%jd", (intmax_t)t);
1.8 guenther 154:
1.20 tedu 155: /* 1970s times are probably relative */
156: if (!relative && t > (10 * 365 * 24 * 3600)) {
1.1 guenther 157: tm = localtime(&t);
1.9 jsg 158: if (tm != NULL) {
159: (void)strftime(timestr, sizeof(timestr), TIME_FORMAT,
160: tm);
161: printf("<\"%s\">", timestr);
162: }
1.1 guenther 163: }
164: }
165:
166: static void
167: print_timespec(const struct timespec *tsp, int relative)
168: {
1.2 guenther 169: if (tsp->tv_nsec == UTIME_NOW)
170: printf("UTIME_NOW");
171: else if (tsp->tv_nsec == UTIME_OMIT)
172: printf("UTIME_OMIT");
1.8 guenther 173: else {
174: print_time(tsp->tv_sec, relative, tsp->tv_nsec);
1.2 guenther 175: if (tsp->tv_nsec != 0)
1.8 guenther 176: printf(".%09ld", tsp->tv_sec >= 0 ? tsp->tv_nsec :
177: 1000000000 - tsp->tv_nsec);
178: }
179: }
180:
181: void
182: uidname(int uid)
183: {
184: const char *name;
185:
186: if (uid == -1)
187: printf("-1");
188: else {
189: printf("%u<", (unsigned)uid);
190: if (uid > UID_MAX || (name = user_from_uid(uid, 1)) == NULL)
191: printf("unknown>");
192: else
193: printf("\"%s\">", name);
194: }
195: }
196:
197: void
198: gidname(int gid)
199: {
200: const char *name;
201:
202: if (gid == -1)
203: printf("-1");
204: else {
205: printf("%u<", (unsigned)gid);
206: if (gid > GID_MAX || (name = group_from_gid(gid, 1)) == NULL)
207: printf("unknown>");
208: else
209: printf("\"%s\">", name);
1.2 guenther 210: }
1.1 guenther 211: }
212:
213: static void
214: ktrstat(const struct stat *statp)
215: {
216: char mode[12];
217:
218: /*
219: * note: ktrstruct() has already verified that statp points to a
220: * buffer exactly sizeof(struct stat) bytes long.
221: */
222: printf("struct stat { ");
223: strmode(statp->st_mode, mode);
1.8 guenther 224: printf("dev=%d, ino=%llu, mode=%s, nlink=%u, uid=",
1.1 guenther 225: statp->st_dev, (unsigned long long)statp->st_ino,
226: mode, statp->st_nlink);
1.8 guenther 227: uidname(statp->st_uid);
228: printf(", gid=");
229: gidname(statp->st_gid);
230: printf(", rdev=%d, ", statp->st_rdev);
1.1 guenther 231: printf("atime=");
232: print_timespec(&statp->st_atim, 0);
233: printf(", mtime=");
234: print_timespec(&statp->st_mtim, 0);
235: printf(", ctime=");
236: print_timespec(&statp->st_ctim, 0);
1.7 krw 237: printf(", size=%lld, blocks=%lld, blksize=%d, flags=0x%x, gen=0x%x",
1.1 guenther 238: statp->st_size, statp->st_blocks, statp->st_blksize,
239: statp->st_flags, statp->st_gen);
240: printf(" }\n");
241: }
242:
243: static void
244: ktrtimespec(const struct timespec *tsp, int relative)
245: {
246: printf("struct timespec { ");
247: print_timespec(tsp, relative);
248: printf(" }\n");
249: }
250:
251: static void
1.3 guenther 252: print_timeval(const struct timeval *tvp, int relative)
1.1 guenther 253: {
1.8 guenther 254: print_time(tvp->tv_sec, relative, tvp->tv_usec);
255: if (tvp->tv_usec != 0)
256: printf(".%06ld", tvp->tv_sec >= 0 ? tvp->tv_usec :
1.4 guenther 257: 1000000 - tvp->tv_usec);
1.3 guenther 258: }
259:
260: static void
261: ktrtimeval(const struct timeval *tvp, int relative)
262: {
263: printf("struct timeval { ");
264: print_timeval(tvp, relative);
1.1 guenther 265: printf(" }\n");
266: }
267:
268: static void
269: ktrsigaction(const struct sigaction *sa)
270: {
271: /*
272: * note: ktrstruct() has already verified that sa points to a
273: * buffer exactly sizeof(struct sigaction) bytes long.
274: */
1.19 guenther 275: /*
276: * Fuck! Comparison of function pointers on hppa assumes you can
277: * dereference them if they're plabels! Cast everything to void *
278: * to suppress that extra logic; sorry folks, the address we report
279: * here might not match what you see in your executable...
280: */
1.1 guenther 281: printf("struct sigaction { ");
1.19 guenther 282: if ((void *)sa->sa_handler == (void *)SIG_DFL)
1.1 guenther 283: printf("handler=SIG_DFL");
1.19 guenther 284: else if ((void *)sa->sa_handler == (void *)SIG_IGN)
1.1 guenther 285: printf("handler=SIG_IGN");
286: else if (sa->sa_flags & SA_SIGINFO)
287: printf("sigaction=%p", (void *)sa->sa_sigaction);
288: else
289: printf("handler=%p", (void *)sa->sa_handler);
290: printf(", mask=");
291: sigset(sa->sa_mask);
292: printf(", flags=");
293: sigactionflagname(sa->sa_flags);
294: printf(" }\n");
295: }
296:
297: static void
298: print_rlim(rlim_t lim)
299: {
300: if (lim == RLIM_INFINITY)
301: printf("infinite");
302: else
303: printf("%llu", (unsigned long long)lim);
304: }
305:
306: static void
307: ktrrlimit(const struct rlimit *limp)
308: {
309: printf("struct rlimit { ");
310: printf("cur=");
311: print_rlim(limp->rlim_cur);
312: printf(", max=");
313: print_rlim(limp->rlim_max);
314: printf(" }\n");
315: }
316:
317: static void
318: ktrtfork(const struct __tfork *tf)
319: {
320: printf("struct __tfork { tcb=%p, tid=%p, stack=%p }\n",
321: tf->tf_tcb, (void *)tf->tf_tid, tf->tf_stack);
322: }
323:
324: static void
1.23 guenther 325: ktrfds(const char *data, size_t count)
326: {
327: size_t i;
328: int fd;
329:
1.27 otto 330: printf("int");
331: if (count > 1)
332: printf(" [%zu] { ", count);
333: for (i = 0; i < count; i++) {
1.23 guenther 334: memcpy(&fd, &data[i * sizeof(fd)], sizeof(fd));
1.27 otto 335: printf("%d%s", fd, i < count - 1 ? ", " : "");
1.23 guenther 336: }
1.27 otto 337: if (count > 1)
338: printf(" }");
339: printf("\n");
1.23 guenther 340: }
341:
342: static void
1.17 guenther 343: ktrfdset(struct fd_set *fds, int len)
1.1 guenther 344: {
345: int nfds, i, start = -1;
346: char sep = ' ';
347:
348: nfds = len * NBBY;
349: printf("struct fd_set {");
350: for (i = 0; i <= nfds; i++)
351: if (i != nfds && FD_ISSET(i, fds)) {
352: if (start == -1)
353: start = i;
354: } else if (start != -1) {
355: putchar(sep);
356: if (start == i - 1)
357: printf("%d", start);
358: else if (start == i - 2)
359: printf("%d,%d", start, i - 1);
360: else
361: printf("%d-%d", start, i - 1);
362: sep = ',';
363: start = -1;
364: }
365:
366: printf(" }\n");
367: }
368:
1.3 guenther 369: static void
370: ktrrusage(const struct rusage *rup)
371: {
372: printf("struct rusage { utime=");
373: print_timeval(&rup->ru_utime, 1);
374: printf(", stime=");
375: print_timeval(&rup->ru_stime, 1);
376: printf(", maxrss=%ld, ixrss=%ld, idrss=%ld, isrss=%ld,"
377: " minflt=%ld, majflt=%ld, nswap=%ld, inblock=%ld,"
378: " oublock=%ld, msgsnd=%ld, msgrcv=%ld, nsignals=%ld,"
379: " nvcsw=%ld, nivcsw=%ld }\n",
380: rup->ru_maxrss, rup->ru_ixrss, rup->ru_idrss, rup->ru_isrss,
381: rup->ru_minflt, rup->ru_majflt, rup->ru_nswap, rup->ru_inblock,
382: rup->ru_oublock, rup->ru_msgsnd, rup->ru_msgrcv, rup->ru_nsignals,
383: rup->ru_nvcsw, rup->ru_nivcsw);
384: }
385:
1.6 guenther 386: static void
387: ktrquota(const struct dqblk *quota)
388: {
389: printf("struct dqblk { bhardlimit=%u, bsoftlimit=%u, curblocks=%u,"
390: " ihardlimit=%u, isoftlimit=%u, curinodes=%u, btime=",
391: quota->dqb_bhardlimit, quota->dqb_bsoftlimit,
392: quota->dqb_curblocks, quota->dqb_ihardlimit,
393: quota->dqb_isoftlimit, quota->dqb_curinodes);
1.8 guenther 394: print_time(quota->dqb_btime, 0, 0);
1.6 guenther 395: printf(", itime=");
1.8 guenther 396: print_time(quota->dqb_itime, 0, 0);
1.6 guenther 397: printf(" }\n");
398: }
399:
1.10 guenther 400: static void
1.30 ! mbuhl 401: ktrmmsghdr(const struct mmsghdr *mmsg)
! 402: {
! 403: printf("struct mmsghdr { msg_hdr = { name=%p, namelen=%u, "
! 404: "iov=%p, iovlen=%u, control=%p, controllen=%u, flags=",
! 405: mmsg->msg_hdr.msg_name, mmsg->msg_hdr.msg_namelen,
! 406: mmsg->msg_hdr.msg_iov, mmsg->msg_hdr.msg_iovlen,
! 407: mmsg->msg_hdr.msg_control, mmsg->msg_hdr.msg_controllen);
! 408: sendrecvflagsname(mmsg->msg_hdr.msg_flags);
! 409: printf(" }, msg_len = %u }\n", mmsg->msg_len);
! 410: }
! 411:
! 412: static void
1.10 guenther 413: ktrmsghdr(const struct msghdr *msg)
414: {
415: printf("struct msghdr { name=%p, namelen=%u, iov=%p, iovlen=%u,"
1.16 guenther 416: " control=%p, controllen=%u, flags=",
1.10 guenther 417: msg->msg_name, msg->msg_namelen, msg->msg_iov, msg->msg_iovlen,
1.16 guenther 418: msg->msg_control, msg->msg_controllen);
419: sendrecvflagsname(msg->msg_flags);
420: printf(" }\n");
1.10 guenther 421: }
422:
423: static void
424: ktriovec(const char *data, int count)
425: {
426: struct iovec iov;
427: int i;
428:
429: printf("struct iovec");
430: if (count > 1)
431: printf(" [%d]", count);
432: for (i = 0; i < count; i++) {
433: memcpy(&iov, data, sizeof(iov));
434: data += sizeof(iov);
435: printf(" { base=%p, len=%lu }", iov.iov_base, iov.iov_len);
436: }
437: printf("\n");
438: }
439:
440: static void
1.14 tedu 441: ktrevent(const char *data, int count)
442: {
443: struct kevent kev;
444: int i;
445:
446: printf("struct kevent");
447: if (count > 1)
448: printf(" [%d]", count);
449: for (i = 0; i < count; i++) {
450: memcpy(&kev, data, sizeof(kev));
451: data += sizeof(kev);
1.16 guenther 452: printf(" { ident=%lu, filter=", kev.ident);
453: evfiltername(kev.filter);
454: printf(", flags=");
455: evflagsname(kev.flags);
456: printf(", fflags=");
457: evfflagsname(kev.filter, kev.fflags);
458: printf(", data=%llu", kev.data);
459: if ((kev.flags & EV_ERROR) && fancy) {
460: printf("<\"%s\">", strerror(kev.data));
1.15 tedu 461: }
1.16 guenther 462: printf(", udata=%p }", kev.udata);
1.14 tedu 463: }
464: printf("\n");
465: }
466:
467: static void
1.21 deraadt 468: ktrpollfd(const char *data, int count)
469: {
470: struct pollfd pfd;
471: int i;
472:
473: printf("struct pollfd");
474: if (count > 1)
475: printf(" [%d]", count);
476: for (i = 0; i < count; i++) {
477: memcpy(&pfd, data, sizeof(pfd));
478: data += sizeof(pfd);
479: printf(" { fd=%d, events=", pfd.fd);
480: pollfdeventname(pfd.events);
481: printf(", revents=");
482: pollfdeventname(pfd.revents);
483: printf(" }");
484: }
485: printf("\n");
486: }
487:
488: static void
1.10 guenther 489: ktrcmsghdr(char *data, socklen_t len)
490: {
491: struct msghdr msg;
492: struct cmsghdr *cmsg;
493: int i, count, *fds;
494:
495: msg.msg_control = data;
496: msg.msg_controllen = len;
497:
498: /* count the control messages */
499: count = 0;
500: for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
501: cmsg = CMSG_NXTHDR(&msg, cmsg)) {
502: count++;
503: }
504:
505: printf("struct cmsghdr");
506: if (count > 1)
507: printf(" [%d]", count);
508:
509: for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
510: cmsg = CMSG_NXTHDR(&msg, cmsg)) {
511: printf(" { len=%u, level=", cmsg->cmsg_len);
512: if (cmsg->cmsg_level == SOL_SOCKET) {
513: printf("SOL_SOCKET, type=");
514: switch (cmsg->cmsg_type) {
515: case SCM_RIGHTS:
516: printf("SCM_RIGHTS, data=");
517: fds = (int *)CMSG_DATA(cmsg);
518: for (i = 0;
1.28 claudio 519: cmsg->cmsg_len > CMSG_LEN(sizeof(int) * i)
520: && (char *)fds + (i + 1) * sizeof(int) <=
521: data + len;
1.10 guenther 522: i++) {
523: printf("%s%d", i ? "," : "", fds[i]);
524: }
525: break;
526: case SCM_TIMESTAMP:
527: default:
528: printf("%d", cmsg->cmsg_type);
529: break;
530: }
531: } else {
532: struct protoent *p = getprotobynumber(cmsg->cmsg_level);
533:
534: printf("%u<%s>, type=%d", cmsg->cmsg_level,
535: p != NULL ? p->p_name : "unknown", cmsg->cmsg_type);
536: }
537: printf(" }");
538: }
539: printf("\n");
540: }
541:
1.26 anton 542: static void
543: ktrflock(const struct flock *fl)
544: {
545: printf("struct flock { start=%lld, len=%lld, pid=%d, type=",
546: fl->l_start, fl->l_len, fl->l_pid);
547: flocktypename(fl->l_type);
548: printf(", whence=");
549: whencename(fl->l_whence);
550: printf(" }\n");
551: }
552:
1.1 guenther 553: void
554: ktrstruct(char *buf, size_t buflen)
555: {
556: char *name, *data;
557: size_t namelen, datalen;
558: int i;
559:
560: for (name = buf, namelen = 0; namelen < buflen && name[namelen] != '\0';
561: ++namelen)
562: /* nothing */;
563: if (namelen == buflen)
564: goto invalid;
565: if (name[namelen] != '\0')
566: goto invalid;
567: data = buf + namelen + 1;
568: datalen = buflen - namelen - 1;
1.27 otto 569:
1.1 guenther 570: /* sanity check */
571: for (i = 0; i < namelen; ++i)
572: if (!isalpha((unsigned char)name[i]))
573: goto invalid;
574: if (strcmp(name, "stat") == 0) {
575: struct stat sb;
576:
577: if (datalen != sizeof(struct stat))
578: goto invalid;
579: memcpy(&sb, data, datalen);
580: ktrstat(&sb);
581: } else if (strcmp(name, "sockaddr") == 0) {
582: struct sockaddr_storage ss;
583:
584: if (datalen > sizeof(ss))
585: goto invalid;
1.27 otto 586: if (datalen < offsetof(struct sockaddr_storage, ss_len) +
587: sizeof(ss.ss_len))
588: goto invalid;
1.1 guenther 589: memcpy(&ss, data, datalen);
590: if ((ss.ss_family != AF_UNIX &&
591: datalen < sizeof(struct sockaddr)) || datalen != ss.ss_len)
592: goto invalid;
593: ktrsockaddr((struct sockaddr *)&ss);
594: } else if (strcmp(name, "abstimespec") == 0 ||
595: strcmp(name, "reltimespec") == 0) {
596: struct timespec ts;
597:
598: if (datalen != sizeof(ts))
599: goto invalid;
600: memcpy(&ts, data, datalen);
601: ktrtimespec(&ts, name[0] == 'r');
602: } else if (strcmp(name, "abstimeval") == 0 ||
603: strcmp(name, "reltimeval") == 0) {
604: struct timeval tv;
605:
606: if (datalen != sizeof(tv))
607: goto invalid;
608: memcpy(&tv, data, datalen);
609: ktrtimeval(&tv, name[0] == 'r');
610: } else if (strcmp(name, "sigaction") == 0) {
611: struct sigaction sa;
612:
613: if (datalen != sizeof(sa))
614: goto invalid;
615: memcpy(&sa, data, datalen);
616: ktrsigaction(&sa);
617: } else if (strcmp(name, "rlimit") == 0) {
618: struct rlimit lim;
619:
620: if (datalen != sizeof(lim))
621: goto invalid;
622: memcpy(&lim, data, datalen);
623: ktrrlimit(&lim);
1.3 guenther 624: } else if (strcmp(name, "rusage") == 0) {
625: struct rusage ru;
626:
627: if (datalen != sizeof(ru))
628: goto invalid;
629: memcpy(&ru, data, datalen);
630: ktrrusage(&ru);
1.1 guenther 631: } else if (strcmp(name, "tfork") == 0) {
632: struct __tfork tf;
633:
634: if (datalen != sizeof(tf))
635: goto invalid;
636: memcpy(&tf, data, datalen);
637: ktrtfork(&tf);
1.23 guenther 638: } else if (strcmp(name, "fds") == 0) {
639: if (datalen % sizeof(int))
640: goto invalid;
641: ktrfds(data, datalen / sizeof(int));
1.1 guenther 642: } else if (strcmp(name, "fdset") == 0) {
643: struct fd_set *fds;
1.10 guenther 644:
1.1 guenther 645: if ((fds = malloc(datalen)) == NULL)
646: err(1, "malloc");
647: memcpy(fds, data, datalen);
648: ktrfdset(fds, datalen);
649: free(fds);
1.6 guenther 650: } else if (strcmp(name, "quota") == 0) {
651: struct dqblk quota;
652:
653: if (datalen != sizeof(quota))
654: goto invalid;
655: memcpy("a, data, datalen);
656: ktrquota("a);
1.10 guenther 657: } else if (strcmp(name, "msghdr") == 0) {
658: struct msghdr msg;
659:
660: if (datalen != sizeof(msg))
661: goto invalid;
662: memcpy(&msg, data, datalen);
663: ktrmsghdr(&msg);
1.30 ! mbuhl 664: } else if (strcmp(name, "mmsghdr") == 0) {
! 665: struct mmsghdr mmsg;
! 666:
! 667: if (datalen != sizeof(mmsg))
! 668: goto invalid;
! 669: memcpy(&mmsg, data, datalen);
! 670: ktrmmsghdr(&mmsg);
1.10 guenther 671: } else if (strcmp(name, "iovec") == 0) {
672: if (datalen % sizeof(struct iovec))
673: goto invalid;
674: ktriovec(data, datalen / sizeof(struct iovec));
1.14 tedu 675: } else if (strcmp(name, "kevent") == 0) {
676: if (datalen % sizeof(struct kevent))
677: goto invalid;
678: ktrevent(data, datalen / sizeof(struct kevent));
1.21 deraadt 679: } else if (strcmp(name, "pollfd") == 0) {
680: if (datalen % sizeof(struct pollfd))
681: goto invalid;
682: ktrpollfd(data, datalen / sizeof(struct pollfd));
1.10 guenther 683: } else if (strcmp(name, "cmsghdr") == 0) {
684: char *cmsg;
1.27 otto 685:
686: if (datalen == 0)
687: goto invalid;
1.10 guenther 688:
689: if ((cmsg = malloc(datalen)) == NULL)
690: err(1, "malloc");
691: memcpy(cmsg, data, datalen);
692: ktrcmsghdr(cmsg, datalen);
693: free(cmsg);
1.12 deraadt 694: } else if (strcmp(name, "pledgereq") == 0) {
1.24 deraadt 695: printf("promise=");
696: showbufc(basecol + sizeof("promise=") - 1,
1.18 guenther 697: (unsigned char *)data, datalen, VIS_DQ | VIS_TAB | VIS_NL);
1.24 deraadt 698: } else if (strcmp(name, "pledgeexecreq") == 0) {
699: printf("execpromise=");
700: showbufc(basecol + sizeof("execpromise=") - 1,
1.25 beck 701: (unsigned char *)data, datalen, VIS_DQ | VIS_TAB | VIS_NL);
702: } else if (strcmp(name, "unveil") == 0) {
703: printf("flags=");
704: showbufc(basecol + sizeof("flags=") - 1,
1.18 guenther 705: (unsigned char *)data, datalen, VIS_DQ | VIS_TAB | VIS_NL);
1.26 anton 706: } else if (strcmp(name, "flock") == 0) {
707: struct flock fl;
708:
709: if (datalen != sizeof(fl))
710: goto invalid;
711: memcpy(&fl, data, datalen);
712: ktrflock(&fl);
1.1 guenther 713: } else {
714: printf("unknown structure %s\n", name);
715: }
716: return;
717: invalid:
718: printf("invalid record\n");
719: }