Commit c43a6be9 authored by Bart Schaefer's avatar Bart Schaefer

16094: zopenmax() need only return the highest-numbered open descriptor

parent d98a67c5
...@@ -198,12 +198,32 @@ zpathmax(char *dir) ...@@ -198,12 +198,32 @@ zpathmax(char *dir)
mod_export long mod_export long
zopenmax(void) zopenmax(void)
{ {
long openmax = sysconf(_SC_OPEN_MAX); static long openmax = 0;
if (openmax < 1) {
if ((openmax = sysconf(_SC_OPEN_MAX)) < 1) {
openmax = OPEN_MAX;
} else if (openmax > OPEN_MAX) {
/* On some systems, "limit descriptors unlimited" or the *
* equivalent will set openmax to a huge number. Unless *
* there actually is a file descriptor > OPEN_MAX already *
* open, nothing in zsh requires the true maximum, and in *
* fact it causes inefficiency elsewhere if we report it. *
* So, report the maximum of OPEN_MAX or the largest open *
* descriptor (is there a better way to find that?). */
long i, j = OPEN_MAX;
for (i = j; i < openmax; i += (errno != EINTR)) {
errno = 0;
if (fcntl(i, F_GETFL, 0) < 0 &&
(errno == EBADF || errno == EINTR))
continue;
j = i;
}
openmax = j;
}
}
if (openmax < 1) return (max_zsh_fd > openmax) ? max_zsh_fd : openmax;
return OPEN_MAX;
else
return openmax;
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment