[vte/vte-0-60] pty: Call grantpt/unlockpt when opening the PTY



commit a9432af3d4478a1be809269ad2a4edb7d4424328
Author: Christian Persch <chpe src gnome org>
Date:   Mon Apr 27 21:45:32 2020 +0200

    pty: Call grantpt/unlockpt when opening the PTY
    
    ... instead of in the child after fork.
    
    This fixes an infrequent deadlock in the NSS code when grantpt
    is called in the child while it was in use in another thread in
    the parent process.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-terminal/-/issues/195
    (cherry picked from commit fc75bd93068041860276cd8b75d73d2d95dd9667)

 src/pty.cc | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/src/pty.cc b/src/pty.cc
index 4f2bcce5..3db1a7c5 100644
--- a/src/pty.cc
+++ b/src/pty.cc
@@ -128,16 +128,6 @@ Pty::child_setup() const noexcept
         if (masterfd == -1)
                 _exit(127);
 
-        if (grantpt(masterfd) != 0) {
-                _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "grantpt");
-                _exit(127);
-        }
-
-       if (unlockpt(masterfd) != 0) {
-                _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "unlockpt");
-                _exit(127);
-        }
-
         if (!(m_flags & VTE_PTY_NO_SESSION)) {
                 /* This starts a new session; we become its process-group leader,
                  * and lose our controlling TTY.
@@ -622,6 +612,18 @@ fd_set_cpkt(int fd)
 static int
 fd_setup(int fd)
 {
+        if (grantpt(fd) != 0) {
+                vte::util::restore_errno errsv;
+                _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "grantpt");
+                return -1;
+        }
+
+        if (unlockpt(fd) != 0) {
+                vte::util::restore_errno errsv;
+                _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "unlockpt");
+                return -1;
+        }
+
         if (fd_set_cloexec(fd) < 0) {
                 vte::util::restore_errno errsv;
                 _vte_debug_print(VTE_DEBUG_PTY,
@@ -706,6 +708,18 @@ _vte_pty_open_posix(void)
                 return -1;
         }
 
+        if (grantpt(fd) != 0) {
+                vte::util::restore_errno errsv;
+                _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "grantpt");
+                return {};
+        }
+
+        if (unlockpt(fd) != 0) {
+                vte::util::restore_errno errsv;
+                _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "unlockpt");
+                return {};
+        }
+
        _vte_debug_print(VTE_DEBUG_PTY, "Allocated pty on fd %d.\n", (int)fd);
 
         return fd.steal();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]