]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Disable Rock store and shared memory cache if shared memory is not available.
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Sun, 28 Aug 2011 17:11:19 +0000 (21:11 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Sun, 28 Aug 2011 17:11:19 +0000 (21:11 +0400)
The patch adds support for building on systems without POSIX shared
memory (e.g. OpenBSD).  IpcIo DiskIO module and Rock store is not
enabled by default if shared memory support is not available.  If IpcIo
or Rock store is explicitly enabled, but no shared memory support is
available, fail with error during configure.  Fail with error at
runtime if shared memory cache is enabled but no shared memory support
is detected.

compat/Makefile.am
compat/shm.h [new file with mode: 0644]
configure.ac
src/MemStore.cc
src/ipc/mem/Segment.cc
src/ipc/mem/Segment.h

index cb60e695802f1dd4e1238778dfdd5b2156dc33e2..8667bb0c65852c165d2b84e71430119e6f8bb4e6 100644 (file)
@@ -32,6 +32,7 @@ libcompat_squid_a_SOURCES = \
        initgroups.h \
        osdetect.h \
        psignal.h \
+       shm.h \
        stdio.h \
        stdvarargs.h \
        strnstr.cc \
diff --git a/compat/shm.h b/compat/shm.h
new file mode 100644 (file)
index 0000000..d1b66bd
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ */
+#ifndef SQUID_COMPAT_SHM_H
+#define SQUID_COMPAT_SHM_H
+
+#if HAVE_SHM
+
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h> /* for mode constants */
+#endif
+
+#if HAVE_FCNTL_H
+#include <fcntl.h> /* for O_* constants */
+#endif
+
+#if HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+
+#else /* HAVE_SHM */
+
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+extern "C" {
+
+inline int
+shm_open(const char *, int, mode_t) {
+    errno = ENOTSUP;
+    return -1;
+}
+
+inline int
+shm_unlink(const char *) {
+    errno = ENOTSUP;
+    return -1;
+}
+
+} /* extern "C" */
+
+#endif /* HAVE_SHM */
+
+#endif /* SQUID_COMPAT_CPU_H */
index 2bc44b31cd4483a4500c0fb0c024f13df18e9d59..a21ab99686037fdb18803715b1a723b31470145b 100644 (file)
@@ -470,6 +470,11 @@ if test "x$with_dl" = "xyes"; then
   AC_MSG_NOTICE([With dl])
 fi
 
+AC_SEARCH_LIBS([shm_open], [rt])
+if test "x$ac_cv_search_shm_open" != "xno" ; then
+  AC_DEFINE(HAVE_SHM,1,[Support shared memory features])
+fi
+
 AC_MSG_CHECKING([for DiskIO modules to be enabled])
 squid_disk_module_candidates=""
 squid_opt_enable_diskio="auto"  #values: no, yes, "auto"(=yes+detect modules)
@@ -500,6 +505,10 @@ case $enableval in
 if test "x$squid_opt_enable_diskio" = "xauto"; then
     squid_opt_enable_diskio="yes"
     SQUID_LOOK_FOR_MODULES([$srcdir/src/DiskIO],[squid_disk_module_candidates])
+    if test "x$ac_cv_search_shm_open" = "xno" ; then
+        # disable IpcIo
+        squid_disk_module_candidates=`echo $squid_disk_module_candidates|sed 's/IpcIo//'`
+    fi
 fi
 
 AC_MSG_RESULT([${squid_disk_module_candidates:-none}])
@@ -675,6 +684,9 @@ for module in $squid_disk_module_candidates none; do
 
     IpcIo)
       AC_MSG_NOTICE([Enabling IpcIo DiskIO module])
+      if test "x$ac_cv_search_shm_open" = "xno" ; then
+        AC_MSG_ERROR([DiskIO IpcIo module requires shared memory support])
+      fi
       DISK_LIBS="$DISK_LIBS libIpcIo.a"
       DISK_MODULES="$DISK_MODULES IpcIo"
       DISK_LINKOBJS="$DISK_LINKOBJS DiskIO/IpcIo/IpcIoDiskIOModule.o"
