aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/common.c')
-rw-r--r--src/lib/common.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib/common.c b/src/lib/common.c
index 7d2ee5362..90cee3e10 100644
--- a/src/lib/common.c
+++ b/src/lib/common.c
@@ -31,6 +31,7 @@
31#include <dirent.h> 31#include <dirent.h>
32#include <string.h> 32#include <string.h>
33#include "../include/common.h" 33#include "../include/common.h"
34#define BUFLEN 4096
34 35
35int join_namespace(pid_t pid, char *type) { 36int join_namespace(pid_t pid, char *type) {
36 char *path; 37 char *path;
@@ -100,6 +101,32 @@ int name2pid(const char *name, pid_t *pid) {
100 char *start = ptr; 101 char *start = ptr;
101 if (!ptr) { 102 if (!ptr) {
102 free(cmd); 103 free(cmd);
104
105 // extract name for /run/mnt/firejail/fslogger file
106 char *fname;
107 if (asprintf(&fname, "/proc/%d/root/run/firejail/mnt/fslogger", newpid) == -1)
108 errExit("asprintf");
109
110 struct stat s;
111 if (stat(fname, &s) == 0) {
112 FILE *fp = fopen(fname, "r");
113 if (fp) {
114 char buf[BUFLEN];
115 if (fgets(buf, BUFLEN, fp)) {
116 if (strncmp(buf, "sandbox name: ", 14) == 0) {
117 char *ptr2 = buf + 14;
118 if (strncmp(name, ptr2, strlen(name)) == 0) {
119 fclose(fp);
120 *pid = newpid;
121 closedir(dir);
122 return 0;
123 }
124 }
125 }
126 fclose(fp);
127 }
128 }
129
103 continue; 130 continue;
104 } 131 }
105 while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0') 132 while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0')
@@ -119,7 +146,6 @@ int name2pid(const char *name, pid_t *pid) {
119 return 1; 146 return 1;
120} 147}
121 148
122#define BUFLEN 4096
123char *pid_proc_comm(const pid_t pid) { 149char *pid_proc_comm(const pid_t pid) {
124 // open /proc/pid/cmdline file 150 // open /proc/pid/cmdline file
125 char *fname; 151 char *fname;