From cb89544d32619822541153118b0bc9c936573c64 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Tue, 8 Aug 2000 14:57:02 +0000 Subject: 12568: check sysconf(_SC_OPEN_MAX) if available instead of OPEN_MAX/NOFILES. --- ChangeLog | 6 ++++++ Src/compat.c | 21 +++++++++++++++++++++ Src/exec.c | 5 ++++- Src/init.c | 2 +- Src/system.h | 3 +++ configure.in | 2 +- 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c205c1cc3..5486e41cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-08-08 Clint Adams + + * 12568: configure.in, Src/compat.c, Src/exec.c, Src/init.c, + Src/system.h: check sysconf(_SC_OPEN_MAX) if available instead + of OPEN_MAX/NOFILES. + 2000-08-08 Sven Wischnowsky * 12567: Completion/Linux/_rpm, Src/Zle/computil.c: handle the diff --git a/Src/compat.c b/Src/compat.c index e9c275df4..88ceac2c8 100644 --- a/Src/compat.c +++ b/Src/compat.c @@ -171,6 +171,27 @@ zpathmax(char *dir) } #endif +#ifdef HAVE_SYSCONF +/* This is replaced by a macro from system.h if not HAVE_PATHCONF. * + * 0 is returned if _SC_OPEN_MAX is unavailable * + * -1 is returned on error * + * * + * Neither of these should happen, but resort to OPEN_MAX rather * + * than return 0 or -1 just in case. */ + +/**/ +mod_export long +zopenmax(void) +{ + long openmax; + + openmax = sysconf(_SC_OPEN_MAX); + if(openmax < 1) + return OPEN_MAX; + else + return openmax; +} +#endif /**/ mod_export char * diff --git a/Src/exec.c b/Src/exec.c index cec096d25..698591475 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1404,8 +1404,11 @@ static void closeallelse(struct multio *mn) { int i, j; + long openmax; - for (i = 0; i < OPEN_MAX; i++) + openmax = zopenmax(); + + for (i = 0; i < openmax; i++) if (mn->pipe != i) { for (j = 0; j < mn->ct; j++) if (mn->fds[j] == i) diff --git a/Src/init.c b/Src/init.c index 131cc855c..e3e8f734e 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1173,7 +1173,7 @@ zsh_main(int argc, char **argv) break; } while (zsh_name); - fdtable_size = OPEN_MAX; + fdtable_size = zopenmax(); fdtable = zcalloc(fdtable_size); createoptiontable(); diff --git a/Src/system.h b/Src/system.h index 1810c525f..2ed75b621 100644 --- a/Src/system.h +++ b/Src/system.h @@ -220,6 +220,9 @@ struct timezone { # define OPEN_MAX 64 # endif #endif +#ifndef HAVE_SYSCONF +# define zopenmax() (long) OPEN_MAX +#endif #ifdef HAVE_FCNTL_H # include diff --git a/configure.in b/configure.in index 6f813e0b0..dfe37e6e0 100644 --- a/configure.in +++ b/configure.in @@ -864,7 +864,7 @@ AC_CHECK_FUNCS(strftime difftime gettimeofday \ signgam \ putenv getenv \ brk sbrk \ - pathconf) + pathconf sysconf) AC_FUNC_STRCOLL if test $ac_cv_func_setpgrp = yes; then -- cgit 1.4.1