Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: sysconf() for open max



This should be less painful than the PATH_MAX stuff.  OPEN_MAX
here is 256, but sysconf(_SC_OPEN_MAX) is 1024.  Go figure.

I notice that other uses of sysconf() presumed its existence
if the appropriate _SC_* macro was defined.  I'm more comfortable
with the autoconf test, though I suppose it would be safer to
check for both (and _PC_PATH_MAX for pathconf).

Index: configure.in
===================================================================
RCS file: /cvsroot/zsh/zsh/configure.in,v
retrieving revision 1.19
diff -u -r1.19 configure.in
--- configure.in	2000/08/05 05:59:53	1.19
+++ configure.in	2000/08/08 14:24:00
@@ -864,7 +864,7 @@
 	       signgam \
 	       putenv getenv \
 	       brk sbrk \
-	       pathconf)
+	       pathconf sysconf)
 AC_FUNC_STRCOLL
 
 if test $ac_cv_func_setpgrp = yes; then
Index: Src/compat.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/compat.c,v
retrieving revision 1.5
diff -u -r1.5 compat.c
--- Src/compat.c	2000/08/05 06:52:15	1.5
+++ Src/compat.c	2000/08/08 14:24:01
@@ -171,6 +171,27 @@
 }
 #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 *
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.16
diff -u -r1.16 exec.c
--- Src/exec.c	2000/08/08 02:38:36	1.16
+++ Src/exec.c	2000/08/08 14:24:09
@@ -1404,8 +1404,11 @@
 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)
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.10
diff -u -r1.10 init.c
--- Src/init.c	2000/08/02 18:01:51	1.10
+++ Src/init.c	2000/08/08 14:24:12
@@ -1173,7 +1173,7 @@
 	  break;
     } while (zsh_name);
 
-    fdtable_size = OPEN_MAX;
+    fdtable_size = zopenmax();
     fdtable = zcalloc(fdtable_size);
 
     createoptiontable();
Index: Src/system.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/system.h,v
retrieving revision 1.4
diff -u -r1.4 system.h
--- Src/system.h	2000/08/05 09:51:26	1.4
+++ Src/system.h	2000/08/08 14:24:13
@@ -220,6 +220,9 @@
 #  define OPEN_MAX 64
 # endif
 #endif
+#ifndef HAVE_SYSCONF
+# define zopenmax() (long) OPEN_MAX
+#endif
 
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>



Messages sorted by: Reverse Date, Date, Thread, Author