about summary refs log tree commit diff
path: root/Src
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 /Src
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.
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>