[vte] pty: Simplify acquiring a new PTY master



commit 33361f1ec6e7d19a550f69c009fae9de88051646
Author: Christian Persch <chpe gnome org>
Date:   Sun Nov 29 20:57:54 2015 +0100

    pty: Simplify acquiring a new PTY master
    
    All supported OSes either use openpty (BSDs) or have posix_openpt
    (linux, illumos). So there is no need to offer a fallback to grantpt(3)
    or to opening /dev/ptmx directly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747046

 configure.ac |    2 +-
 src/pty.cc   |   20 ++++----------------
 2 files changed, 5 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9b2783a..a7817f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -272,7 +272,7 @@ AC_CHECK_FUNCS([posix_openpt grantpt unlockpt ptsname],[],[
 AC_SUBST([LIBUTIL])
 
 # Misc PTY handling functions
-AC_CHECK_FUNCS([cfmakeraw fork setsid setpgid getpgid ptsname_r tcgetattr tcsetattr])
+AC_CHECK_FUNCS([cfmakeraw fork setsid setpgid getpgid tcgetattr tcsetattr])
 
 # Misc I/O routines.
 AC_CHECK_FUNCS([pread pwrite])
diff --git a/src/pty.cc b/src/pty.cc
index c10d591..0f89ec7 100644
--- a/src/pty.cc
+++ b/src/pty.cc
@@ -621,27 +621,15 @@ vte_pty_get_size(VtePty *pty,
 static int
 _vte_pty_getpt(GError **error)
 {
-       int fd, flags, rv;
-#if defined(HAVE_POSIX_OPENPT)
-       fd = posix_openpt(O_RDWR | O_NOCTTY);
-#elif defined(HAVE_GETPT)
-       /* Call the system's function for allocating a pty. */
-       fd = getpt();
-#else
-       /* Try to allocate a pty by accessing the pty master multiplex. */
-       fd = open("/dev/ptmx", O_RDWR | O_NOCTTY);
-       if ((fd == -1) && (errno == ENOENT)) {
-               fd = open("/dev/ptc", O_RDWR | O_NOCTTY); /* AIX */
-       }
-#endif
+       int fd = posix_openpt(O_RDWR | O_NOCTTY);
         if (fd == -1) {
                 g_set_error (error, VTE_PTY_ERROR,
                              VTE_PTY_ERROR_PTY98_FAILED,
-                             "%s failed: %s", "getpt", g_strerror(errno));
+                             "%s failed: %s", "posix_openpt", g_strerror(errno));
                 return -1;
         }
 
-        rv = fcntl(fd, F_GETFL, 0);
+        int rv = fcntl(fd, F_GETFL, 0);
         if (rv < 0) {
                 int errsv = errno;
                 g_set_error(error, VTE_PTY_ERROR,
@@ -654,7 +642,7 @@ _vte_pty_getpt(GError **error)
 
        /* Set it to blocking. */
         /* FIXMEchpe: why?? vte_terminal_set_pty does the inverse... */
-        flags = rv & ~(O_NONBLOCK);
+        int flags = rv & ~(O_NONBLOCK);
         rv = fcntl(fd, F_SETFL, flags);
         if (rv < 0) {
                 int errsv = errno;


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