diff options
Diffstat (limited to 'src/firemon/x11.c')
-rw-r--r-- | src/firemon/x11.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/firemon/x11.c b/src/firemon/x11.c index e30c2d78b..73dc310d3 100644 --- a/src/firemon/x11.c +++ b/src/firemon/x11.c | |||
@@ -22,39 +22,35 @@ | |||
22 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | 24 | ||
25 | void x11(pid_t pid) { | 25 | void x11(pid_t pid, int print_procs) { |
26 | if (getuid() == 0) | ||
27 | firemon_drop_privs(); | ||
28 | |||
29 | pid_read(pid); | 26 | pid_read(pid); |
30 | 27 | ||
31 | // print processes | 28 | // print processes |
32 | int i; | 29 | int i; |
33 | for (i = 0; i < max_pids; i++) { | 30 | for (i = 0; i < max_pids; i++) { |
34 | if (pids[i].level == 1) { | 31 | if (pids[i].level == 1) { |
35 | pid_print_list(i, 0); | 32 | if (print_procs || pid == 0) |
33 | pid_print_list(i, 0); | ||
36 | 34 | ||
37 | char *x11file; | 35 | char *x11file; |
38 | // todo: use macro from src/firejail/firejail.h for /run/firejail/x11 directory | 36 | // todo: use macro from src/firejail/firejail.h for /run/firejail/x11 directory |
39 | if (asprintf(&x11file, "/run/firejail/x11/%d", i) == -1) | 37 | if (asprintf(&x11file, "/run/firejail/x11/%d", i) == -1) |
40 | errExit("asprintf"); | 38 | errExit("asprintf"); |
41 | 39 | ||
42 | struct stat s; | 40 | FILE *fp = fopen(x11file, "r"); |
43 | if (stat(x11file, &s) == 0) { | 41 | if (!fp) { |
44 | FILE *fp = fopen(x11file, "r"); | 42 | free(x11file); |
45 | if (!fp) { | 43 | continue; |
46 | free(x11file); | ||
47 | continue; | ||
48 | } | ||
49 | int display; | ||
50 | int rv = fscanf(fp, "%d", &display); | ||
51 | if (rv == 1) | ||
52 | printf(" DISPLAY :%d\n", display); | ||
53 | fclose(fp); | ||
54 | } | 44 | } |
55 | 45 | ||
46 | int display; | ||
47 | int rv = fscanf(fp, "%d", &display); | ||
48 | if (rv == 1) | ||
49 | printf(" DISPLAY :%d\n", display); | ||
50 | fclose(fp); | ||
56 | free(x11file); | 51 | free(x11file); |
57 | } | 52 | } |
58 | } | 53 | } |
54 | printf("\n"); | ||
59 | } | 55 | } |
60 | 56 | ||