aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar smitsohu <smitsohu@gmail.com>2019-12-23 23:11:32 +0100
committerLibravatar smitsohu <smitsohu@gmail.com>2019-12-23 23:11:32 +0100
commit6bb06fe038f1ad43427dcd547733e8f6c3667316 (patch)
tree1b22edaf6f4dc838c2b4bcf61d29660e9c396f37 /src
parentsimplify join timeout (diff)
downloadfirejail-6bb06fe038f1ad43427dcd547733e8f6c3667316.tar.gz
firejail-6bb06fe038f1ad43427dcd547733e8f6c3667316.tar.zst
firejail-6bb06fe038f1ad43427dcd547733e8f6c3667316.zip
let is_ready_for_join() return a boolean
Diffstat (limited to 'src')
-rw-r--r--src/firejail/cpu.c2
-rw-r--r--src/firejail/firejail.h2
-rw-r--r--src/firejail/join.c20
3 files changed, 12 insertions, 12 deletions
diff --git a/src/firejail/cpu.c b/src/firejail/cpu.c
index f3392d1e0..702186eaf 100644
--- a/src/firejail/cpu.c
+++ b/src/firejail/cpu.c
@@ -170,7 +170,7 @@ void cpu_print_filter(pid_t pid) {
170 pid = switch_to_child(pid); 170 pid = switch_to_child(pid);
171 171
172 // now check if the pid belongs to a firejail sandbox 172 // now check if the pid belongs to a firejail sandbox
173 if (is_ready_for_join(pid) == 0) { 173 if (is_ready_for_join(pid) == false) {
174 fprintf(stderr, "Error: no valid sandbox\n"); 174 fprintf(stderr, "Error: no valid sandbox\n");
175 exit(1); 175 exit(1);
176 } 176 }
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h
index 8b7cfdcdd..03bcbda46 100644
--- a/src/firejail/firejail.h
+++ b/src/firejail/firejail.h
@@ -426,7 +426,7 @@ void usage(void);
426 426
427// join.c 427// join.c
428void join(pid_t pid, int argc, char **argv, int index); 428void join(pid_t pid, int argc, char **argv, int index);
429int is_ready_for_join(const pid_t pid); 429bool is_ready_for_join(const pid_t pid);
430void check_join_permission(pid_t pid); 430void check_join_permission(pid_t pid);
431pid_t switch_to_child(pid_t pid); 431pid_t switch_to_child(pid_t pid);
432 432
diff --git a/src/firejail/join.c b/src/firejail/join.c
index ddf26e0e7..1494c782f 100644
--- a/src/firejail/join.c
+++ b/src/firejail/join.c
@@ -255,9 +255,9 @@ static void extract_umask(pid_t pid) {
255 fclose(fp); 255 fclose(fp);
256} 256}
257 257
258// return 0 if the sandbox identified by pid is not fully set up yet or if 258// return false if the sandbox identified by pid is not fully set up yet or if
259// it is no firejail sandbox at all, return 1 if the sandbox is complete 259// it is no firejail sandbox at all, return true if the sandbox is complete
260int is_ready_for_join(const pid_t pid) { 260bool is_ready_for_join(const pid_t pid) {
261 EUID_ASSERT(); 261 EUID_ASSERT();
262 // check if a file "ready-for-join" exists 262 // check if a file "ready-for-join" exists
263 char *fname; 263 char *fname;
@@ -268,7 +268,7 @@ int is_ready_for_join(const pid_t pid) {
268 EUID_USER(); 268 EUID_USER();
269 free(fname); 269 free(fname);
270 if (!fp) 270 if (!fp)
271 return 0; 271 return false;
272 // regular file owned by root 272 // regular file owned by root
273 int fd = fileno(fp); 273 int fd = fileno(fp);
274 if (fd == -1) 274 if (fd == -1)
@@ -278,18 +278,18 @@ int is_ready_for_join(const pid_t pid) {
278 errExit("fstat"); 278 errExit("fstat");
279 if (!S_ISREG(s.st_mode) || s.st_uid != 0) { 279 if (!S_ISREG(s.st_mode) || s.st_uid != 0) {
280 fclose(fp); 280 fclose(fp);
281 return 0; 281 return false;
282 } 282 }
283 // check if it is non-empty 283 // check if it is non-empty
284 char buf[BUFLEN]; 284 char buf[BUFLEN];
285 if (fgets(buf, BUFLEN, fp) == NULL) { 285 if (fgets(buf, BUFLEN, fp) == NULL) {
286 fclose(fp); 286 fclose(fp);
287 return 0; 287 return false;
288 } 288 }
289 fclose(fp); 289 fclose(fp);
290 // confirm "ready" string was written 290 // confirm "ready" string was written
291 if (strcmp(buf, "ready\n") != 0) 291 if (strcmp(buf, "ready\n") != 0)
292 return 0; 292 return false;
293 293
294 // walk down the process tree a few nodes, there should be no firejail leaf 294 // walk down the process tree a few nodes, there should be no firejail leaf
295#define MAXNODES 5 295#define MAXNODES 5
@@ -307,7 +307,7 @@ int is_ready_for_join(const pid_t pid) {
307 } 307 }
308 if (strcmp(comm, "firejail") == 0) { 308 if (strcmp(comm, "firejail") == 0) {
309 free(comm); 309 free(comm);
310 return 0; 310 return false;
311 } 311 }
312 free(comm); 312 free(comm);
313 break; 313 break;
@@ -315,14 +315,14 @@ int is_ready_for_join(const pid_t pid) {
315 current = next; 315 current = next;
316 } 316 }
317 317
318 return 1; 318 return true;
319} 319}
320 320
321#define SNOOZE 100000 // sleep interval in microseconds 321#define SNOOZE 100000 // sleep interval in microseconds
322void check_join_permission(pid_t pid) { 322void check_join_permission(pid_t pid) {
323 // check if pid belongs to a fully set up firejail sandbox 323 // check if pid belongs to a fully set up firejail sandbox
324 unsigned long i; 324 unsigned long i;
325 for (i = 0; is_ready_for_join(pid) == 0; i += SNOOZE) { // give sandbox some time to start up 325 for (i = 0; is_ready_for_join(pid) == false; i += SNOOZE) { // give sandbox some time to start up
326 if (i >= join_timeout) { 326 if (i >= join_timeout) {
327 fprintf(stderr, "Error: no valid sandbox\n"); 327 fprintf(stderr, "Error: no valid sandbox\n");
328 exit(1); 328 exit(1);