On Mon, 5 Aug 2024 22:36:41 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:Particularly in shell it's sometimes natural to save the pid from a process run and later kill it. If doing this with nstool exec, however, it will kill nstool itself, not the program it is running, which isn't usually what you want or expect. Address this by having nstool propagate SIGTERM to its child process. It may make sense to propagate some other signals, but some introduce extra complications, so we'll worry about them when and if it seems useful. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/nstool.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/nstool.c b/test/nstool.c index a6aca981..fc357d8a 100644 --- a/test/nstool.c +++ b/test/nstool.c @@ -345,17 +345,39 @@ static int openns(const char *fmt, ...) return fd; } +static pid_t sig_pid; +static void sig_handler(int signum) +{ + int err; + + err = kill(sig_pid, signum); + if (err) + die("Propagating %s: %s\n", strsignal(signum), strerror(errno));As I've just been bitten by this, f30ed68c5273 ("pasta: Save errno on signal handler entry, restore on return when needed"), I was kind of wondering if we should save and restore errno, regardless of the fact it's not needed here (if kill() affects ernno, we won't return). On the other hand this handler at the moment is simple enough that we would notice if it's needed because of some further changes. -- Stefano