diff options
Diffstat (limited to 'src/lib/pid.c')
-rw-r--r-- | src/lib/pid.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/src/lib/pid.c b/src/lib/pid.c index d1ade389e..42687274e 100644 --- a/src/lib/pid.c +++ b/src/lib/pid.c | |||
@@ -29,16 +29,14 @@ | |||
29 | //Process pids[max_pids]; | 29 | //Process pids[max_pids]; |
30 | Process *pids = NULL; | 30 | Process *pids = NULL; |
31 | int max_pids=32769; | 31 | int max_pids=32769; |
32 | #define PIDS_BUFLEN 4096 | ||
33 | 32 | ||
34 | // get the memory associated with this pid | 33 | // get the memory associated with this pid |
35 | void pid_getmem(unsigned pid, unsigned *rss, unsigned *shared) { | 34 | void pid_getmem(unsigned pid, unsigned *rss, unsigned *shared) { |
36 | // open stat file | 35 | // open stat file |
37 | char *file; | 36 | char *file; |
38 | if (asprintf(&file, "/proc/%u/statm", pid) == -1) { | 37 | if (asprintf(&file, "/proc/%u/statm", pid) == -1) |
39 | perror("asprintf"); | 38 | errExit("asprintf"); |
40 | exit(1); | 39 | |
41 | } | ||
42 | FILE *fp = fopen(file, "r"); | 40 | FILE *fp = fopen(file, "r"); |
43 | if (!fp) { | 41 | if (!fp) { |
44 | free(file); | 42 | free(file); |
@@ -60,10 +58,9 @@ void pid_getmem(unsigned pid, unsigned *rss, unsigned *shared) { | |||
60 | void pid_get_cpu_time(unsigned pid, unsigned *utime, unsigned *stime) { | 58 | void pid_get_cpu_time(unsigned pid, unsigned *utime, unsigned *stime) { |
61 | // open stat file | 59 | // open stat file |
62 | char *file; | 60 | char *file; |
63 | if (asprintf(&file, "/proc/%u/stat", pid) == -1) { | 61 | if (asprintf(&file, "/proc/%u/stat", pid) == -1) |
64 | perror("asprintf"); | 62 | errExit("asprintf"); |
65 | exit(1); | 63 | |
66 | } | ||
67 | FILE *fp = fopen(file, "r"); | 64 | FILE *fp = fopen(file, "r"); |
68 | if (!fp) { | 65 | if (!fp) { |
69 | free(file); | 66 | free(file); |
@@ -94,10 +91,9 @@ myexit: | |||
94 | unsigned long long pid_get_start_time(unsigned pid) { | 91 | unsigned long long pid_get_start_time(unsigned pid) { |
95 | // open stat file | 92 | // open stat file |
96 | char *file; | 93 | char *file; |
97 | if (asprintf(&file, "/proc/%u/stat", pid) == -1) { | 94 | if (asprintf(&file, "/proc/%u/stat", pid) == -1) |
98 | perror("asprintf"); | 95 | errExit("asprintf"); |
99 | exit(1); | 96 | |
100 | } | ||
101 | FILE *fp = fopen(file, "r"); | 97 | FILE *fp = fopen(file, "r"); |
102 | if (!fp) { | 98 | if (!fp) { |
103 | free(file); | 99 | free(file); |
@@ -139,10 +135,8 @@ uid_t pid_get_uid(pid_t pid) { | |||
139 | 135 | ||
140 | // open status file | 136 | // open status file |
141 | char *file; | 137 | char *file; |
142 | if (asprintf(&file, "/proc/%u/status", pid) == -1) { | 138 | if (asprintf(&file, "/proc/%u/status", pid) == -1) |
143 | perror("asprintf"); | 139 | errExit("asprintf"); |
144 | exit(1); | ||
145 | } | ||
146 | 140 | ||
147 | FILE *fp = fopen(file, "r"); | 141 | FILE *fp = fopen(file, "r"); |
148 | if (!fp) { | 142 | if (!fp) { |
@@ -317,10 +311,9 @@ void pid_read(pid_t mon_pid) { | |||
317 | 311 | ||
318 | // open stat file | 312 | // open stat file |
319 | char *file; | 313 | char *file; |
320 | if (asprintf(&file, "/proc/%u/status", pid) == -1) { | 314 | if (asprintf(&file, "/proc/%u/status", pid) == -1) |
321 | perror("asprintf"); | 315 | errExit("asprintf"); |
322 | exit(1); | 316 | |
323 | } | ||
324 | FILE *fp = fopen(file, "r"); | 317 | FILE *fp = fopen(file, "r"); |
325 | if (!fp) { | 318 | if (!fp) { |
326 | free(file); | 319 | free(file); |
@@ -340,18 +333,12 @@ void pid_read(pid_t mon_pid) { | |||
340 | exit(1); | 333 | exit(1); |
341 | } | 334 | } |
342 | 335 | ||
343 | if (mon_pid == 0 && strncmp(ptr, "firejail", 8) == 0) { | 336 | if ((strncmp(ptr, "firejail", 8) == 0) && (mon_pid == 0 || mon_pid == pid)) { |
344 | pids[pid].level = 1; | 337 | if (pid_proc_cmdline_x11_xpra_xephyr(pid)) |
345 | } | 338 | pids[pid].level = -1; |
346 | else if (mon_pid == pid && strncmp(ptr, "firejail", 8) == 0) { | 339 | else |
347 | pids[pid].level = 1; | 340 | pids[pid].level = 1; |
348 | } | 341 | } |
349 | // else if (mon_pid == 0 && strncmp(ptr, "lxc-execute", 11) == 0) { | ||
350 | // pids[pid].level = 1; | ||
351 | // } | ||
352 | // else if (mon_pid == pid && strncmp(ptr, "lxc-execute", 11) == 0) { | ||
353 | // pids[pid].level = 1; | ||
354 | // } | ||
355 | else | 342 | else |
356 | pids[pid].level = -1; | 343 | pids[pid].level = -1; |
357 | } | 344 | } |