about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2000-08-08 14:57:02 +0000
committerClint Adams <clint@users.sourceforge.net>2000-08-08 14:57:02 +0000
commitcb89544d32619822541153118b0bc9c936573c64 (patch)
treedbab588ad5cff4f9e801a9b9804e0dfc12a2bac5
parent3bca186819e7e1e0fc6321592ccc62d75e0525be (diff)
downloadzsh-cb89544d32619822541153118b0bc9c936573c64.tar.gz
zsh-cb89544d32619822541153118b0bc9c936573c64.tar.xz
zsh-cb89544d32619822541153118b0bc9c936573c64.zip
12568: check sysconf(_SC_OPEN_MAX) if available instead of OPEN_MAX/NOFILES.
-rw-r--r--ChangeLog6
-rw-r--r--Src/compat.c21
-rw-r--r--Src/exec.c5
-rw-r--r--Src/init.c2
-rw-r--r--Src/system.h3
-rw-r--r--configure.in2
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  <schizo@debian.org>
+
+	* 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  <wischnow@zsh.org>
 
 	* 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 <fcntl.h>
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