From joe@tao.org.uk  Mon Aug 13 13:52:07 2001
Return-Path: <joe@tao.org.uk>
Received: from tao.org.uk (xwing.creative.net.au [203.56.168.36])
	by hub.freebsd.org (Postfix) with ESMTP id DD5D237B408
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 13 Aug 2001 13:52:05 -0700 (PDT)
	(envelope-from joe@tao.org.uk)
Received: by tao.org.uk (Postfix, from userid 100)
	id 5D3C337C; Sun, 12 Aug 2001 16:23:56 +0100 (BST)
Message-Id: <20010812152356.5D3C337C@tao.org.uk>
Date: Sun, 12 Aug 2001 16:23:56 +0100 (BST)
From: Joe Karthauser <joe@tao.org.uk>
Reply-To: Joe Karthauser <joe@tao.org.uk>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /proc/pid/status broken for irqN processes.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         29682
>Category:       kern
>Synopsis:       /proc/pid/status broken for irqN processes.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    mike
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 13 14:00:05 PDT 2001
>Closed-Date:    Sun Nov 10 12:11:38 PST 2002
>Last-Modified:  Sun Nov 10 12:11:38 PST 2002
>Originator:     Joe Karthauser
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Tao Research
>Environment:
System: FreeBSD genius.tao.org.uk 5.0-CURRENT FreeBSD 5.0-CURRENT #12: Sun Aug 12 14:13:44 BST 2001 root@:/usr/obj/usr/src/sys/GENIUS i386

>Description:
	Processes that use procfs, like wmtop, are broken under -current.
	This is because the /proc/pid/status file is a space separated
	list of entries, but irq threads in -current contain spaces in
	their names.  This makes it impossible to parse the status file
	correctly.
	
	genius# cat /proc/15/status
	swi5: task queue 15 0 0 0 -1,-1 noflags 997626444,23 0,0 0,0 nochan 0 0
	0,0 -

	The field 'swi5: task queue' should is a single field, but
	contains spaces.


>How-To-Repeat:
>Fix:

	I've fixed it locally by replacing spaces with underscores
	whilst constructing the status file in
	sys/fs/procfs/procfs_status.c.

	The following patch illustrates the idea, but please note that
	it's a hack[tm], not a recommendation:


Index: procfs_status.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/procfs/procfs_status.c,v
retrieving revision 1.32
diff -u -r1.32 procfs_status.c
--- procfs_status.c	2001/07/05 17:10:43	1.32
+++ procfs_status.c	2001/08/12 15:03:10
@@ -58,6 +58,8 @@
 
 #include <fs/procfs/procfs.h>
 
+void jbcopy(const char *src0, char *dst0, register size_t length);
+
 #define DOCHECK() do { if (ps >= psbuf+sizeof(psbuf)) goto bailout; } while (0)
 int
 procfs_dostatus(curp, p, pfs, uio)
@@ -95,7 +97,7 @@
 			("Too short buffer for new MAXCOMLEN"));
 
 	ps = psbuf;
-	bcopy(p->p_comm, ps, MAXCOMLEN);
+	jbcopy(p->p_comm, ps, MAXCOMLEN);
 	ps[MAXCOMLEN] = '\0';
 	ps += strlen(ps);
 	DOCHECK();
@@ -188,6 +190,34 @@
 
 bailout:
 	return (ENOMEM);
+}
+
+
+
+void
+jbcopy(src0, dst0, length)
+        const char *src0;
+        char *dst0;
+        register size_t length;
+{
+	int i;
+
+	for (i = 0 ; i < length ; ++i) {
+		*dst0 = *src0;
+		if (*dst0 == ' ') {
+			*dst0 = '_';
+		}
+		if (!*src0) {
+			break;
+		}
+
+		++dst0;
+		++src0;
+	}
+
+	if (i == length) {
+		*dst0 = '\0';
+	}
 }
 
 int
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: mike 
State-Changed-When: Thu Sep 27 11:29:29 PDT 2001 
State-Changed-Why:  

I've fixed the problem in -CURRENT by replacing unprintable characters 
and spaces with their octal form variants.  This will be MFC'd shortly. 


Responsible-Changed-From-To: freebsd-bugs->mike 
Responsible-Changed-By: mike 
Responsible-Changed-When: Thu Sep 27 11:29:29 PDT 2001 
Responsible-Changed-Why:  

Over to me. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29682 
State-Changed-From-To: analyzed->closed 
State-Changed-By: mike 
State-Changed-When: Sun Nov 10 12:09:28 PST 2002 
State-Changed-Why:  

I never got around to MFCing this.  The originator can MFC it if he 
likes. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=29682 
>Unformatted:
