]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Refactored filedescriptors number detection.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 29 Jul 2010 19:44:13 +0000 (21:44 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 29 Jul 2010 19:44:13 +0000 (21:44 +0200)
acinclude/os-deps.m4
configure.in

index 8c5721764597639054341bf56b21970c23e8d7fa..c45496f0b191efd2787dc4435f7a36d5697496d5 100644 (file)
@@ -234,3 +234,94 @@ int main(int argc, char **argv) {
 AC_MSG_RESULT($DEFAULT_FD_SETSIZE)
 AC_DEFINE_UNQUOTED(DEFAULT_FD_SETSIZE, $DEFAULT_FD_SETSIZE, [Default FD_SETSIZE value])
 ])
+
+
+dnl checks the maximum number of filedescriptor we can open
+dnl sets shell var squid_filedescriptors_num
+
+AC_DEFUN([SQUID_CHECK_MAXFD],[
+AC_MSG_CHECKING(Maximum number of filedescriptors we can open)
+dnl damn! FreeBSD pthreads break dup2().
+SQUID_STATE_SAVE(maxfd)
+  case $host in
+  i386-unknown-freebsd*)
+      if echo "$LDFLAGS" | grep -q pthread; then
+       LDFLAGS=`echo $LDFLAGS | sed -e "s/-pthread//"`
+      fi
+  esac
+  AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/time.h>  /* needed on FreeBSD */
+#include <sys/param.h>
+#include <sys/resource.h>
+int main(int argc, char **argv) {
+       FILE *fp;
+       int i,j;
+#if defined(__CYGWIN32__) || defined (__CYGWIN__)
+    /* getrlimit and sysconf returns bogous values on cygwin32.
+     * Number of fds is virtually unlimited in cygwin (sys/param.h)
+     * __CYGWIN32__ is deprecated.
+     */
+    i = NOFILE;
+#else
+#if HAVE_SETRLIMIT
+    struct rlimit rl;
+#if defined(RLIMIT_NOFILE)
+    if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
+        perror("getrlimit: RLIMIT_NOFILE");
+    } else {
+#if defined(__APPLE__)
+        /* asking for more than OPEN_MAX fails on Leopard */
+        rl.rlim_cur = (OPEN_MAX < rl.rlim_max ? OPEN_MAX : rl.rlim_max);
+#else
+        rl.rlim_cur = rl.rlim_max;      /* set it to the max */
+#endif
+        if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
+            perror("setrlimit: RLIMIT_NOFILE");
+        }
+    }
+#elif defined(RLIMIT_OFILE)
+    if (getrlimit(RLIMIT_OFILE, &rl) < 0) {
+        perror("getrlimit: RLIMIT_OFILE");
+    } else {
+        rl.rlim_cur = rl.rlim_max;      /* set it to the max */
+        if (setrlimit(RLIMIT_OFILE, &rl) < 0) {
+            perror("setrlimit: RLIMIT_OFILE");
+        }
+    }
+#endif /* RLIMIT_NOFILE */
+#endif /* HAVE_SETRLIMIT */
+       /* by starting at 2^14, we will never get higher
+       than 2^15 for squid_filedescriptors_num */
+        i = j = 1<<14;
+        while (j) {
+                j >>= 1;
+                if (dup2(0, i) < 0) { 
+                        i -= j;
+                } else {
+                        close(i);
+                        i += j;
+                }
+        }
+        i++;
+#endif /* IF !DEF CYGWIN */
+       fp = fopen("conftestval", "w");
+       fprintf (fp, "%d\n", i & ~0x3F);
+       return 0;
+}
+  ]])],[squid_filedescriptors_num=`cat conftestval`],[squid_filedescriptors_num=256],[squid_filedescriptors_num=256])
+  dnl Microsoft MSVCRT.DLL supports 2048 maximum FDs
+  case "$host_os" in
+  mingw|mingw32)
+    squid_filedescriptors_num="2048"
+    ;;
+  esac
+  AC_MSG_RESULT($squid_filedescriptors_num)
+SQUID_STATE_ROLLBACK(maxfd)
+
+if test `expr $squid_filedescriptors_num % 64` != 0; then
+    AC_MSG_WARN([$squid_filedescriptors_num is not an multiple of 64. This may cause issues on certain platforms.])
+fi
+])
index cb11c065a0f282bd79aa11f508ce859acb232ffb..854fa481abfe911357cbb83849b81ab7ed4e6872 100644 (file)
@@ -2032,34 +2032,6 @@ SQUID_DEFINE_BOOL(USE_ZPH_QOS,${enable_zph_qos:=no},
            TOS field of HIT responses to help policing network traffic])
 AC_MSG_NOTICE([ZPH QOS enabled: $enable_zph_qos])
 
-dnl --with-maxfd present for compatibility with Squid-2.
-dnl undocumented in ./configure --help  to encourage using the Squid-3 directive
-AC_ARG_WITH(maxfd,,
-[ 
-  case ${withval} in
-    [[0-9]]*)
-      squid_filedescriptors_num=$withval
-      ;;
-    *)
-      AC_MSG_ERROR(--with-maxfd expects a numeric argument)
-      ;;
-    esac
-])
-
-AC_ARG_WITH(filedescriptors,
-  AS_HELP_STRING([--with-filedescriptors=NUMBER],
-                 [Force squid to support NUMBER filedescriptors]),
-[ 
-  case ${withval} in
-    [[0-9]]*)
-      squid_filedescriptors_num=$withval
-      ;;
-    *)
-      AC_MSG_ERROR(--with-filedescriptors expects a numeric argument)
-      ;;
-    esac
-])
-
 if $CPPUNITCONFIG --help >/dev/null; then
   squid_cv_cppunit_version="`$CPPUNITCONFIG --version`"
   AC_MSG_NOTICE([using system installed cppunit version $squid_cv_cppunit_version])
@@ -2474,6 +2446,50 @@ mingw|mingw32)
        ;;
 esac
 
+
+dnl --with-maxfd present for compatibility with Squid-2.
+dnl undocumented in ./configure --help  to encourage using the Squid-3 directive
+AC_ARG_WITH(maxfd,,
+[ 
+  case ${withval} in
+    [[0-9]]*)
+      squid_filedescriptors_num=$withval
+      ;;
+    *)
+      AC_MSG_ERROR(--with-maxfd expects a numeric argument)
+      ;;
+    esac
+])
+
+AC_ARG_WITH(filedescriptors,
+  AS_HELP_STRING([--with-filedescriptors=NUMBER],
+                 [Force squid to support NUMBER filedescriptors]),
+[ 
+  case ${withval} in
+    [[0-9]]*)
+      squid_filedescriptors_num=$withval
+      ;;
+    *)
+      AC_MSG_ERROR(--with-filedescriptors expects a numeric argument)
+      ;;
+    esac
+])
+
+SQUID_CHECK_DEFAULT_FD_SETSIZE
+if test "x$squid_filedescriptors_num" = "x"; then
+  SQUID_CHECK_MAXFD
+else
+  AC_MSG_NOTICE([forcing use of $squid_filedescriptors_num filedescriptors (user-forced)])
+fi
+if test "$squid_filedescriptors_num" -lt 512 ; then
+    AC_MSG_WARN([$squid_filedescriptors_num may not be enough filedescriptors if your])
+    AC_MSG_WARN([cache will be very busy.  Please see the FAQ page])
+    AC_MSG_WARN([http://wiki.squid-cache.org/SquidFaq/TroubleShooting])
+    AC_MSG_WARN([on how to increase your filedescriptor limit])
+fi
+AC_DEFINE_UNQUOTED(SQUID_MAXFD, $squid_filedescriptors_num,[Maximum number of open filedescriptors])
+
+
 dnl Enable IPv6 support
 AC_MSG_CHECKING([whether to enable IPv6])
 use_ipng=yes
@@ -3005,105 +3021,6 @@ fi
 SQUID_DEFINE_BOOL(USE_GNUREGEX,$enable_gnuregex,[Define if we should use GNU regex])
 AC_SUBST(REGEXLIB)
 
-SQUID_CHECK_DEFAULT_FD_SETSIZE
-
-dnl Not cached since people are likely to tune this
-AC_MSG_CHECKING(Maximum number of filedescriptors we can open)
-dnl damn! FreeBSD pthreads break dup2().
-TLDFLAGS="$LDFLAGS"
-if test -n "$squid_filedescriptors_num" ; then
-  SQUID_MAXFD=$squid_filedescriptors_num
-  AC_MSG_RESULT($SQUID_MAXFD (user-forced))
-else
-  case $host in
-  i386-unknown-freebsd*)
-      if echo "$LDFLAGS" | grep -q pthread; then
-       LDFLAGS=`echo $LDFLAGS | sed -e "s/-pthread//"`
-      fi
-  esac
-  AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/time.h>  /* needed on FreeBSD */
-#include <sys/param.h>
-#include <sys/resource.h>
-int main(int argc, char **argv) {
-       FILE *fp;
-       int i,j;
-#if defined(__CYGWIN32__) || defined (__CYGWIN__)
-    /* getrlimit and sysconf returns bogous values on cygwin32.
-     * Number of fds is virtually unlimited in cygwin (sys/param.h)
-     * __CYGWIN32__ is deprecated.
-     */
-    i = NOFILE;
-#else
-#if HAVE_SETRLIMIT
-    struct rlimit rl;
-#if defined(RLIMIT_NOFILE)
-    if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
-        perror("getrlimit: RLIMIT_NOFILE");
-    } else {
-#if defined(__APPLE__)
-        /* asking for more than OPEN_MAX fails on Leopard */
-        rl.rlim_cur = (OPEN_MAX < rl.rlim_max ? OPEN_MAX : rl.rlim_max);
-#else
-        rl.rlim_cur = rl.rlim_max;      /* set it to the max */
-#endif
-        if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
-            perror("setrlimit: RLIMIT_NOFILE");
-        }
-    }
-#elif defined(RLIMIT_OFILE)
-    if (getrlimit(RLIMIT_OFILE, &rl) < 0) {
-        perror("getrlimit: RLIMIT_OFILE");
-    } else {
-        rl.rlim_cur = rl.rlim_max;      /* set it to the max */
-        if (setrlimit(RLIMIT_OFILE, &rl) < 0) {
-            perror("setrlimit: RLIMIT_OFILE");
-        }
-    }
-#endif /* RLIMIT_NOFILE */
-#endif /* HAVE_SETRLIMIT */
-       /* by starting at 2^14, we will never get higher
-       than 2^15 for SQUID_MAXFD */
-        i = j = 1<<14;
-        while (j) {
-                j >>= 1;
-                if (dup2(0, i) < 0) { 
-                        i -= j;
-                } else {
-                        close(i);
-                        i += j;
-                }
-        }
-        i++;
-#endif /* IF !DEF CYGWIN */
-       fp = fopen("conftestval", "w");
-       fprintf (fp, "%d\n", i & ~0x3F);
-       return 0;
-}
-  ]])],[SQUID_MAXFD=`cat conftestval`],[SQUID_MAXFD=256],[SQUID_MAXFD=256])
-  dnl Microsoft MSVCRT.DLL supports 2048 maximum FDs
-  case "$host_os" in
-  mingw|mingw32)
-    SQUID_MAXFD="2048"
-    ;;
-  esac
-  AC_MSG_RESULT($SQUID_MAXFD)
-fi
-AC_DEFINE_UNQUOTED(SQUID_MAXFD, $SQUID_MAXFD,[Maximum number of open filedescriptors])
-if test "$SQUID_MAXFD" -lt 512 ; then
-    AC_MSG_WARN([$SQUID_MAXFD may not be enough filedescriptors if your])
-    AC_MSG_WARN([cache will be very busy.  Please see the FAQ page])
-    AC_MSG_WARN([http://wiki.squid-cache.org/SquidFaq/TroubleShooting])
-    AC_MSG_WARN([on how to increase your filedescriptor limit])
-fi
-LDFLAGS="$TLDFLAGS"
-
-if test `expr $SQUID_MAXFD % 64` != 0; then
-    AC_MSG_WARN([$SQUID_MAXFD is not an multiple of 64. This may cause issues on certain platforms.])
-fi
 
 dnl Not cached since people are likely to tune this
 AC_MSG_CHECKING(Default UDP send buffer size)