]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #3380: Mac OSX compile errors with CMSG_SPACE
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Mon, 4 Jun 2012 10:52:56 +0000 (04:52 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 4 Jun 2012 10:52:56 +0000 (04:52 -0600)
compat/Makefile.am
compat/cmsg.h [new file with mode: 0644]
compat/os/macosx.h
configure.ac
src/ipc/TypedMsgHdr.h

index a483647cbc0e7147369c894847101d492d4cb85b..d69d5dbb91519800b770ab88f1eaaf2516a5e304 100644 (file)
@@ -13,6 +13,7 @@ noinst_LIBRARIES = libcompat-squid.a
 libcompat_squid_a_SOURCES = \
        assert.cc \
        assert.h \
+       cmsg.h \
        compat.cc \
        compat.h \
        compat_shared.h \
diff --git a/compat/cmsg.h b/compat/cmsg.h
new file mode 100644 (file)
index 0000000..a433f77
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef SQUID_COMPAT_CMSG_H
+#define SQUID_COMPAT_CMSG_H
+
+// CMSG_SPACE is not constant on some systems (in particular Max OS X),
+// provide a replacement that can be used at build time in that case
+
+#if HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#if HAVE_CONSTANT_CMSG_SPACE
+#define SQUID_CMSG_SPACE CMSG_SPACE
+#else
+// add 16 bytes for header and data alignment
+#define SQUID_CMSG_SPACE(len) (sizeof(struct cmsghdr) + (len) + 16)
+#endif
+
+#endif /* SQUID_COMPAT_CMSG_H */
index e601614f112e06dc19b145cbdac7fb9364540669..4baf2dc84877e6798a160feea16c660b61b1c53c 100644 (file)
@@ -18,5 +18,7 @@
 //#define s6_addr16 __u6_addr.__u6_addr16
 #define s6_addr32 __u6_addr.__u6_addr32
 
+#include "compat/cmsg.h"
+
 #endif /* _SQUID_APPLE_ */
 #endif /* SQUID_OS_MACOSX_H */
index 8ad7d2a1869ac6d0e6d92dc79ae51ba87fc20e55..b5f81f8e596690b347fd2c17f9ee9e4f1533d5e9 100644 (file)
@@ -3246,6 +3246,20 @@ if test "x$squid_cv_resuid_works" = "xyes" ; then
   AC_DEFINE(HAVE_SETRESUID,1,[Yay! Another Linux brokenness. Knowing that setresuid() exists is not enough, because RedHat 5.0 declares setresuid() but does not implement it.])
 fi
 
+AC_MSG_CHECKING([for constant CMSG_SPACE])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+  #if HAVE_SYS_SOCKET_H
+  #include <sys/socket.h>
+  #endif
+
+  int a[CMSG_SPACE(int)];
+]])], [
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(HAVE_CONSTANT_CMSG_SPACE, 1, [Define to 1 if CMSG_SPACE is constant])
+], [
+  AC_MSG_RESULT(no)
+])
+
 SQUID_CHECK_FUNC_STRNSTR
 SQUID_CHECK_FUNC_VACOPY
 SQUID_CHECK_FUNC___VACOPY
index 95afe00dd67201606bae090f2e26e68ac79c77fb..a3ca266171fa50926511896e9af479aa92140f6e 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef SQUID_IPC_TYPED_MSG_HDR_H
 #define SQUID_IPC_TYPED_MSG_HDR_H
 
+#include "compat/cmsg.h"
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
@@ -90,7 +91,8 @@ private:
     } data; ///< same as .msg_iov[0].iov_base
 
     struct CtrlBuffer {
-        char raw[CMSG_SPACE(sizeof(int))]; ///< control buffer space for one fd
+        /// control buffer space for one fd
+        char raw[SQUID_CMSG_SPACE(sizeof(int))];
     } ctrl; ///< same as .msg_control
 
     /// data offset for the next get/put*() to start with