
From: <blaisorblade_spam@yahoo.it>

Update os_process_pc and os_process_parent: now a PID can be > 32768 (so
increase number of digits) and make it work even with spaces in the command
name.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade_spam@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/um/os-Linux/process.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff -puN arch/um/os-Linux/process.c~uml-fix-os_process_pc-and-os_process_parent-for-corner-cases arch/um/os-Linux/process.c
--- 25/arch/um/os-Linux/process.c~uml-fix-os_process_pc-and-os_process_parent-for-corner-cases	2004-07-05 16:00:52.137094408 -0700
+++ 25-akpm/arch/um/os-Linux/process.c	2004-07-05 16:00:52.141093800 -0700
@@ -17,9 +17,12 @@
 #define ARBITRARY_ADDR -1
 #define FAILURE_PID    -1
 
+#define STAT_PATH_LEN sizeof("/proc/#######/stat\0")
+#define COMM_SCANF "%*[^)])"
+
 unsigned long os_process_pc(int pid)
 {
-	char proc_stat[sizeof("/proc/#####/stat\0")], buf[256];
+	char proc_stat[STAT_PATH_LEN], buf[256];
 	unsigned long pc;
 	int fd, err;
 
@@ -39,9 +42,9 @@ unsigned long os_process_pc(int pid)
 	}
 	os_close_file(fd);
 	pc = ARBITRARY_ADDR;
-	if(sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*d %*d %*d "
+	if(sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d %*d "
 		  "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
-		  "%*d %*d %*d %*d %ld", &pc) != 1){
+		  "%*d %*d %*d %*d %lu", &pc) != 1){
 		printk("os_process_pc - couldn't find pc in '%s'\n", buf);
 	}
 	return(pc);
@@ -49,7 +52,7 @@ unsigned long os_process_pc(int pid)
 
 int os_process_parent(int pid)
 {
-	char stat[sizeof("/proc/nnnnn/stat\0")];
+	char stat[STAT_PATH_LEN];
 	char data[256];
 	int parent, n, fd;
 
@@ -71,8 +74,7 @@ int os_process_parent(int pid)
 	}
 
 	parent = FAILURE_PID;
-	/* XXX This will break if there is a space in the command */
-	n = sscanf(data, "%*d %*s %*c %d", &parent);
+	n = sscanf(data, "%*d " COMM_SCANF " %*c %d", &parent);
 	if(n != 1)
 		printk("Failed to scan '%s'\n", data);
 
_
