Module Name: src Committed By: kamil Date: Thu Apr 2 03:32:46 UTC 2020
Modified Files: src/distrib/sets/lists/base: mi src/distrib/sets/lists/man: mi src/usr.bin/kdump: Makefile kdump.c Added Files: src/usr.bin/kdump: ioctlprint.1 Log Message: Add ioctlprint - descriptive ioctl value printer ioctlprint(1) is embedded in the kdump(1) program. To generate a diff of this commit: cvs rdiff -u -r1.1235 -r1.1236 src/distrib/sets/lists/base/mi cvs rdiff -u -r1.1684 -r1.1685 src/distrib/sets/lists/man/mi cvs rdiff -u -r1.32 -r1.33 src/usr.bin/kdump/Makefile cvs rdiff -u -r0 -r1.1 src/usr.bin/kdump/ioctlprint.1 cvs rdiff -u -r1.132 -r1.133 src/usr.bin/kdump/kdump.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/base/mi diff -u src/distrib/sets/lists/base/mi:1.1235 src/distrib/sets/lists/base/mi:1.1236 --- src/distrib/sets/lists/base/mi:1.1235 Sun Mar 29 17:13:46 2020 +++ src/distrib/sets/lists/base/mi Thu Apr 2 03:32:46 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1235 2020/03/29 17:13:46 christos Exp $ +# $NetBSD: mi,v 1.1236 2020/04/02 03:32:46 kamil Exp $ # # Note: Don't delete entries from here - mark them as "obsolete" instead, # unless otherwise stated below. @@ -797,6 +797,7 @@ ./usr/bin/install base-util-bin ./usr/bin/install-info base-texinfo-bin ./usr/bin/install-sid base-gnats-bin +./usr/bin/ioctlprint base-debug-bin ./usr/bin/ipcrm base-util-bin ./usr/bin/ipcs base-util-bin ./usr/bin/join base-util-bin Index: src/distrib/sets/lists/man/mi diff -u src/distrib/sets/lists/man/mi:1.1684 src/distrib/sets/lists/man/mi:1.1685 --- src/distrib/sets/lists/man/mi:1.1684 Sun Mar 29 17:13:46 2020 +++ src/distrib/sets/lists/man/mi Thu Apr 2 03:32:46 2020 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1684 2020/03/29 17:13:46 christos Exp $ +# $NetBSD: mi,v 1.1685 2020/04/02 03:32:46 kamil Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -226,6 +226,7 @@ ./usr/share/man/cat1/install-info.0 man-texinfo-catman .cat ./usr/share/man/cat1/install.0 man-util-catman .cat ./usr/share/man/cat1/intro.0 man-sys-catman .cat +./usr/share/man/cat1/ioctlprint.0 man-debug-catman .cat ./usr/share/man/cat1/ipcrm.0 man-util-catman .cat ./usr/share/man/cat1/ipcs.0 man-util-catman .cat ./usr/share/man/cat1/ipftest.0 man-ipf-catman ipfilter,.cat @@ -3512,6 +3513,7 @@ ./usr/share/man/html1/install-info.html man-texinfo-htmlman html ./usr/share/man/html1/install.html man-util-htmlman html ./usr/share/man/html1/intro.html man-sys-htmlman html +./usr/share/man/html1/ioctlprint.html man-debug-htmlman html ./usr/share/man/html1/ipcrm.html man-util-htmlman html ./usr/share/man/html1/ipcs.html man-util-htmlman html ./usr/share/man/html1/ipftest.html man-ipf-htmlman ipfilter,html @@ -6436,6 +6438,7 @@ ./usr/share/man/man1/install-info.1 man-texinfo-man .man ./usr/share/man/man1/install.1 man-util-man .man ./usr/share/man/man1/intro.1 man-sys-man .man +./usr/share/man/man1/ioctlprint.1 man-debug-man .man ./usr/share/man/man1/ipcrm.1 man-util-man .man ./usr/share/man/man1/ipcs.1 man-util-man .man ./usr/share/man/man1/ipftest.1 man-ipf-man ipfilter,.man Index: src/usr.bin/kdump/Makefile diff -u src/usr.bin/kdump/Makefile:1.32 src/usr.bin/kdump/Makefile:1.33 --- src/usr.bin/kdump/Makefile:1.32 Sat Jan 23 21:22:49 2016 +++ src/usr.bin/kdump/Makefile Thu Apr 2 03:32:46 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.32 2016/01/23 21:22:49 christos Exp $ +# $NetBSD: Makefile,v 1.33 2020/04/02 03:32:46 kamil Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include <bsd.own.mk> # for MKDYNAMICROOT & NETBSDSRCDIR @@ -6,6 +6,8 @@ USE_FORT?= yes # cryptographic software PROG= kdump +LINKS= ${BINDIR}/kdump ${BINDIR}/ioctlprint +MAN= kdump.1 ioctlprint.1 SRCS= kdump.c subr.c setemul.c siginfo.c .PATH: ${NETBSDSRCDIR}/usr.bin/ktrace CLEANFILES+=siginfo.c Index: src/usr.bin/kdump/kdump.c diff -u src/usr.bin/kdump/kdump.c:1.132 src/usr.bin/kdump/kdump.c:1.133 --- src/usr.bin/kdump/kdump.c:1.132 Tue Jul 23 01:54:51 2019 +++ src/usr.bin/kdump/kdump.c Thu Apr 2 03:32:46 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: kdump.c,v 1.132 2019/07/23 01:54:51 nonaka Exp $ */ +/* $NetBSD: kdump.c,v 1.133 2020/04/02 03:32:46 kamil Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: kdump.c,v 1.132 2019/07/23 01:54:51 nonaka Exp $"); +__RCSID("$NetBSD: kdump.c,v 1.133 2020/04/02 03:32:46 kamil Exp $"); #endif #endif /* not lint */ @@ -58,6 +58,7 @@ __RCSID("$NetBSD: kdump.c,v 1.132 2019/0 #include <ctype.h> #include <err.h> +#include <inttypes.h> #include <signal.h> #include <stddef.h> #include <stdio.h> @@ -107,6 +108,9 @@ static const char * const linux_ptrace_o "PTRACE_SYSCALL", }; +static const char default_format[] = { "%n %e %x\n" }; + +static void fmtprint(const char *, unsigned long int); static int fread_tail(void *, size_t, size_t); static int dumpheader(struct ktr_header *); static int output_ts(const struct timespec *); @@ -132,25 +136,33 @@ static void visdump_buf(const void *, in int main(int argc, char **argv) { + unsigned long int u; unsigned int ktrlen, size; int ch; void *m; int trpoints = 0; int trset = 0; const char *emul_name = "netbsd"; + const char *format = default_format; int col; + int e; char *cp; setprogname(argv[0]); - if (strcmp(getprogname(), "ioctlname") == 0) { + if (strcmp(getprogname(), "ioctlprint") == 0) { int i; - while ((ch = getopt(argc, argv, "e:")) != -1) + while ((ch = getopt(argc, argv, "e:f:")) != -1) switch (ch) { case 'e': emul_name = optarg; break; + case 'f': + if (format != default_format) + errx(1, "Too many formats"); + format = optarg; + break; default: usage(); break; @@ -163,8 +175,10 @@ main(int argc, char **argv) usage(); for (i = 0; i < argc; i++) { - ioctldecode(strtoul(argv[i], NULL, 0)); - (void)putchar('\n'); + u = strtou(argv[i], NULL, 0, 0, ULONG_MAX, &e); + if (e) + errc(1, e, "invalid argument: `%s'", argv[i]); + fmtprint(format, u); } return 0; } @@ -323,6 +337,60 @@ main(int argc, char **argv) return (0); } +static void +fmtprint(const char *fmt, unsigned long int u) +{ + const char *name; + int c; + + while ((c = *fmt++) != '\0') { + switch (c) { + default: + putchar(c); + continue; + case '\\': + switch (c = *fmt) { + case '\0': + continue; + case 'n': + putchar('\n'); + break; + case 't': + putchar('\t'); + break; + } + break; + case '%': + switch (c = *fmt) { + case '\0': + continue; + case '%': + default: + putchar(c); + break; + case 'e': + ioctldecode(u); + break; + case 'n': + name = ioctlname(u); + printf("%s", name ? name : "(null)"); + break; + case 'x': + printf("%#lx", u); + break; + case 'o': + printf("%#lo", u); + break; + case 'd': case 'i': + printf("%ld", u); + break; + } + break; + } + ++fmt; + } +} + static int fread_tail(void *buf, size_t num, size_t size) { @@ -1235,8 +1303,8 @@ signame(long sig, int xlat) static void usage(void) { - if (strcmp(getprogname(), "ioctlname") == 0) { - (void)fprintf(stderr, "Usage: %s [-e emulation] <ioctl> ...\n", + if (strcmp(getprogname(), "ioctlprint") == 0) { + (void)fprintf(stderr, "Usage: %s [-f format] [-e emulation] <ioctl> ...\n", getprogname()); } else { (void)fprintf(stderr, "Usage: %s [-dElNnRT] [-e emulation] " Added files: Index: src/usr.bin/kdump/ioctlprint.1 diff -u /dev/null src/usr.bin/kdump/ioctlprint.1:1.1 --- /dev/null Thu Apr 2 03:32:46 2020 +++ src/usr.bin/kdump/ioctlprint.1 Thu Apr 2 03:32:46 2020 @@ -0,0 +1,89 @@ +.\" +.\" Copyright (c) 2020 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Kamil Rytarowski. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd April 2, 2020 +.Dt IOCTLPRINT 1 +.Os +.Sh NAME +.Nm ioctlprint +.Nd display descriptive ioctl value +.Sh SYNOPSIS +.Nm +.Op Fl e Ar emulation +.Op Fl f Ar format +.Op Ar arg ... +.Sh DESCRIPTION +The +.Nm +utility displays information about the file ioctl operation pointed to by one or more +.Ar arg +arguments. +.Pp +The options are as follows: +.Bl -tag -width Fl +.It Fl e Ar emulation +If an emulation of a process is unknown, +interpret system call maps assuming the named emulation instead of +default "netbsd". +.It Fl f Ar format +The argument is a +.Xr printf 3 +style format string that allows customization of +.Nm ioctlprint Ns 's +output. +.Pp +The following conversion characters can be used: +.Bl -tag -width xxxx +.It \&%e +Decoded ioctl string. +.It \&%n +Descriptive ioctl operation name. +.It \&%x +Hexadecimal ioctl number. +.It \&%o +Octal ioctl number. +.It \&%d or \&%i +Decimal ioctl number. +.El +.Pp +The default format is: +.Bd -literal -offset indent +"%n %e %x\\n" +.Ed +.El +.Pp +.Sh SEE ALSO +.Xr kdump 1 +.Xr ktrace 1 +.Sh HISTORY +The +.Nm +command first appeared in +.Nx 10 . +.Sh AUTHORS +.An Kamil Rytarowski Aq Mt ka...@netbsd.org