[cpp-sp COMMIT] in /branches/REL_2: configure.ac shibsp/remoting/impl/TCPListener.cpp shibsp/remoting/impl/UnixListen...

noreply at shibboleth.net noreply at shibboleth.net
Wed May 29 15:08:47 EDT 2013


Author: scantor
Date: Wed May 29 15:08:47 2013
New Revision: 3858

URL: http://svn.shibboleth.net/view/cpp-sp?rev=3858&view=rev
Log:
https://issues.shibboleth.net/jira/browse/SSPCPP-569

Modified:
    branches/REL_2/configure.ac
    branches/REL_2/shibsp/remoting/impl/TCPListener.cpp
    branches/REL_2/shibsp/remoting/impl/UnixListener.cpp

Modified: branches/REL_2/configure.ac
URL: http://svn.shibboleth.net/view/cpp-sp/branches/REL_2/configure.ac?rev=3858&r1=3857&r2=3858&view=diff
==============================================================================
--- branches/REL_2/configure.ac (original)
+++ branches/REL_2/configure.ac Wed May 29 15:08:47 2013
@@ -81,6 +81,18 @@
 AC_CHECK_TYPES([struct sockaddr_storage], [], [], [[#include <sys/socket.h>]])
 AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [], [[#include <sys/socket.h>]])
 
+AC_CACHE_CHECK([for SOCK_CLOEXEC support], [shib_cv_sock_cloexec],
+[AC_TRY_RUN([
+#include <sys/types.h>
+#include <sys/socket.h>
+int main()
+{
+return socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0) == -1;
+}], [shib_cv_sock_cloexec=yes], [shib_cv_sock_cloexec=no], [shib_cv_sock_cloexec=no])])
+
+if test "$shib_cv_sock_cloexec" = "yes"; then
+	AC_DEFINE([HAVE_SOCK_CLOEXEC], 1, [Define if the SOCK_CLOEXEC flag is supported])
+fi
 
 # checks for pthreads
 ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])

Modified: branches/REL_2/shibsp/remoting/impl/TCPListener.cpp
URL: http://svn.shibboleth.net/view/cpp-sp/branches/REL_2/shibsp/remoting/impl/TCPListener.cpp?rev=3858&r1=3857&r2=3858&view=diff
==============================================================================
--- branches/REL_2/shibsp/remoting/impl/TCPListener.cpp (original)
+++ branches/REL_2/shibsp/remoting/impl/TCPListener.cpp Wed May 29 15:08:47 2013
@@ -53,6 +53,7 @@
 #include <sys/stat.h>		/* for chmod() */
 #include <stdio.h>
 #include <stdlib.h>
+#include <fcntl.h>
 #include <errno.h>
 
 using namespace shibsp;
@@ -181,10 +182,15 @@
 
 bool TCPListener::create(ShibSocket& s) const
 {
+    int type = SOCK_STREAM;
+#ifdef HAVE_SOCK_CLOEXEC
+    type |= SOCK_CLOEXEC;
+#endif
+
 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
-    s = socket(m_sockaddr.ss_family, SOCK_STREAM, 0);
-#else
-    s = socket(m_sockaddr.sin_family, SOCK_STREAM, 0);
+    s = socket(m_sockaddr.ss_family, type, 0);
+#else
+    s = socket(m_sockaddr.sin_family, type, 0);
 #endif
 #ifdef WIN32
     if(s == INVALID_SOCKET)
@@ -192,6 +198,15 @@
     if (s < 0)
 #endif
         return log_error("socket");
+
+#if !defined(HAVE_SOCK_CLOEXEC) && defined(HAVE_FD_CLOEXEC)
+    int fdflags = fcntl(s, F_GETFD);
+    if (fdflags != -1) {
+        fdflags |= FD_CLOEXEC;
+        fcntl(s, F_SETFD, fdflags);
+    }
+#endif
+
     return true;
 }
 

Modified: branches/REL_2/shibsp/remoting/impl/UnixListener.cpp
URL: http://svn.shibboleth.net/view/cpp-sp/branches/REL_2/shibsp/remoting/impl/UnixListener.cpp?rev=3858&r1=3857&r2=3858&view=diff
==============================================================================
--- branches/REL_2/shibsp/remoting/impl/UnixListener.cpp (original)
+++ branches/REL_2/shibsp/remoting/impl/UnixListener.cpp Wed May 29 15:08:47 2013
@@ -44,6 +44,7 @@
 #include <sys/stat.h>		/* for chmod() */
 #include <stdio.h>
 #include <stdlib.h>
+#include <fcntl.h>
 #include <errno.h>
 
 using namespace shibsp;
@@ -98,11 +99,24 @@
 #define UNIX_PATH_MAX 100
 #endif
 
-bool UnixListener::create(ShibSocket& sock) const
+bool UnixListener::create(ShibSocket& s) const
 {
-    sock = socket(PF_UNIX, SOCK_STREAM, 0);
-    if (sock < 0)
+    int type = SOCK_STREAM;
+#ifdef HAVE_SOCK_CLOEXEC
+    type |= SOCK_CLOEXEC;
+#endif
+    s = socket(PF_UNIX, type, 0);
+    if (s < 0)
         return log_error("socket");
+
+#if !defined(HAVE_SOCK_CLOEXEC) && defined(HAVE_FD_CLOEXEC)
+    int fdflags = fcntl(s, F_GETFD);
+    if (fdflags != -1) {
+        fdflags |= FD_CLOEXEC;
+        fcntl(s, F_SETFD, fdflags);
+    }
+#endif
+
     return true;
 }
 



More information about the commits mailing list