diff options
Diffstat (limited to 'src/lib/common.c')
-rw-r--r-- | src/lib/common.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/lib/common.c b/src/lib/common.c index 6f2cebf12..98cb48abf 100644 --- a/src/lib/common.c +++ b/src/lib/common.c | |||
@@ -37,7 +37,7 @@ int join_namespace(pid_t pid, char *type) { | |||
37 | char *path; | 37 | char *path; |
38 | if (asprintf(&path, "/proc/%u/ns/%s", pid, type) == -1) | 38 | if (asprintf(&path, "/proc/%u/ns/%s", pid, type) == -1) |
39 | errExit("asprintf"); | 39 | errExit("asprintf"); |
40 | 40 | ||
41 | int fd = open(path, O_RDONLY); | 41 | int fd = open(path, O_RDONLY); |
42 | if (fd < 0) | 42 | if (fd < 0) |
43 | goto errout; | 43 | goto errout; |
@@ -55,14 +55,14 @@ errout: | |||
55 | free(path); | 55 | free(path); |
56 | fprintf(stderr, "Error: cannot join namespace %s\\n", type); | 56 | fprintf(stderr, "Error: cannot join namespace %s\\n", type); |
57 | return -1; | 57 | return -1; |
58 | 58 | ||
59 | } | 59 | } |
60 | 60 | ||
61 | // return 1 if error | 61 | // return 1 if error |
62 | // this function requires root access - todo: fix it! | 62 | // this function requires root access - todo: fix it! |
63 | int name2pid(const char *name, pid_t *pid) { | 63 | int name2pid(const char *name, pid_t *pid) { |
64 | pid_t parent = getpid(); | 64 | pid_t parent = getpid(); |
65 | 65 | ||
66 | DIR *dir; | 66 | DIR *dir; |
67 | if (!(dir = opendir("/proc"))) { | 67 | if (!(dir = opendir("/proc"))) { |
68 | // sleep 2 seconds and try again | 68 | // sleep 2 seconds and try again |
@@ -72,7 +72,7 @@ int name2pid(const char *name, pid_t *pid) { | |||
72 | exit(1); | 72 | exit(1); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | struct dirent *entry; | 76 | struct dirent *entry; |
77 | char *end; | 77 | char *end; |
78 | while ((entry = readdir(dir))) { | 78 | while ((entry = readdir(dir))) { |
@@ -91,7 +91,7 @@ int name2pid(const char *name, pid_t *pid) { | |||
91 | } | 91 | } |
92 | free(comm); | 92 | free(comm); |
93 | } | 93 | } |
94 | 94 | ||
95 | // look for the sandbox name in /run/firejail/name/<PID> | 95 | // look for the sandbox name in /run/firejail/name/<PID> |
96 | // todo: use RUN_FIREJAIL_NAME_DIR define from src/firejail/firejail.h | 96 | // todo: use RUN_FIREJAIL_NAME_DIR define from src/firejail/firejail.h |
97 | char *fname; | 97 | char *fname; |
@@ -249,10 +249,10 @@ int pid_proc_cmdline_x11_xpra_xephyr(const pid_t pid) { | |||
249 | break; | 249 | break; |
250 | if (strncmp(arg, "--", 2) != 0) | 250 | if (strncmp(arg, "--", 2) != 0) |
251 | break; | 251 | break; |
252 | 252 | ||
253 | if (strcmp(arg, "--x11=xorg") == 0) | 253 | if (strcmp(arg, "--x11=xorg") == 0) |
254 | return 0; | 254 | return 0; |
255 | 255 | ||
256 | // check x11 xpra or xephyr | 256 | // check x11 xpra or xephyr |
257 | if (strncmp(arg, "--x11", 5) == 0) | 257 | if (strncmp(arg, "--x11", 5) == 0) |
258 | return 1; | 258 | return 1; |
@@ -267,7 +267,7 @@ int pid_hidepid(void) { | |||
267 | FILE *fp = fopen("/proc/mounts", "r"); | 267 | FILE *fp = fopen("/proc/mounts", "r"); |
268 | if (!fp) | 268 | if (!fp) |
269 | return 1; | 269 | return 1; |
270 | 270 | ||
271 | char buf[BUFLEN]; | 271 | char buf[BUFLEN]; |
272 | while (fgets(buf, BUFLEN, fp)) { | 272 | while (fgets(buf, BUFLEN, fp)) { |
273 | if (strstr(buf, "proc /proc proc")) { | 273 | if (strstr(buf, "proc /proc proc")) { |
@@ -278,10 +278,7 @@ int pid_hidepid(void) { | |||
278 | return 0; | 278 | return 0; |
279 | } | 279 | } |
280 | } | 280 | } |
281 | 281 | ||
282 | fclose(fp); | 282 | fclose(fp); |
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
285 | |||
286 | |||
287 | |||