From 10c6c566a9ca136abf916c172fe13a91ee6f4b7a Mon Sep 17 00:00:00 2001 From: Dmitry Kurochkin Date: Mon, 4 Jun 2012 04:52:56 -0600 Subject: [PATCH] Bug #3380: Mac OSX compile errors with CMSG_SPACE --- compat/Makefile.am | 1 + compat/cmsg.h | 18 ++++++++++++++++++ compat/os/macosx.h | 2 ++ configure.ac | 14 ++++++++++++++ src/ipc/TypedMsgHdr.h | 4 +++- 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 compat/cmsg.h diff --git a/compat/Makefile.am b/compat/Makefile.am index a483647cbc..d69d5dbb91 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -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 index 0000000000..a433f77f55 --- /dev/null +++ b/compat/cmsg.h @@ -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 +#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 */ diff --git a/compat/os/macosx.h b/compat/os/macosx.h index e601614f11..4baf2dc848 100644 --- a/compat/os/macosx.h +++ b/compat/os/macosx.h @@ -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 */ diff --git a/configure.ac b/configure.ac index 8ad7d2a186..b5f81f8e59 100644 --- a/configure.ac +++ b/configure.ac @@ -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 + #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 diff --git a/src/ipc/TypedMsgHdr.h b/src/ipc/TypedMsgHdr.h index 95afe00dd6..a3ca266171 100644 --- a/src/ipc/TypedMsgHdr.h +++ b/src/ipc/TypedMsgHdr.h @@ -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 #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 -- 2.47.2