summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2024-02-11 12:46:41 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-02-11 13:00:42 -0800
commit59ee902e952c58d989de64e6ab0511e5a2dc3c0d (patch)
treef786c4598ca9e9254bce7248de66e938466b0438
parentc85c1f5480ac8f7c0d43a4b0f353e6f6828901af (diff)
Use closefrom() if availableHEADmaster
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac2
-rw-r--r--fd.c13
2 files changed, 9 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index ae9d2a7..0e11c77 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,7 +72,7 @@ fi
# Checks for pkg-config packages
PKG_CHECK_MODULES(XSCOPE, [xproto >= 7.0.17 $XTRANS_PKG])
-AC_CHECK_FUNCS([getdtablesize getpeerucred])
+AC_CHECK_FUNCS([closefrom getdtablesize getpeerucred])
AC_CHECK_HEADERS([sys/filio.h langinfo.h])
dnl Allow checking code with lint, sparse, etc.
diff --git a/fd.c b/fd.c
index 8fdae9b..aee9b98 100644
--- a/fd.c
+++ b/fd.c
@@ -113,13 +113,16 @@ InitializeFD(void)
panic("Can't allocate memory for file descriptor info table");
}
- /* be sure all fd's are closed and marked not busy */
- for (i = 0; i < MaxFD; i++) {
- /* 0, 1, 2 are special (stdin, stdout, stderr) */
- if (i > 2)
- close(i);
+ /* be sure all fd's other than 0, 1, 2 are closed and marked not busy */
+ /* 0, 1, 2 are special (stdin, stdout, stderr) */
+#ifdef HAVE_CLOSEFROM
+ closefrom(3);
+#else
+ for (i = 3; i < MaxFD; i++) {
+ close(i);
/* FDD[i].Busy = false; - not needed since false==0 */
}
+#endif
/* save one FD for single file input or output like debugging */
/* also the getservbyname call is currently using an FD */