com_enter(): Avoid hang if container is shut down.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 23 Mar 2025 13:43:57 +0000 (14:43 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 23 Mar 2025 13:43:57 +0000 (14:43 +0100)
util.c

diff --git a/util.c b/util.c
index 997f9eb194f8e5474874ed6c24ed25f1f2975178..f4f941e94683b6810b7b9bbe59c57de32abd4145 100644 (file)
--- a/util.c
+++ b/util.c
@@ -167,8 +167,17 @@ bool xexec(char * const argv[])
                die_errno("fork");
        if (pid > 0) { /* parent */
                int wstatus;
-               if (waitpid(pid, &wstatus, 0) < 0)
+               if (waitpid(pid, &wstatus, WUNTRACED) < 0)
                        die_errno("waitp");
+               /*
+                * If the user shuts down the container from an interactive
+                * com_enter() shell, the nsenter process receives SIGSTOP
+                * because the container shuts down the controlling tty,
+                * causing the shell to hang. Avoid this by letting the process
+                * continue once.
+                */
+               if (WIFSTOPPED(wstatus))
+                       kill(pid, SIGCONT);
                if (!WIFEXITED(wstatus))
                        return false;
                if (WEXITSTATUS(wstatus) != EXIT_SUCCESS)