documentation for the software which includes the set or a subset
of the icons contained within.
+==============================================================================
+
+shm_portable_segment_name_is_path() implementation:
+
+ Derived from boost/interprocess/shared_memory_object.hpp and
+ boost/interprocess/detail/workaround.hpp at http://www.boost.org/
+
+ (C) Copyright Ion Gaztanaga 2005-2009.
+ Distributed under the Boost Software License, Version 1.0
+
+ Boost Software License - Version 1.0 - August 17th, 2003
+
+ Permission is hereby granted, free of charge, to any person or organization
+ obtaining a copy of the software and accompanying documentation covered by
+ this license (the "Software") to use, reproduce, display, distribute,
+ execute, and transmit the Software, and to prepare derivative works of the
+ Software, and to permit third-parties to whom the Software is furnished to
+ do so, all subject to the following:
+
+ The copyright notices in the Software and this entire statement, including
+ the above license grant, this restriction and the following disclaimer,
+ must be included in all copies of the Software, in whole or in part, and
+ all derivative works of the Software, unless such copies or derivative
+ works are solely in the form of machine-executable object code generated by
+ a source language processor.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
--- /dev/null
+#include "config.h"
+#include "compat/shm.h"
+
+#if defined(__FreeBSD__) && (__FreeBSD__ >= 7)
+# include <sys/sysctl.h>
+#endif
+
+
+/*
+ * Some systems have filesystem-based resources and interpret segment names
+ * as file paths. The so-called 'portable' "/name" format does not work well
+ * for them. And, according to Boost::interprocess, recent FreeBSD versions
+ * make this decision depending on whether the shm_open() caller is jailed!
+ */
+bool
+shm_portable_segment_name_is_path()
+{
+#if defined(_SQUID_HPUX_) || defined(_SQUID_OSF_) || defined(__vms) || (defined(_SQUID_FREEBSD_) && (__FreeBSD__ < 7))
+ return true;
+#elif defined(_SQUID_FREEBSD_)
+ int jailed = 0;
+ size_t len = sizeof(jailed);
+ ::sysctlbyname("security.jail.jailed", &jailed, &len, NULL, 0);
+ return !jailed;
+#else
+ return false;
+#endif
+}
#include <sys/stat.h>
#include <unistd.h>
+
+// test cases change this
+const char *Ipc::Mem::Segment::BasePath = DEFAULT_STATEDIR;
+
void *
Ipc::Mem::Segment::reserve(size_t chunkSize)
{
return s.st_size;
}
-/// Generate name for shared memory segment. Replaces all slashes with dots.
+/// Generate name for shared memory segment. Starts with a prefix required
+/// for cross-platform portability and replaces all slashes in ID with dots.
String
Ipc::Mem::Segment::GenerateName(const char *id)
{
- String name("/squid-");
+ assert(BasePath);
+ static const bool nameIsPath = shm_portable_segment_name_is_path();
+ String name(nameIsPath ? BasePath : "/squid-");
+
+ // append id, replacing slashes with dots
for (const char *slash = strchr(id, '/'); slash; slash = strchr(id, '/')) {
if (id != slash) {
name.append(id, slash - id);
id = slash + 1;
}
name.append(id);
+
+ name.append(".shm"); // to distinguish from non-segments when nameIsPath
return name;
}