if (m_PidFile == NULL)
BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'"));
-#ifdef F_GETFL
- int flags;
- flags = fcntl(fileno(m_PidFile), F_GETFL, 0);
- if (flags < 0)
- BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
+#ifndef _WIN32
+ int flags;
+ flags = fcntl(fileno(m_PidFile), F_GETFD, 0);
+ if (flags < 0)
+ BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- if (fcntl(fileno(m_PidFile), F_SETFL, flags | FD_CLOEXEC) < 0)
- BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
-#endif /* FD_CLOEXEC */
+ if (fcntl(fileno(m_PidFile), F_SETFD, flags | FD_CLOEXEC) < 0)
+ BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
-#ifndef _WIN32
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
ClosePidFile();
m_TaskFd = fds[1];
int flags;
- flags = fcntl(fds[1], F_GETFL, 0);
+ flags = fcntl(fds[1], F_GETFD, 0);
if (flags < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- if (fcntl(fds[1], F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
+ if (fcntl(fds[1], F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
for (int i = 0; i < thread::hardware_concurrency(); i++) {
BOOST_THROW_EXCEPTION(PosixException("dup() failed.", errno));
int flags;
- flags = fcntl(childTaskFd, F_GETFL, 0);
+ flags = fcntl(childTaskFd, F_GETFD, 0);
if (flags < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- if (fcntl(childTaskFd, F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
+ if (fcntl(childTaskFd, F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
thread t(&Process::WorkerThreadProc, childTaskFd);
#ifndef HAVE_PIPE2
int flags;
- flags = fcntl(fds[0], F_GETFL, 0);
+ flags = fcntl(fds[0], F_GETFD, 0);
if (flags < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- if (fcntl(fds[0], F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
+ if (fcntl(fds[0], F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- flags = fcntl(fds[1], F_GETFL, 0);
+ flags = fcntl(fds[1], F_GETFD, 0);
if (flags < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- if (fcntl(fds[1], F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
+ if (fcntl(fds[1], F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
#endif /* HAVE_PIPE2 */
*/
void Socket::SetFD(SOCKET fd)
{
- /* mark the socket as non-blocking */
+ /* mark the socket as non-blocking and close-on-exec */
if (fd != INVALID_SOCKET) {
-#ifdef F_GETFL
+#ifndef _WIN32
int flags;
- flags = fcntl(fd, F_GETFL, 0);
+ flags = fcntl(fd, F_GETFD, 0);
if (flags < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
- if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0)
+ if (fcntl(fd, F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
-#else /* F_GETFL */
+#else /* _WIN32 */
unsigned long lTrue = 1;
ioctlsocket(fd, FIONBIO, &lTrue);
-#endif /* F_GETFL */
+#endif /* _WIN32 */
}
m_FD = fd;