nspawn: surrender controlling terminal to PID2 when using the PID1 stub
authorNicolas Douma <nicolas@serveur.io>
Tue, 17 Sep 2019 03:07:00 +0000 (05:07 +0200)
committerMichael Biebl <biebl@debian.org>
Tue, 19 Nov 2019 08:17:12 +0000 (08:17 +0000)
(cherry picked from commit de1b29f375b13b0566814517bf81e3cdbdd9a610)
(cherry picked from commit fbad077cec34c922a985d894d8181ceefc852ec8)

Gbp-Pq: Name nspawn-surrender-controlling-terminal-to-PID2-when-using-.patch

src/nspawn/nspawn-stub-pid1.c

index ebf4f0f523c989d64724967b68996d317ce9c92c..0589685afe308fff8a92a990a86c5340c11f68e3 100644 (file)
@@ -53,6 +53,12 @@ int stub_pid1(sd_id128_t uuid) {
         assert_se(sigfillset(&fullmask) >= 0);
         assert_se(sigprocmask(SIG_BLOCK, &fullmask, &oldmask) >= 0);
 
+        /* Surrender the terminal this stub may control so that child processes can have a controlling terminal
+         * without resorting to setsid hacks. */
+        r = ioctl(STDIN_FILENO, TIOCNOTTY);
+        if (r < 0 && errno != ENOTTY)
+                return log_error_errno(errno, "Failed to surrender controlling terminal: %m");
+
         pid = fork();
         if (pid < 0)
                 return log_error_errno(errno, "Failed to fork child pid: %m");