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"])
#include <sys/stat.h> /* for chmod() */
#include <stdio.h>
#include <stdlib.h>
+#include <fcntl.h>
#include <errno.h>
using namespace shibsp;
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);
+ s = socket(m_sockaddr.ss_family, type, 0);
#else
- s = socket(m_sockaddr.sin_family, SOCK_STREAM, 0);
+ s = socket(m_sockaddr.sin_family, type, 0);
#endif
#ifdef WIN32
if(s == INVALID_SOCKET)
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;
}
#include <sys/stat.h> /* for chmod() */
#include <stdio.h>
#include <stdlib.h>
+#include <fcntl.h>
#include <errno.h>
using namespace shibsp;
#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;
}