[gnome-builder] pty: use g_unix_set_fd_nonblocking()



commit db5ec733d595b77a0247ea814908f718a717a274
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 24 16:00:11 2018 -0800

    pty: use g_unix_set_fd_nonblocking()
    
    We can use g_unix_set_fd_nonblocking() rather than O_NONBLOCKING manually,
    which may not work with F_SETFD anyway.
    
    This should fix things up for FreeBSD in a more portable way.
    
    #361

 src/libide/util/ptyintercept.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/src/libide/util/ptyintercept.c b/src/libide/util/ptyintercept.c
index d8bd6597e..523eff238 100644
--- a/src/libide/util/ptyintercept.c
+++ b/src/libide/util/ptyintercept.c
@@ -122,15 +122,20 @@ pty_intercept_create_slave (pty_fd_t master_fd)
 
       ret = open (name, O_RDWR | O_CLOEXEC);
       if (ret == PTY_FD_INVALID && errno == EINVAL)
-        ret = open (name, O_RDWR | O_CLOEXEC);
+        ret = open (name, O_RDWR);
 
       if (ret == PTY_FD_INVALID)
         return PTY_FD_INVALID;
 
+      /* Add FD_CLOEXEC if O_CLOEXEC failed */
       flags = fcntl (ret, F_GETFD, 0);
-      flags |= O_NONBLOCK | FD_CLOEXEC;
+      if ((flags & FD_CLOEXEC) == 0)
+        {
+          if (fcntl (ret, F_SETFD, flags | FD_CLOEXEC) < 0)
+            return PTY_FD_INVALID;
+        }
 
-      if (fcntl (ret, F_SETFD, flags) < 0)
+      if (!g_unix_set_fd_nonblocking (ret, TRUE, NULL))
         return PTY_FD_INVALID;
     }
 


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