Skip to content

Commit

Permalink
rework exitcodes
Browse files Browse the repository at this point in the history
* add 128 to exitcode if child receives a fatal signal
(this is similar to what bash and other shells do)
* unify exitcodes across firejail: treat join'ed processes
the same as processes in the primary process tree
  • Loading branch information
smitsohu committed Sep 11, 2021
1 parent e17223e commit f167b0e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/firejail/join.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ void join(pid_t pid, int argc, char **argv, int index) {
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);

#ifdef HAVE_APPARMOR
// add apparmor confinement after the execve
set_apparmor();
#endif

Expand Down Expand Up @@ -601,9 +600,9 @@ void join(pid_t pid, int argc, char **argv, int index) {
if (WIFEXITED(status)) {
status = WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
status = WTERMSIG(status);
status = 128 + WTERMSIG(status);
} else {
status = 0;
status = -1;
}

exit(status);
Expand Down
6 changes: 3 additions & 3 deletions src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3216,10 +3216,10 @@ printf("link #%s#\n", prf->link);
if (WIFEXITED(status)){
myexit(WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
myexit(WTERMSIG(status));
myexit(128 + WTERMSIG(status));
} else {
myexit(0);
myexit(1);
}

return 0;
return 1;
}
11 changes: 7 additions & 4 deletions src/firejail/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,6 @@ int sandbox(void* sandbox_arg) {

if (app_pid == 0) {
#ifdef HAVE_APPARMOR
// add apparmor confinement after the execve
set_apparmor();
#endif

Expand All @@ -1262,9 +1261,13 @@ int sandbox(void* sandbox_arg) {

if (WIFEXITED(status)) {
// if we had a proper exit, return that exit status
return WEXITSTATUS(status);
status = WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
// distinguish fatal signals by adding 128
status = 128 + WTERMSIG(status);
} else {
// something else went wrong!
return -1;
status = -1;
}

return status;
}

0 comments on commit f167b0e

Please sign in to comment.