[glib] GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC



commit c078223b388939f3f7cb77bdaa8b60aad0713756
Author: Colin Walters <walters verbum org>
Date:   Mon May 2 15:42:51 2011 -0400

    GCancellable: Use g_unix_pipe_flags with FD_CLOEXEC
    
    The old code was creating a pipe and setting FD_CLOEXEC
    non-atomically.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=649225

 gio/gcancellable.c |   18 +-----------------
 1 files changed, 1 insertions(+), 17 deletions(-)
---
diff --git a/gio/gcancellable.c b/gio/gcancellable.c
index 32f5081..5a078b4 100644
--- a/gio/gcancellable.c
+++ b/gio/gcancellable.c
@@ -194,34 +194,18 @@ g_cancellable_class_init (GCancellableClass *klass)
 #ifndef G_OS_WIN32
 
 static void
-set_fd_close_exec (int fd)
-{
-  int flags;
-
-  flags = fcntl (fd, F_GETFD, 0);
-  if (flags != -1 && (flags & FD_CLOEXEC) == 0)
-    {
-      flags |= FD_CLOEXEC;
-      fcntl (fd, F_SETFD, flags);
-    }
-}
-
-
-static void
 g_cancellable_open_pipe (GCancellable *cancellable)
 {
   GCancellablePrivate *priv;
 
   priv = cancellable->priv;
-  if (pipe (priv->cancel_pipe) == 0)
+  if (g_unix_pipe_flags (priv->cancel_pipe, FD_CLOEXEC, NULL))
     {
       /* Make them nonblocking, just to be sure we don't block
        * on errors and stuff
        */
       g_unix_set_fd_nonblocking (priv->cancel_pipe[0], TRUE, NULL);
       g_unix_set_fd_nonblocking (priv->cancel_pipe[1], TRUE, NULL);
-      set_fd_close_exec (priv->cancel_pipe[0]);
-      set_fd_close_exec (priv->cancel_pipe[1]);
       
       if (priv->cancelled)
         {



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