X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-sp.git;a=blobdiff_plain;f=shibsp%2Fremoting%2Fimpl%2FTCPListener.cpp;h=4d1452ad5d0afa0325a4f99e4b00dead27f20d4b;hp=02df8e4a7fd009c13783979b3bd794dfe3fdf530;hb=c93bace8a29010e8c825ba028084c48743dad574;hpb=4b33e4e91aa504fc2bf68398d22a96f47d81e48f diff --git a/shibsp/remoting/impl/TCPListener.cpp b/shibsp/remoting/impl/TCPListener.cpp index 02df8e4..4d1452a 100644 --- a/shibsp/remoting/impl/TCPListener.cpp +++ b/shibsp/remoting/impl/TCPListener.cpp @@ -53,6 +53,7 @@ #include /* for chmod() */ #include #include +#include #include using namespace shibsp; @@ -181,10 +182,15 @@ bool TCPListener::setup_tcp_sockaddr() 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) @@ -192,6 +198,15 @@ bool TCPListener::create(ShibSocket& s) const 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; }