aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/process.c')
-rw-r--r--arch/um/os-Linux/process.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c
index 8b57eb3647f5..90b480cf78f4 100644
--- a/arch/um/os-Linux/process.c
+++ b/arch/um/os-Linux/process.c
@@ -7,6 +7,7 @@
7#include <unistd.h> 7#include <unistd.h>
8#include <errno.h> 8#include <errno.h>
9#include <signal.h> 9#include <signal.h>
10#include <fcntl.h>
10#include <sys/mman.h> 11#include <sys/mman.h>
11#include <sys/ptrace.h> 12#include <sys/ptrace.h>
12#include <sys/wait.h> 13#include <sys/wait.h>
@@ -28,31 +29,32 @@
28unsigned long os_process_pc(int pid) 29unsigned long os_process_pc(int pid)
29{ 30{
30 char proc_stat[STAT_PATH_LEN], buf[256]; 31 char proc_stat[STAT_PATH_LEN], buf[256];
31 unsigned long pc; 32 unsigned long pc = ARBITRARY_ADDR;
32 int fd, err; 33 int fd, err;
33 34
34 sprintf(proc_stat, "/proc/%d/stat", pid); 35 sprintf(proc_stat, "/proc/%d/stat", pid);
35 fd = os_open_file(proc_stat, of_read(OPENFLAGS()), 0); 36 fd = open(proc_stat, O_RDONLY, 0);
36 if (fd < 0) { 37 if (fd < 0) {
37 printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', " 38 printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', "
38 "err = %d\n", proc_stat, -fd); 39 "errno = %d\n", proc_stat, errno);
39 return ARBITRARY_ADDR; 40 goto out;
40 } 41 }
41 CATCH_EINTR(err = read(fd, buf, sizeof(buf))); 42 CATCH_EINTR(err = read(fd, buf, sizeof(buf)));
42 if (err < 0) { 43 if (err < 0) {
43 printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', " 44 printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', "
44 "err = %d\n", proc_stat, errno); 45 "err = %d\n", proc_stat, errno);
45 os_close_file(fd); 46 goto out_close;
46 return ARBITRARY_ADDR;
47 } 47 }
48 os_close_file(fd); 48 os_close_file(fd);
49 pc = ARBITRARY_ADDR; 49 pc = ARBITRARY_ADDR;
50 if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d " 50 if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d "
51 "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " 51 "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
52 "%*d %*d %*d %*d %*d %lu", &pc) != 1) { 52 "%*d %*d %*d %*d %*d %lu", &pc) != 1)
53 printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n", 53 printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n",
54 buf); 54 buf);
55 } 55 out_close:
56 close(fd);
57 out:
56 return pc; 58 return pc;
57} 59}
58 60
@@ -60,25 +62,26 @@ int os_process_parent(int pid)
60{ 62{
61 char stat[STAT_PATH_LEN]; 63 char stat[STAT_PATH_LEN];
62 char data[256]; 64 char data[256];
63 int parent, n, fd; 65 int parent = FAILURE_PID, n, fd;
64 66
65 if (pid == -1) 67 if (pid == -1)
66 return -1; 68 return parent;
67 69
68 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid); 70 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
69 fd = os_open_file(stat, of_read(OPENFLAGS()), 0); 71 fd = open(stat, O_RDONLY, 0);
70 if (fd < 0) { 72 if (fd < 0) {
71 printk(UM_KERN_ERR "Couldn't open '%s', err = %d\n", stat, -fd); 73 printk(UM_KERN_ERR "Couldn't open '%s', errno = %d\n", stat,
72 return FAILURE_PID; 74 errno);
75 return parent;
73 } 76 }
74 77
75 CATCH_EINTR(n = read(fd, data, sizeof(data))); 78 CATCH_EINTR(n = read(fd, data, sizeof(data)));
76 os_close_file(fd); 79 close(fd);
77 80
78 if (n < 0) { 81 if (n < 0) {
79 printk(UM_KERN_ERR "Couldn't read '%s', err = %d\n", stat, 82 printk(UM_KERN_ERR "Couldn't read '%s', errno = %d\n", stat,
80 errno); 83 errno);
81 return FAILURE_PID; 84 return parent;
82 } 85 }
83 86
84 parent = FAILURE_PID; 87 parent = FAILURE_PID;