From 8a5fe8ce6bb6c2bd81f237a0f4a2583722ffbd1c Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Fri, 20 Dec 2024 21:51:24 +0000 Subject: [PATCH] Extend the code to effciently close unwanted file descriptors to *BSD. --- src/util.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/util.c b/src/util.c index 89ee968..933340c 100644 --- a/src/util.c +++ b/src/util.c @@ -810,11 +810,25 @@ void close_fds(long max_fd, int spare1, int spare2, int spare3) { /* On Linux, use the /proc/ filesystem to find which files are actually open, rather than iterate over the whole space, - for efficiency reasons. If this fails we drop back to the dumb code. */ -#ifdef HAVE_LINUX_NETWORK + for efficiency reasons. + + On *BSD, the same facility is found at /dev/fd. + + If this fails we drop back to the dumb code. + */ + +#ifdef HAVE_LINUX_NETWORK +#define FDESCFS "/proc/self/fd" +#endif + +#ifdef HAVE_BSD_NETWORK +#define FDESCFS "/dev/fd" +#endif + +#ifdef FDESCFS DIR *d; - if ((d = opendir("/proc/self/fd"))) + if ((d = opendir(FDESCFS))) { struct dirent *de;