Subject: kern/33815: /emul/linux/proc/#/stat always report current process status
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <njoly@pasteur.fr>
List: netbsd-bugs
Date: 06/24/2006 15:20:01
>Number:         33815
>Category:       kern
>Synopsis:       /emul/linux/proc/#/stat always report current process status
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 24 15:20:01 +0000 2006
>Originator:     Nicolas Joly
>Release:        NetBSD 3.99.21
>Organization:
Institut Pasteur, Paris.
>Environment:
System: NetBSD cixy.dial.pasteur.fr 3.99.21 NetBSD 3.99.21 (CIXY) #2: Sat Jun 24 16:43:18 CEST 2006 njoly@cixy.dial.pasteur.fr:/local/src/NetBSD/obj/i386/sys/arch/i386/compile/CIXY i386
Architecture: i386
Machine: i386
>Description:
I just noticed that `/emul/linux/proc/#/stat' special file, always report
status for the current process, instead of the numbered one. It breaks some
linux programs such as pstree(1).

njoly@cixy [~]> uname -a
NetBSD cixy.dial.pasteur.fr 3.99.21 NetBSD 3.99.21 (CIXY) #0: Sat Jun 24 01:15:17 CEST 2006  njoly@cixy.dial.pasteur.fr:/local/src/NetBSD/obj/i386/sys/arch/i386/compile/CIXY i386
njoly@cixy [~]> mount -vv | grep /emul/linux/proc
procfs on /usr/pkg/emul/linux/proc type procfs (local, fsid: 0x1b01/0x1ae1b, reads: sync 0 async 0, writes: sync 0 async 0, [procfs: version=1, flags=0x1<linuxcompat>])
njoly@cixy [linux/proc]> cd /emul/linux/proc 
njoly@cixy [linux/proc]> for n in 1 2 3 4; do echo "** $n **"; cat $n/status; cat $n/stat; done
** 1 **
init 1 0 1 1 -1,-1 sldr 1151133417,2 0,70113 0,122698 wait 0 0
27903 (cat) R 11565 27903 11565 1288 27903 16386 129 0 0 0 0 0 0 0 20 20 0 0 1151160072 0 0 318533632 134512640 134520832 3217031168 0 0 0 0 2554888192 0 3400555776 0 2 20 0
** 2 **
sysmon 2 0 0 0 -1,-1 noflags 1151133417,2 0,0 0,0 smtaskq 0 0
12719 (cat) R 11565 12719 11565 1288 12719 16386 129 0 0 0 0 0 0 0 20 20 0 0 1151160072 0 0 318533632 134512640 134520832 3217031168 0 0 0 0 2554888192 0 3230170024 0 1 20 0
** 3 **
pms0 3 0 0 0 -1,-1 noflags 1151133417,2 0,0 0,0 pmsreset 0 0
394 (cat) R 11565 394 11565 1288 394 16386 129 0 0 0 0 0 0 0 20 20 0 0 1151160072 0 0 318533632 134512640 134520832 3217031168 0 0 0 0 2554888192 0 3238861124 0 1 20 0
** 4 **
atabus0 4 0 0 0 -1,-1 noflags 1151133417,2 0,0 0,1133 atath 0 0
28966 (cat) R 11565 28966 11565 1288 28966 16386 129 0 0 0 0 0 0 0 20 20 0 0 1151160072 0 0 318533632 134512640 134520832 3217031168 0 0 0 0 2554888192 0 3237548596 0 2 20 0

>How-To-Repeat:
Just compare `/emul/linux/proc/#/{stat,status}' output.
binary.
>Fix:
Index: sys/miscfs/procfs/procfs_linux.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_linux.c,v
retrieving revision 1.24
diff -u -r1.24 procfs_linux.c
--- sys/miscfs/procfs/procfs_linux.c	11 Dec 2005 12:24:51 -0000	1.24
+++ sys/miscfs/procfs/procfs_linux.c	24 Jun 2006 14:51:44 -0000
@@ -116,7 +116,7 @@
 		 struct uio *uio)
 {
 	char bf[512];
-	struct proc *p = curl->l_proc;
+	struct proc *p = l->l_proc;
 	int len;
 	struct tty *tty = p->p_session->s_ttyp;
 	struct rusage *ru = &p->p_stats->p_ru;