summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2023-05-08 01:01:26 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2023-05-08 01:01:26 -0400
commit61dc9affb72f12a309e5ebb851da5724ac4c561a (patch)
tree7ae913fcf957f094177b81b135c63217b6afa951
parent9f0b30b5cafbeb8409a1ebc285b3de3142d5df88 (diff)
downloadlighttpd-git-61dc9affb72f12a309e5ebb851da5724ac4c561a.tar.gz
[core] posix_spawn_file_actions_addclosefrom_np()
use posix_spawn_file_actions_addclosefrom_np() where available
-rw-r--r--SConstruct1
-rw-r--r--configure.ac1
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/config.h.cmake1
-rw-r--r--src/fdevent.c12
-rw-r--r--src/meson.build1
6 files changed, 17 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct
index a611c44c..fc171f28 100644
--- a/SConstruct
+++ b/SConstruct
@@ -432,6 +432,7 @@ if 1:
'pipe2',
'poll',
'posix_spawn',
+ 'posix_spawn_file_actions_addclosefrom_np',
'posix_spawn_file_actions_addfchdir_np',
'pread',
'preadv',
diff --git a/configure.ac b/configure.ac
index 331f95d2..52fb4eab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1462,6 +1462,7 @@ AC_CHECK_FUNCS([\
pipe2 \
poll \
posix_spawn \
+ posix_spawn_file_actions_addclosefrom_np \
posix_spawn_file_actions_addfchdir_np \
pread \
pwrite \
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ea7ba2f9..92642d08 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -212,6 +212,7 @@ endif()
check_include_files(spawn.h HAVE_SPAWN_H)
if(HAVE_SPAWN_H)
check_function_exists(posix_spawn HAVE_POSIX_SPAWN)
+check_function_exists(posix_spawn_file_actions_addclosefrom_np HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP)
check_function_exists(posix_spawn_file_actions_addfchdir_np HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR_NP)
endif()
diff --git a/src/config.h.cmake b/src/config.h.cmake
index 99dfd954..1482fdc0 100644
--- a/src/config.h.cmake
+++ b/src/config.h.cmake
@@ -179,6 +179,7 @@
#cmakedefine HAVE_PIPE2
#cmakedefine HAVE_POLL
#cmakedefine HAVE_POSIX_SPAWN
+#cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP
#cmakedefine HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR_NP
#cmakedefine HAVE_PORT_CREATE
#cmakedefine HAVE_PREAD
diff --git a/src/fdevent.c b/src/fdevent.c
index 1c704fd9..115dca5a 100644
--- a/src/fdevent.c
+++ b/src/fdevent.c
@@ -512,6 +512,18 @@ pid_t fdevent_fork_execve(const char *name, char *argv[], char *envp[], int fdin
&& 0 == (rc = sigaddset(&sigs, SIGUSR1))
&& 0 == (rc = posix_spawnattr_setsigdefault(&attr, &sigs))) {
+ /* optional: potentially improve performance when many fds open
+ * (might create new file descriptor table containing only 0,1,2
+ * instead of close() on all other fds with O_CLOEXEC flag set)
+ * optional: disable manually and externally via gdb or other
+ * debugger by setting trace_children to non-zero value */
+ static volatile sig_atomic_t trace_children;
+ if (!trace_children) {
+ #ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP
+ posix_spawn_file_actions_addclosefrom_np(&file_actions, 3);
+ #endif
+ }
+
#if !defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDFCHDIR_NP) \
&& !defined(HAVE_POSIX_SPAWNATTR_SETCWD_NP)
/* not thread-safe, but ok since lighttpd not (currently) threaded
diff --git a/src/meson.build b/src/meson.build
index 2d7e7169..ed7a3953 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -137,6 +137,7 @@ functions = {
'pipe2': 'unistd.h',
'poll': 'poll.h',
'posix_spawn': 'spawn.h',
+ 'posix_spawn_file_actions_addclosefrom_np': 'spawn.h',
'posix_spawn_file_actions_addfchdir_np': 'spawn.h',
'pread': 'unistd.h',
'preadv': 'sys/uio.h',