diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/run_files.c | 30 | ||||
-rw-r--r-- | src/lib/pid.c | 10 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/firejail/run_files.c b/src/firejail/run_files.c index 57a0e19df..361ad1414 100644 --- a/src/firejail/run_files.c +++ b/src/firejail/run_files.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include "firejail.h" | 21 | #include "firejail.h" |
22 | #include "../include/pid.h" | 22 | #include "../include/pid.h" |
23 | #define BUFLEN 4096 | ||
23 | 24 | ||
24 | static void delete_x11_run_file(pid_t pid) { | 25 | static void delete_x11_run_file(pid_t pid) { |
25 | char *fname; | 26 | char *fname; |
@@ -74,7 +75,36 @@ void delete_run_files(pid_t pid) { | |||
74 | delete_profile_run_file(pid); | 75 | delete_profile_run_file(pid); |
75 | } | 76 | } |
76 | 77 | ||
78 | static char *newname(char *name) { | ||
79 | char *rv; | ||
80 | pid_t pid; | ||
81 | |||
82 | // try the name | ||
83 | if (name2pid(name, &pid)) | ||
84 | return name; | ||
85 | |||
86 | // try name-1 to 9 | ||
87 | int i; | ||
88 | for (i = 1; i < 10; i++) { | ||
89 | if (asprintf(&rv, "%s-%d", name, i) == -1) | ||
90 | errExit("asprintf"); | ||
91 | if (name2pid(rv, &pid)) { | ||
92 | fwarning("Sandbox name changed to %s\n", rv); | ||
93 | return rv; | ||
94 | } | ||
95 | free(rv); | ||
96 | } | ||
97 | |||
98 | // return name-pid | ||
99 | if (asprintf(&rv, "%s-%d", name, getpid()) == -1) | ||
100 | errExit("asprintf"); | ||
101 | return rv; | ||
102 | } | ||
103 | |||
104 | |||
77 | void set_name_run_file(pid_t pid) { | 105 | void set_name_run_file(pid_t pid) { |
106 | cfg.name = newname(cfg.name); | ||
107 | |||
78 | char *fname; | 108 | char *fname; |
79 | if (asprintf(&fname, "%s/%d", RUN_FIREJAIL_NAME_DIR, pid) == -1) | 109 | if (asprintf(&fname, "%s/%d", RUN_FIREJAIL_NAME_DIR, pid) == -1) |
80 | errExit("asprintf"); | 110 | errExit("asprintf"); |
diff --git a/src/lib/pid.c b/src/lib/pid.c index f138efc8c..3c804716d 100644 --- a/src/lib/pid.c +++ b/src/lib/pid.c | |||
@@ -188,10 +188,11 @@ static void print_elem(unsigned index, int nowrap) { | |||
188 | uid_t uid = pids[index].uid; | 188 | uid_t uid = pids[index].uid; |
189 | char *cmd = pid_proc_cmdline(index); | 189 | char *cmd = pid_proc_cmdline(index); |
190 | char *user = pid_get_user_name(uid); | 190 | char *user = pid_get_user_name(uid); |
191 | char *allocated = user; | 191 | char *user_allocated = user; |
192 | 192 | ||
193 | // extract sandbox name - pid == index | 193 | // extract sandbox name - pid == index |
194 | char *sandbox_name = ""; | 194 | char *sandbox_name = ""; |
195 | char *sandbox_name_allocated = NULL; | ||
195 | char *fname; | 196 | char *fname; |
196 | if (asprintf(&fname, "%s/%d", RUN_FIREJAIL_NAME_DIR, index) == -1) | 197 | if (asprintf(&fname, "%s/%d", RUN_FIREJAIL_NAME_DIR, index) == -1) |
197 | errExit("asprintf"); | 198 | errExit("asprintf"); |
@@ -202,6 +203,7 @@ static void print_elem(unsigned index, int nowrap) { | |||
202 | sandbox_name = malloc(s.st_size + 1); | 203 | sandbox_name = malloc(s.st_size + 1); |
203 | if (!sandbox_name) | 204 | if (!sandbox_name) |
204 | errExit("malloc"); | 205 | errExit("malloc"); |
206 | sandbox_name_allocated = sandbox_name; | ||
205 | char *rv = fgets(sandbox_name, s.st_size + 1, fp); | 207 | char *rv = fgets(sandbox_name, s.st_size + 1, fp); |
206 | if (!rv) | 208 | if (!rv) |
207 | *sandbox_name = '\0'; | 209 | *sandbox_name = '\0'; |
@@ -241,8 +243,10 @@ static void print_elem(unsigned index, int nowrap) { | |||
241 | else | 243 | else |
242 | printf("%s%u:\n", indent, index); | 244 | printf("%s%u:\n", indent, index); |
243 | } | 245 | } |
244 | if (allocated) | 246 | if (user_allocated) |
245 | free(allocated); | 247 | free(user_allocated); |
248 | if (sandbox_name_allocated) | ||
249 | free(sandbox_name_allocated); | ||
246 | } | 250 | } |
247 | 251 | ||
248 | // recursivity!!! | 252 | // recursivity!!! |