From 12c9336374953999d491098df4ee2bb6fec26fde Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 26 Jul 2018 20:23:42 +0100 Subject: [PATCH] Close the fds after log initialisation. --- P25Gateway/P25Gateway.cpp | 12 ++++++++---- P25Reflector/P25Reflector.cpp | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/P25Gateway/P25Gateway.cpp b/P25Gateway/P25Gateway.cpp index 9ef0e92..8f09b00 100644 --- a/P25Gateway/P25Gateway.cpp +++ b/P25Gateway/P25Gateway.cpp @@ -119,10 +119,6 @@ void CP25Gateway::run() return; } - ::close(STDIN_FILENO); - ::close(STDOUT_FILENO); - ::close(STDERR_FILENO); - // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); @@ -160,6 +156,14 @@ void CP25Gateway::run() return; } +#if !defined(_WIN32) && !defined(_WIN64) + if (m_daemon) { + ::close(STDIN_FILENO); + ::close(STDOUT_FILENO); + ::close(STDERR_FILENO); + } +#endif + in_addr rptAddr = CUDPSocket::lookup(m_conf.getRptAddress()); unsigned int rptPort = m_conf.getRptPort(); diff --git a/P25Reflector/P25Reflector.cpp b/P25Reflector/P25Reflector.cpp index 0febc31..721b25c 100644 --- a/P25Reflector/P25Reflector.cpp +++ b/P25Reflector/P25Reflector.cpp @@ -119,10 +119,6 @@ void CP25Reflector::run() return; } - ::close(STDIN_FILENO); - ::close(STDOUT_FILENO); - ::close(STDERR_FILENO); - // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); @@ -160,6 +156,14 @@ void CP25Reflector::run() return; } +#if !defined(_WIN32) && !defined(_WIN64) + if (m_daemon) { + ::close(STDIN_FILENO); + ::close(STDOUT_FILENO); + ::close(STDERR_FILENO); + } +#endif + CNetwork network(m_conf.getNetworkPort(), m_conf.getNetworkDebug()); ret = network.open();