about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/compat.c21
-rw-r--r--Src/exec.c5
-rw-r--r--Src/init.c2
-rw-r--r--Src/system.h3
4 files changed, 29 insertions, 2 deletions
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>