diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-02-11 12:46:41 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-02-11 13:00:42 -0800 |
commit | 59ee902e952c58d989de64e6ab0511e5a2dc3c0d (patch) | |
tree | f786c4598ca9e9254bce7248de66e938466b0438 | |
parent | c85c1f5480ac8f7c0d43a4b0f353e6f6828901af (diff) |
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | fd.c | 13 |
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. @@ -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 */ |