diff mbox

[1/3] helper: linux: request SIGTERM if parent process dies

Message ID 1446210967-23576-2-git-send-email-carl.wallen@nokia.com
State Accepted
Commit 3d0dafc1dc72dab028db1b06f183339e7d578d5b
Headers show

Commit Message

Wallen, Carl (Nokia - FI/Espoo) Oct. 30, 2015, 1:16 p.m. UTC
Request SIGTERM be sent to forked child processes if the parent
process dies.

Signed-off-by: Carl Wallen <carl.wallen@nokia.com>
---
 helper/linux.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox

Patch

diff --git a/helper/linux.c b/helper/linux.c
index 3d3b6b8..3d5da18 100644
--- a/helper/linux.c
+++ b/helper/linux.c
@@ -11,6 +11,7 @@ 
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/prctl.h>
 
 #include <stdlib.h>
 #include <string.h>
@@ -167,6 +168,13 @@  int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl,
 		}
 
 		/* Child process */
+
+		/* Request SIGTERM if parent dies */
+		prctl(PR_SET_PDEATHSIG, SIGTERM);
+		/* Parent died already? */
+		if (getppid() == 1)
+			kill(getpid(), SIGTERM);
+
 		if (sched_setaffinity(0, sizeof(cpu_set_t), &proc_mask.set)) {
 			ODPH_ERR("sched_setaffinity() failed\n");
 			return -2;