aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Austin Morton <austinpmorton@gmail.com>2019-05-20 20:50:48 -0400
committerLibravatar Austin Morton <austinpmorton@gmail.com>2019-05-20 20:59:49 -0400
commitd380de39f039cf23a992b08c506cc200a7cf6292 (patch)
tree681aa830ee7c657a7bfe2e0c8de92d91e38d19bf /src
parentCreate a profile for mp3splt-gtk (diff)
downloadfirejail-d380de39f039cf23a992b08c506cc200a7cf6292.tar.gz
firejail-d380de39f039cf23a992b08c506cc200a7cf6292.tar.zst
firejail-d380de39f039cf23a992b08c506cc200a7cf6292.zip
Add deterministic-exit-code option to ensure firejail exits with the first childs exit code regardless of the termination ordering of orphaned children
Diffstat (limited to 'src')
-rw-r--r--src/firejail/firejail.h1
-rw-r--r--src/firejail/main.c4
-rw-r--r--src/firejail/profile.c5
-rw-r--r--src/firejail/sandbox.c7
-rw-r--r--src/firejail/usage.c1
-rw-r--r--src/man/firejail-profile.txt4
-rw-r--r--src/man/firejail.txt4
7 files changed, 24 insertions, 2 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h
index e0f3a6a16..b2083d6ad 100644
--- a/src/firejail/firejail.h
+++ b/src/firejail/firejail.h
@@ -315,6 +315,7 @@ extern int arg_notv; // --notv
315extern int arg_nodvd; // --nodvd 315extern int arg_nodvd; // --nodvd
316extern int arg_nou2f; // --nou2f 316extern int arg_nou2f; // --nou2f
317extern int arg_nodbus; // -nodbus 317extern int arg_nodbus; // -nodbus
318extern int arg_deterministic_exit_code; // always exit with first childs exit status
318 319
319extern int login_shell; 320extern int login_shell;
320extern int parent_to_child_fds[2]; 321extern int parent_to_child_fds[2];
diff --git a/src/firejail/main.c b/src/firejail/main.c
index f3dc72944..3e2cc3a17 100644
--- a/src/firejail/main.c
+++ b/src/firejail/main.c
@@ -125,6 +125,7 @@ int arg_notv = 0; // --notv
125int arg_nodvd = 0; // --nodvd 125int arg_nodvd = 0; // --nodvd
126int arg_nodbus = 0; // -nodbus 126int arg_nodbus = 0; // -nodbus
127int arg_nou2f = 0; // --nou2f 127int arg_nou2f = 0; // --nou2f
128int arg_deterministic_exit_code = 0; // always exit with first childs exit status
128int login_shell = 0; 129int login_shell = 0;
129 130
130 131
@@ -2275,6 +2276,9 @@ int main(int argc, char **argv) {
2275 return 1; 2276 return 1;
2276 } 2277 }
2277 } 2278 }
2279 else if (strcmp(argv[i], "--deterministic-exit-code") == 0) {
2280 arg_deterministic_exit_code = 1;
2281 }
2278 else { 2282 else {
2279 // double dash - positional params to follow 2283 // double dash - positional params to follow
2280 if (strcmp(argv[i], "--") == 0) { 2284 if (strcmp(argv[i], "--") == 0) {
diff --git a/src/firejail/profile.c b/src/firejail/profile.c
index c8619f7e2..55d3cf5b0 100644
--- a/src/firejail/profile.c
+++ b/src/firejail/profile.c
@@ -1301,6 +1301,11 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
1301 return 0; 1301 return 0;
1302 } 1302 }
1303 1303
1304 if (strcmp(ptr, "deterministic-exit-code") == 0) {
1305 arg_deterministic_exit_code = 1;
1306 return 0;
1307 }
1308
1304 // rest of filesystem 1309 // rest of filesystem
1305 if (strncmp(ptr, "blacklist ", 10) == 0) 1310 if (strncmp(ptr, "blacklist ", 10) == 0)
1306 ptr += 10; 1311 ptr += 10;
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c
index 9f0a5f25c..c09a1bc73 100644
--- a/src/firejail/sandbox.c
+++ b/src/firejail/sandbox.c
@@ -271,6 +271,7 @@ static int monitor_application(pid_t app_pid) {
271 } 271 }
272 272
273 int status = 0; 273 int status = 0;
274 int app_status = 0;
274 while (monitored_pid) { 275 while (monitored_pid) {
275 usleep(20000); 276 usleep(20000);
276 char *msg; 277 char *msg;
@@ -295,6 +296,8 @@ static int monitor_application(pid_t app_pid) {
295 sleep(1); 296 sleep(1);
296 break; 297 break;
297 } 298 }
299 else if (rv == app_pid)
300 app_status = status;
298 301
299 // handle --timeout 302 // handle --timeout
300 if (options) { 303 if (options) {
@@ -352,8 +355,8 @@ static int monitor_application(pid_t app_pid) {
352 printf("Sandbox monitor: monitoring %d\n", monitored_pid); 355 printf("Sandbox monitor: monitoring %d\n", monitored_pid);
353 } 356 }
354 357
355 // return the latest exit status. 358 // return the appropriate exit status.
356 return status; 359 return arg_deterministic_exit_code ? app_status : status;
357} 360}
358 361
359static void print_time(void) { 362static void print_time(void) {
diff --git a/src/firejail/usage.c b/src/firejail/usage.c
index 7620bba82..ab749413b 100644
--- a/src/firejail/usage.c
+++ b/src/firejail/usage.c
@@ -66,6 +66,7 @@ static char *usage_str =
66#ifdef HAVE_NETWORK 66#ifdef HAVE_NETWORK
67 " --defaultgw=address - configure default gateway.\n" 67 " --defaultgw=address - configure default gateway.\n"
68#endif 68#endif
69 " --deterministic-exit-code - always exit with first childs status code.\n"
69 " --dns=address - set DNS server.\n" 70 " --dns=address - set DNS server.\n"
70 " --dns.print=name|pid - print DNS configuration.\n" 71 " --dns.print=name|pid - print DNS configuration.\n"
71 " --env=name=value - set environment variable.\n" 72 " --env=name=value - set environment variable.\n"
diff --git a/src/man/firejail-profile.txt b/src/man/firejail-profile.txt
index 703fac30f..cbc745af7 100644
--- a/src/man/firejail-profile.txt
+++ b/src/man/firejail-profile.txt
@@ -661,6 +661,10 @@ instead of the default one.
661Join the sandbox identified by name or start a new one. 661Join the sandbox identified by name or start a new one.
662Same as "firejail --join=sandboxname" command if sandbox with specified name exists, otherwise same as "name sandboxname". 662Same as "firejail --join=sandboxname" command if sandbox with specified name exists, otherwise same as "name sandboxname".
663 663
664.TP
665\fBdeterministic-exit-code
666Always exit firejail with the first childs exit status. The default behavior is to use the exit status of the final child to exit, which can be nondeterministic.
667
664.SH FILES 668.SH FILES
665/etc/firejail/filename.profile, $HOME/.config/firejail/filename.profile 669/etc/firejail/filename.profile, $HOME/.config/firejail/filename.profile
666 670
diff --git a/src/man/firejail.txt b/src/man/firejail.txt
index e6826448b..fcc7f66d7 100644
--- a/src/man/firejail.txt
+++ b/src/man/firejail.txt
@@ -410,6 +410,10 @@ Example:
410$ firejail \-\-disable-mnt firefox 410$ firejail \-\-disable-mnt firefox
411 411
412.TP 412.TP
413\fB\-\-deterministic-exit-code
414Always exit firejail with the first childs exit status. The default behavior is to use the exit status of the final child to exit, which can be nondeterministic.
415
416.TP
413\fB\-\-dns=address 417\fB\-\-dns=address
414Set a DNS server for the sandbox. Up to three DNS servers can be defined. 418Set a DNS server for the sandbox. Up to three DNS servers can be defined.
415Use this option if you don't trust the DNS setup on your network. 419Use this option if you don't trust the DNS setup on your network.