From 093cd6a6a3e2431f950d2b4953f36fe7c75cfd01 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Fri, 5 Nov 2021 13:30:12 +0000 Subject: [PATCH] Fix FD_CLOEXEC setting --- mongoose.c | 3 ++- src/sock.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index e91bb021..6804a8a3 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2976,7 +2976,8 @@ static void mg_set_non_blocking_mode(SOCKET fd) { #elif MG_ARCH == MG_ARCH_AZURERTOS fcntl(fd, F_SETFL, O_NONBLOCK); #else - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK | FD_CLOEXEC); + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); // Set non-blocking mode + fcntl(fd, F_SETFD, FD_CLOEXEC); // Set close-on-exec #endif } diff --git a/src/sock.c b/src/sock.c index 4962caa9..6725a075 100644 --- a/src/sock.c +++ b/src/sock.c @@ -134,7 +134,8 @@ static void mg_set_non_blocking_mode(SOCKET fd) { #elif MG_ARCH == MG_ARCH_AZURERTOS fcntl(fd, F_SETFL, O_NONBLOCK); #else - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK | FD_CLOEXEC); + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); // Set non-blocking mode + fcntl(fd, F_SETFD, FD_CLOEXEC); // Set close-on-exec #endif }