[glib] gio: don't assume that SOCK_CLOEXEC is supported whenever it's defined



commit 732ff1b27cc6f7bbbb1133bf8e7cb3de8475f72a
Author: Julien Cristau <jcristau debian org>
Date:   Thu Jul 15 15:26:02 2010 +0100

    gio: don't assume that SOCK_CLOEXEC is supported whenever it's defined
    
    Just because SOCK_CLOEXEC was defined at build time doesn't mean the
    kernel we're running on supports it.  So if socket() fails with EINVAL,
    try again without the flag.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=624463

 gio/gsocket.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index e2ba788..5ab7778 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -455,9 +455,11 @@ g_socket_create_socket (GSocketFamily   family,
     }
 
 #ifdef SOCK_CLOEXEC
-  native_type |= SOCK_CLOEXEC;
+  fd = socket (family, native_type | SOCK_CLOEXEC, protocol);
+  /* It's possible that libc has SOCK_CLOEXEC but the kernel does not */
+  if (fd < 0 && errno == EINVAL)
 #endif
-  fd = socket (family, native_type, protocol);
+    fd = socket (family, native_type, protocol);
 
   if (fd < 0)
     {



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