From 0a0ab0703ae6ec453e7b011ca1fb78049303166b Mon Sep 17 00:00:00 2001 From: modeco80 Date: Fri, 2 Feb 2024 20:37:34 -0500 Subject: [PATCH] Make Process do prctl(PR_SET_PDEATHSIG) This means that nanosm managed process will also predictably die if nanosm is killed. --- src/Process.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Process.cpp b/src/Process.cpp index 5145723..544a1b1 100644 --- a/src/Process.cpp +++ b/src/Process.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "WordExp.hpp" @@ -49,6 +50,12 @@ namespace nanosm { for(usize i = 0; i < exp.words.size(); ++i) argv[i] = exp.words[i].data(); + // Ensure that if nanosm (the parent) dies, we die along with it + if(prctl(PR_SET_PDEATHSIG, SIGTERM) == -1) { + perror("Process pre-exec: prctl(PR_SET_PDEATHSIG)"); + exit(1); + } + exit(execvp(exp.words[0].data(), argv.data())); } else { // Parent: monitor the pidfd by adding ourselves to the event loop now