aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-25 22:24:00 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-25 22:30:19 +0200
commit75dea27979f0d219eed9c6afc3a721f592f7ca2a (patch)
treea7724d2cf73aae17bddeddd3c3d0906320f35e18
parent7c5cd1e104f23ec7d9c23086993630f398e2d8e0 (diff)
Terminate the unpacker child processes if the main process exits
Should the main process exit (e.g. the user presses CTRL+C) or explcitily sends it a signal, the desired behaviour is for the children to stop unpacking and exit. This commit adds a line to configure the kernel to send SIGKILL to the children if their parent dies. The same option also exists on various BSDs (not all of them) but with a different name which has to be checked for and adjusted should the program be required to run on one of those. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--unpack/fill_files.c3
-rw-r--r--unpack/rdsquashfs.h1
2 files changed, 4 insertions, 0 deletions
diff --git a/unpack/fill_files.c b/unpack/fill_files.c
index 865d050..88efd01 100644
--- a/unpack/fill_files.c
+++ b/unpack/fill_files.c
@@ -97,6 +97,9 @@ int fill_unpacked_files(fstree_t *fs, data_reader_t *data, int flags,
pid = fork();
if (pid == 0) {
+ /* Kill the child when the parent process dies */
+ prctl(PR_SET_PDEATHSIG, SIGKILL);
+
if (fill_files(data, sublists[i], flags))
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS);
diff --git a/unpack/rdsquashfs.h b/unpack/rdsquashfs.h
index 34404b0..8866679 100644
--- a/unpack/rdsquashfs.h
+++ b/unpack/rdsquashfs.h
@@ -15,6 +15,7 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
+#include <sys/prctl.h>
#include <sys/wait.h>
#include <string.h>
#include <stdlib.h>