@@ -738,6 +750,10 @@ if test "x$squid_opt_enable_storeio" = "xauto"; then
   SQUID_LOOK_FOR_MODULES([$srcdir/src/fs],[squid_storeio_module_candidates])
   # disable coss
   squid_storeio_module_candidates=`echo $squid_storeio_module_candidates|sed 's/coss//'`
+  if test "x$ac_cv_search_shm_open" = "xno" ; then
+    # disable rock
+    squid_storeio_module_candidates=`echo $squid_storeio_module_candidates|sed 's/rock//'`
+  fi
   AC_MSG_RESULT([$squid_storeio_module_candidates])
 fi
 
@@ -773,6 +789,9 @@ for fs in $squid_storeio_module_candidates none; do
          "x$squid_disk_module_candidates_Blocking" = "xyes"; then
          AC_MSG_ERROR([Storage module Rock requires IpcIo and Blocking DiskIO modules])
        fi
+       if test "x$ac_cv_search_shm_open" = "xno" ; then
+         AC_MSG_ERROR([Storage module Rock requires shared memory support])
+       fi
        STORE_TESTS="$STORE_TESTS tests/testRock$EXEEXT"
        ;;
     ufs)
@@ -2351,6 +2370,7 @@ AC_CHECK_HEADERS( \
   sys/param.h \
   sys/prctl.h \
   sys/md5.h \
+  sys/mman.h \
   sys/msg.h \
   sys/resource.h \
   sys/select.h \
@@ -2571,7 +2591,7 @@ AC_SEARCH_LIBS([bind],[socket])
 AC_SEARCH_LIBS([opcom_stack_trace],[opcom_stack])
 AC_SEARCH_LIBS([strlcpy], [bsd])
 AC_SEARCH_LIBS([yp_match], [nsl nss_nis nss_nisplus])
-AC_SEARCH_LIBS([shm_open], [rt])
+
 dnl Check for Winsock only on MinGW, on Cygwin we must use emulated BSD socket API
 if test "x$squid_host_os" = "xmingw" ; then
   SQUID_CHECK_WINSOCK_LIB
index e7621689d44aa93b65d4f09fc111790d48efc94c..c4109ea931af4417e7022f8018b0676777758560 100644 (file)
@@ -362,11 +362,15 @@ void MemStoreRr::run(const RunnerRegistry &)
     // decide whether to use a shared memory cache if the user did not specify
     if (!Config.memShared.configured()) {
         Config.memShared.configure(AtomicOperationsSupported &&
-            UsingSmp() && Config.memMaxSize > 0);
+            Ipc::Mem::Segment::Enabled() && UsingSmp() &&
+            Config.memMaxSize > 0);
     } else
     if (Config.memShared && !AtomicOperationsSupported) {
         // bail if the user wants shared memory cache but we cannot support it
         fatal("memory_cache_shared is on, but no support for atomic operations detected");
+    } else
+    if (Config.memShared && !Ipc::Mem::Segment::Enabled()) {
+        fatal("memory_cache_shared is on, but no support for shared memory detected");
     }
 
     if (!Config.memShared)
index 470c3b900256dc082dd50f262682cf41c0a7f88c..545a1586070d42f402e1a09c4d2ab4a2926e78bc 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "config.h"
 #include "base/TextException.h"
+#include "compat/shm.h"
 #include "ipc/mem/Segment.h"
 #include "protos.h"
 
@@ -32,6 +33,15 @@ Ipc::Mem::Segment::~Segment() {
         unlink();
 }
 
+bool
+Ipc::Mem::Segment::Enabled() {
+#if HAVE_SHM
+    return true;
+#else
+    return false;
+#endif
+}
+
 void
 Ipc::Mem::Segment::create(const off_t aSize)
 {
index b45a99fba71545bfb6880919e4a12a17c08271ab..792ab9f75dc88824af35991cdcc55aeef6bae472 100644 (file)
@@ -19,6 +19,9 @@ public:
     Segment(const char *const id);
     ~Segment();
 
+    /// Whether shared memory support is available
+    static bool Enabled();
+
     /// Create a new shared memory segment. Fails if a segment with
     /// the same name already exists. Unlinks the segment on destruction.
     void create(const off_t aSize);