Skip to content

Commit cf377c0

Browse files
committed
close inherited file descriptors if closefrom() is available
1 parent 2dd3ad7 commit cf377c0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ if(CMAKE_USE_PTHREADS_INIT)
6161
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
6262
endif()
6363

64+
include(CheckFunctionExists)
65+
check_function_exists(closefrom HAVE_CLOSEFROM)
66+
if(HAVE_CLOSEFROM)
67+
add_definitions(-DHAVE_CLOSEFROM)
68+
endif()
69+
6470
add_definitions(-DASIO_STANDALONE)
6571
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/src/submodules/asio/.git")
6672
execute_process(COMMAND git submodule update --init -- src/submodules/asio

src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424
#include <thread>
2525
#include <exception>
2626
#include <memory>
27+
#include <unistd.h>
2728

2829
int main(int argc, char* argv[])
2930
{
31+
#ifdef HAVE_CLOSEFROM
32+
//close any inherrited file descriptors
33+
closefrom(3);
34+
#endif
3035
try
3136
{
3237
CmdArgs Args(argc,argv);

0 commit comments

Comments
 (0)