Commit 0d59a6c4 authored by Paolo \'Blaisorblade\' Giarrusso's avatar Paolo \'Blaisorblade\' Giarrusso Committed by Linus Torvalds

[PATCH] uml: Fix os_process_pc and os_process_parent for corner cases.

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: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade_spam@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent a15968fe
...@@ -17,9 +17,12 @@ ...@@ -17,9 +17,12 @@
#define ARBITRARY_ADDR -1 #define ARBITRARY_ADDR -1
#define FAILURE_PID -1 #define FAILURE_PID -1
#define STAT_PATH_LEN sizeof("/proc/#######/stat\0")
#define COMM_SCANF "%*[^)])"
unsigned long os_process_pc(int pid) 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; unsigned long pc;
int fd, err; int fd, err;
...@@ -39,9 +42,9 @@ unsigned long os_process_pc(int pid) ...@@ -39,9 +42,9 @@ unsigned long os_process_pc(int pid)
} }
os_close_file(fd); os_close_file(fd);
pc = ARBITRARY_ADDR; 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 %*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); printk("os_process_pc - couldn't find pc in '%s'\n", buf);
} }
return(pc); return(pc);
...@@ -49,7 +52,7 @@ unsigned long os_process_pc(int pid) ...@@ -49,7 +52,7 @@ unsigned long os_process_pc(int pid)
int os_process_parent(int pid) int os_process_parent(int pid)
{ {
char stat[sizeof("/proc/nnnnn/stat\0")]; char stat[STAT_PATH_LEN];
char data[256]; char data[256];
int parent, n, fd; int parent, n, fd;
...@@ -71,8 +74,7 @@ int os_process_parent(int pid) ...@@ -71,8 +74,7 @@ int os_process_parent(int pid)
} }
parent = FAILURE_PID; parent = FAILURE_PID;
/* XXX This will break if there is a space in the command */ n = sscanf(data, "%*d " COMM_SCANF " %*c %d", &parent);
n = sscanf(data, "%*d %*s %*c %d", &parent);
if(n != 1) if(n != 1)
printk("Failed to scan '%s'\n", data); printk("Failed to scan '%s'\n", data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment