Subject: kdump(1) and non printable ioctl types values
To: NetBSD current <current-users@NetBSD.org>
From: Nicolas Joly <njoly@pasteur.fr>
List: current-users
Date: 03/19/2007 13:46:31
--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Hi,

While working on NetBSD/amd64 compat linux/linux32, i noticed that
kdump(1) display strange characters for non printable ioctl types
values ...

By example, compat linux use type 0x89 for socket ioctls :

 19042      1 MATLAB   CALL  socket(2,2,0)
 19042      1 MATLAB   RET   socket 4
 19042      1 MATLAB   CALL  ioctl(4,_IO('<89>',0x27,0),0x7f7fffffa480)
 19042      1 MATLAB   RET   ioctl 0
 19042      1 MATLAB   CALL  close(4)
 19042      1 MATLAB   RET   close 0

With the attached patch, all non printable characters are displayed
with their hexadecimal value.

 19042      1 MATLAB   CALL  socket(2,2,0)
 19042      1 MATLAB   RET   socket 4
 19042      1 MATLAB   CALL  ioctl(4,_IO(0x89,0x27,0),0x7f7fffffa480)
 19042      1 MATLAB   RET   ioctl 0
 19042      1 MATLAB   CALL  close(4)
 19042      1 MATLAB   RET   close 0

Does it looks ok ?

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.

--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="netbsd-kdumpioctl.diff"

Index: usr.bin/kdump/kdump.c
===================================================================
RCS file: /cvsroot/src/usr.bin/kdump/kdump.c,v
retrieving revision 1.89
diff -u -r1.89 kdump.c
--- usr.bin/kdump/kdump.c	9 Feb 2007 22:08:48 -0000	1.89
+++ usr.bin/kdump/kdump.c	19 Mar 2007 12:27:26 -0000
@@ -413,6 +413,7 @@
 ioctldecode(u_long cmd)
 {
 	char dirbuf[4], *dir = dirbuf;
+	int c;
 
 	if (cmd & IOC_IN)
 		*dir++ = 'W';
@@ -420,7 +421,11 @@
 		*dir++ = 'R';
 	*dir = '\0';
 
-	printf(",_IO%s('%c',", dirbuf, (int) ((cmd >> 8) & 0xff));
+	c = (cmd >> 8) & 0xff;
+	if (isprint(c))
+		printf(",_IO%s('%c',", dirbuf, c);
+	else
+		printf(",_IO%s(0x%02x,", dirbuf, c);
 	output_long(cmd & 0xff, decimal == 0);
 	if ((cmd & IOC_VOID) == 0) {
 		putchar(',');

--C7zPtVaVf+AK4Oqc--