Skip to content

Commit

Permalink
lxc-attach: Fix lost return codes of spawned processes that are killed
Browse files Browse the repository at this point in the history
lxc-attach swallows the return codes of processes that are terminated
via a signal, and by default exits with a return code of 0 (i.e.
indicating success) even if the command it tried to execute was
terminated.

This patch fixes it by explicitly checking if the process was terminated
via a signal, and returning an appropriate exit code.

Note that we add 128 to the signal value to generate the exit code
because by convention the exit code is 128 + signal number. e.g. if a
process is killed via signal 9, then the error code is 9 + 128 = 137.

Signed-off-by: Mohammed Ajmal Siddiqui <ajmalsiddiqui21@gmail.com>
  • Loading branch information
ajmalsiddiqui committed Oct 5, 2022
1 parent fb319ca commit 4ebca5a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lxc/tools/lxc_attach.c
Expand Up @@ -399,6 +399,8 @@ int lxc_attach_main(int argc, char *argv[])
}
if (WIFEXITED(ret))
wexit = WEXITSTATUS(ret);
else if (WIFSIGNALED(ret))
wexit = WTERMSIG(ret) + 128;

out:
lxc_container_put(c);
Expand Down

0 comments on commit 4ebca5a

Please sign in to comment.