aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-08-05 22:36:41 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-08-07 09:16:48 +0200
commit755f9fd91125c65361c81d8aa9e8af2cfd7adc6d (patch)
treec42ea64d4aaf8e08cfc8275da411f63c06e3b1b7
parent5ca61c2f34cdcadb486ad1e186aeb9c7df8c132e (diff)
downloadpasst-755f9fd91125c65361c81d8aa9e8af2cfd7adc6d.tar
passt-755f9fd91125c65361c81d8aa9e8af2cfd7adc6d.tar.gz
passt-755f9fd91125c65361c81d8aa9e8af2cfd7adc6d.tar.bz2
passt-755f9fd91125c65361c81d8aa9e8af2cfd7adc6d.tar.lz
passt-755f9fd91125c65361c81d8aa9e8af2cfd7adc6d.tar.xz
passt-755f9fd91125c65361c81d8aa9e8af2cfd7adc6d.tar.zst
passt-755f9fd91125c65361c81d8aa9e8af2cfd7adc6d.zip
nstool: Propagate SIGTERM to processes executed in the namespace
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@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--test/nstool.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/test/nstool.c b/test/nstool.c
index a6aca98..fc357d8 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));
+}
+
static void wait_for_child(pid_t pid)
{
- int status;
+ struct sigaction sa = {
+ .sa_handler = sig_handler,
+ .sa_flags = SA_RESETHAND,
+ };
+ int status, err;
+
+ sig_pid = pid;
+ err = sigaction(SIGTERM, &sa, NULL);
+ if (err)
+ die("sigaction(SIGTERM): %s\n", strerror(errno));
/* Match the child's exit status, if possible */
for (;;) {
pid_t rc;
rc = waitpid(pid, &status, WUNTRACED);
- if (rc < 0)
+ if (rc < 0) {
+ if (errno == EINTR)
+ continue;
die("waitpid() on %d: %s\n", pid, strerror(errno));
+ }
if (rc != pid)
die("waitpid() on %d returned %d", pid, rc);
if (WIFSTOPPED(status)) {