summaryrefslogtreecommitdiffstats
path: root/spawn
diff options
context:
space:
mode:
authorDim-P <Dim-P@users.noreply.github.com>2023-01-19 12:01:02 +0000
committerGitHub <noreply@github.com>2023-01-19 12:01:02 +0000
commit8ee7e8b26162c1c29e46c8894903b57d7bbd687f (patch)
treedaee30f6f2496446bd06539a317aba52a1de8568 /spawn
parentc1908d3163185cf65a139edeb11a165a10eca1e9 (diff)
Improve file descriptor closing loops (#14213)
* Add for_each_open_fd() and fix second instance of _SC_OPEN_MAX * Add argument to allow exclusion of file descriptors from closing * Fix clang error * Address review comments * Use close_range() if possible and replace macros with enums
Diffstat (limited to 'spawn')
-rw-r--r--spawn/spawn_server.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/spawn/spawn_server.c b/spawn/spawn_server.c
index 53b143deac..1d79ef15d4 100644
--- a/spawn/spawn_server.c
+++ b/spawn/spawn_server.c
@@ -317,10 +317,7 @@ void spawn_server(void)
// close all open file descriptors, except the standard ones
// the caller may have left open files (lxc-attach has this issue)
- int fd;
- for(fd = (int)(sysconf(_SC_OPEN_MAX) - 1) ; fd > 2 ; --fd)
- if(fd_is_valid(fd))
- close(fd);
+ for_each_open_fd(OPEN_FD_ACTION_CLOSE, OPEN_FD_EXCLUDE_STDIN | OPEN_FD_EXCLUDE_STDOUT | OPEN_FD_EXCLUDE_STDERR);
// Have the libuv IPC pipe be closed when forking child processes
(void) fcntl(0, F_SETFD, FD_CLOEXEC);