gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r28877 - in libmicrohttpd: . src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r28877 - in libmicrohttpd: . src/microhttpd
Date: Tue, 27 Aug 2013 18:43:53 +0200

Author: grothoff
Date: 2013-08-27 18:43:53 +0200 (Tue, 27 Aug 2013)
New Revision: 28877

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/microhttpd/daemon.c
Log:
making build tolerate missing SOCK_NONBLOCK/EPOLL_CLOEXEC (older glibc)

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2013-08-27 16:43:15 UTC (rev 28876)
+++ libmicrohttpd/ChangeLog     2013-08-27 16:43:53 UTC (rev 28877)
@@ -1,3 +1,7 @@
+Tue Aug 27 18:39:08 CEST 2013
+       Fix build issue if SOCK_NONBLOCK/EPOLL_CLOEXEC are not
+       defined (as is the case on older glibc versions). -CG
+
 Mon Aug 12 23:51:18 CEST 2013
        Updated manual, documenting W32 select/shutdown issue. -CG
 

Modified: libmicrohttpd/src/microhttpd/daemon.c
===================================================================
--- libmicrohttpd/src/microhttpd/daemon.c       2013-08-27 16:43:15 UTC (rev 
28876)
+++ libmicrohttpd/src/microhttpd/daemon.c       2013-08-27 16:43:53 UTC (rev 
28877)
@@ -86,7 +86,11 @@
 #define SOCK_CLOEXEC 0
 #endif
 
+#ifndef EPOLL_CLOEXEC
+#define EPOLL_CLOEXEC 0
+#endif
 
+
 /**
  * Default implementation of the panic function,
  * prints an error message and aborts.
@@ -1511,9 +1515,8 @@
         }
       return MHD_NO;
     }
-#if !HAVE_ACCEPT4
-  make_nonblocking_noninheritable (daemon, s);
-#endif
+  if ( (! HAVE_ACCEPT4) || (0 == SOCK_CLOEXEC) )
+    make_nonblocking_noninheritable (daemon, s);
 #if HAVE_MESSAGES
 #if DEBUG_CONNECT
   MHD_DLOG (daemon, "Accepted connection on socket %d\n", s);
@@ -2794,62 +2797,30 @@
 /**
  * Create a listen socket, if possible with CLOEXEC flag set.
  *
+ * @param daemon daemon for which we create the socket
  * @param domain socket domain (i.e. PF_INET)
  * @param type socket type (usually SOCK_STREAM)
  * @param protocol desired protocol, 0 for default
  */
 static int
-create_socket (int domain, int type, int protocol)
+create_socket (struct MHD_Daemon *daemon,
+              int domain, int type, int protocol)
 {
-  static int sock_cloexec = SOCK_CLOEXEC;
-  int ctype = SOCK_STREAM | sock_cloexec;
+  int ctype = type | SOCK_CLOEXEC;
   int fd;
-  int flags;
-#ifdef WINDOWS
-  DWORD dwFlags;
-#endif
  
   /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
    * implementations do not set ai_socktype, e.g. RHL6.2. */
   fd = SOCKET (domain, ctype, protocol);
-  if ( (-1 == fd) && (EINVAL == errno) && (0 != sock_cloexec) )
+  if ( (-1 == fd) && (EINVAL == errno) && (0 != SOCK_CLOEXEC) )
   {
-    sock_cloexec = 0;
+    ctype = type;
     fd = SOCKET(domain, type, protocol);
   }
   if (-1 == fd)
     return -1;
-  if (0 != sock_cloexec)
-    return fd; /* this is it */  
-  /* flag was not set during 'socket' call, let's try setting it manually */
-#ifndef WINDOWS
-  flags = fcntl (fd, F_GETFD);
-  if (flags < 0)
-#else
-  if (!GetHandleInformation ((HANDLE) fd, &dwFlags))
-#endif
-  {
-#ifdef WINDOWS
-    SetErrnoFromWinError (GetLastError ());
-#endif
-    return fd; /* good luck */
-  }
-#ifndef WINDOWS
-  if (flags == (flags | FD_CLOEXEC))
-    return fd; /* already set */
-  flags |= FD_CLOEXEC;
-  if (0 != fcntl (fd, F_SETFD, flags))
-#else
-  if (dwFlags != (dwFlags | HANDLE_FLAG_INHERIT))
-    return fd; /* already unset */
-  if (!SetHandleInformation ((HANDLE) fd, HANDLE_FLAG_INHERIT, 0))
-#endif
-  {
-#ifdef WINDOWS
-    SetErrnoFromWinError (GetLastError ());
-#endif
-    return fd; /* good luck */
-  }
+  if (type == ctype)
+    make_nonblocking_noninheritable (daemon, fd);
   return fd;
 }
 
@@ -2878,6 +2849,9 @@
 #endif
       return MHD_NO;
     }
+  if (0 == EPOLL_CLOEXEC)
+    make_nonblocking_noninheritable (daemon, 
+                                    daemon->epoll_fd);
   if (-1 == daemon->socket_fd)
     return MHD_YES; /* non-listening daemon */
   event.events = EPOLLIN;
@@ -3155,9 +3129,11 @@
     {
       /* try to open listen socket */
       if ((flags & MHD_USE_IPv6) != 0)
-       socket_fd = create_socket (PF_INET6, SOCK_STREAM, 0);
+       socket_fd = create_socket (daemon,
+                                  PF_INET6, SOCK_STREAM, 0);
       else
-       socket_fd = create_socket (PF_INET, SOCK_STREAM, 0);
+       socket_fd = create_socket (daemon,
+                                  PF_INET, SOCK_STREAM, 0);
       if (-1 == socket_fd)
        {
 #if HAVE_MESSAGES




reply via email to

[Prev in Thread] Current Thread [Next in Thread]