While working on the exeter tests, I noticed a couple of things missing in nstool. These make sense standalone, even if we don't have an urgent need for them without the exeter tests. David Gibson (2): test: Rename propagating signal handler test: Make nstool hold robust against interruptions to control clients test/nstool.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) -- 2.47.0
nstool in "exec" mode will propagate some signals (specifically SIGTERM) to the process in the namespace it executes. The signal handler which accomplishes this is called simply sig_handler(). However, it turns out we're going to need some other signal handlers, so rename this to the more specific sig_propagate(). Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/nstool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/nstool.c b/test/nstool.c index fc357d8..3f75edd 100644 --- a/test/nstool.c +++ b/test/nstool.c @@ -346,7 +346,7 @@ static int openns(const char *fmt, ...) } static pid_t sig_pid; -static void sig_handler(int signum) +static void sig_propagate(int signum) { int err; @@ -358,7 +358,7 @@ static void sig_handler(int signum) static void wait_for_child(pid_t pid) { struct sigaction sa = { - .sa_handler = sig_handler, + .sa_handler = sig_propagate, .sa_flags = SA_RESETHAND, }; int status, err; -- 2.47.0
Currently nstool die()s on essentially any error. In most cases that's fine for our purposes. However, it's a problem when in "hold" mode and getting an IO error on an accept()ed socket. This could just indicate that the control client aborted prematurely, in which case we don't want to kill of the namespace we're holding. Adjust these to print an error, close() the control client socket and carry on. In addition, we need to explicitly ignore SIGPIPE in order not to be killed by an abruptly closed client connection. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/nstool.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/test/nstool.c b/test/nstool.c index 3f75edd..7ab5d2a 100644 --- a/test/nstool.c +++ b/test/nstool.c @@ -31,10 +31,15 @@ #define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0]))) -#define die(...) \ - do { \ - fprintf(stderr, __VA_ARGS__); \ - exit(1); \ +#define die(...) \ + do { \ + fprintf(stderr, "nstool: " __VA_ARGS__); \ + exit(1); \ + } while (0) + +#define err(...) \ + do { \ + fprintf(stderr, "nstool: " __VA_ARGS__); \ } while (0) struct ns_type { @@ -156,6 +161,9 @@ static int connect_ctl(const char *sockpath, bool wait, static void cmd_hold(int argc, char *argv[]) { + struct sigaction sa = { + .sa_handler = SIG_IGN, + }; int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, PF_UNIX); struct sockaddr_un addr; const char *sockpath = argv[1]; @@ -185,6 +193,10 @@ static void cmd_hold(int argc, char *argv[]) if (!getcwd(info.cwd, sizeof(info.cwd))) die("getcwd(): %s\n", strerror(errno)); + rc = sigaction(SIGPIPE, &sa, NULL); + if (rc) + die("sigaction(SIGPIPE): %s\n", strerror(errno)); + do { int afd = accept(fd, NULL, NULL); char buf; @@ -193,17 +205,21 @@ static void cmd_hold(int argc, char *argv[]) die("accept(): %s\n", strerror(errno)); rc = write(afd, &info, sizeof(info)); - if (rc < 0) - die("write(): %s\n", strerror(errno)); + if (rc < 0) { + err("holder write() to control socket: %s\n", + strerror(errno)); + } if ((size_t)rc < sizeof(info)) - die("short write() on control socket\n"); + err("holder short write() on control socket\n"); rc = read(afd, &buf, sizeof(buf)); - if (rc < 0) - die("read(): %s\n", strerror(errno)); + if (rc < 0) { + err("holder read() on control socket: %s\n", + strerror(errno)); + } close(afd); - } while (rc == 0); + } while (rc <= 0); unlink(sockpath); } -- 2.47.0
On Wed, 6 Nov 2024 14:03:20 +1100 David Gibson <david(a)gibson.dropbear.id.au> wrote:While working on the exeter tests, I noticed a couple of things missing in nstool. These make sense standalone, even if we don't have an urgent need for them without the exeter tests. David Gibson (2): test: Rename propagating signal handler test: Make nstool hold robust against interruptions to control clientsApplied. Actually, one much-needed improvement for nstool in the current test framework (at least for my usage) would be to make it terminate when needed. A while ago, 'killall -9 nstool' entered my shell history and now it's right there with 'git rebase --continue': $ sort ~/.bash_history | uniq -c | sort -nr | grep -A1 'killall -9 nstool' 192 killall -9 nstool 192 git rebase --continue -- Stefano
On Thu, Nov 07, 2024 at 03:54:43PM +0100, Stefano Brivio wrote:On Wed, 6 Nov 2024 14:03:20 +1100 David Gibson <david(a)gibson.dropbear.id.au> wrote:Yeah, I have something similar. But, I don't currently know what exactly the circumstances are that lead to those stale nstools, so it would involve a fair bit of debugging. -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibsonWhile working on the exeter tests, I noticed a couple of things missing in nstool. These make sense standalone, even if we don't have an urgent need for them without the exeter tests. David Gibson (2): test: Rename propagating signal handler test: Make nstool hold robust against interruptions to control clientsApplied. Actually, one much-needed improvement for nstool in the current test framework (at least for my usage) would be to make it terminate when needed. A while ago, 'killall -9 nstool' entered my shell history and now it's right there with 'git rebase --continue': $ sort ~/.bash_history | uniq -c | sort -nr | grep -A1 'killall -9 nstool' 192 killall -9 nstool 192 git rebase --continue
On Fri, 8 Nov 2024 10:30:00 +1100 David Gibson <david(a)gibson.dropbear.id.au> wrote:On Thu, Nov 07, 2024 at 03:54:43PM +0100, Stefano Brivio wrote:Start tests, the ones using nstool (not the "ugly" ones), then ^C ^D until you're out of tmux, and nstool is _always_ there at that point. -- StefanoOn Wed, 6 Nov 2024 14:03:20 +1100 David Gibson <david(a)gibson.dropbear.id.au> wrote:Yeah, I have something similar. But, I don't currently know what exactly the circumstances are that lead to those stale nstools, so it would involve a fair bit of debugging.While working on the exeter tests, I noticed a couple of things missing in nstool. These make sense standalone, even if we don't have an urgent need for them without the exeter tests. David Gibson (2): test: Rename propagating signal handler test: Make nstool hold robust against interruptions to control clientsApplied. Actually, one much-needed improvement for nstool in the current test framework (at least for my usage) would be to make it terminate when needed. A while ago, 'killall -9 nstool' entered my shell history and now it's right there with 'git rebase --continue': $ sort ~/.bash_history | uniq -c | sort -nr | grep -A1 'killall -9 nstool' 192 killall -9 nstool 192 git rebase --continue
On Fri, Nov 08, 2024 at 01:05:43AM +0100, Stefano Brivio wrote:On Fri, 8 Nov 2024 10:30:00 +1100 David Gibson <david(a)gibson.dropbear.id.au> wrote:Huh. I usually exit with ^B-& then ^C and that only occasionally leaves things behind. -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibsonOn Thu, Nov 07, 2024 at 03:54:43PM +0100, Stefano Brivio wrote:Start tests, the ones using nstool (not the "ugly" ones), then ^C ^D until you're out of tmux, and nstool is _always_ there at that point.On Wed, 6 Nov 2024 14:03:20 +1100 David Gibson <david(a)gibson.dropbear.id.au> wrote:Yeah, I have something similar. But, I don't currently know what exactly the circumstances are that lead to those stale nstools, so it would involve a fair bit of debugging.While working on the exeter tests, I noticed a couple of things missing in nstool. These make sense standalone, even if we don't have an urgent need for them without the exeter tests. David Gibson (2): test: Rename propagating signal handler test: Make nstool hold robust against interruptions to control clientsApplied. Actually, one much-needed improvement for nstool in the current test framework (at least for my usage) would be to make it terminate when needed. A while ago, 'killall -9 nstool' entered my shell history and now it's right there with 'git rebase --continue': $ sort ~/.bash_history | uniq -c | sort -nr | grep -A1 'killall -9 nstool' 192 killall -9 nstool 192 git rebase --continue