A bit reworked but originally from Igor Pashev:
https://github.com/ip1981/libqb/commit/84c47f8160a9a78f068cc5b0d40b3901c0...
Note: __EXTENSIONS__ also defines _GNU_SOURCE, so removing it as well.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
configure.ac | 10 ++++++++++
include/os_base.h | 4 ----
lib/ipc_us.c | 15 ++++++++++-----
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/configure.ac b/configure.ac
index fda5ea4..6e3e8dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8,6 +8,8 @@ AC_INIT([libqb],
[quarterback-devel(a)fedorahosted.org])
AC_CONFIG_SRCDIR([lib/ringbuffer.c])
AC_CONFIG_HEADERS([include/config.h include/qb/qbconfig.h])
+AC_USE_SYSTEM_EXTENSIONS
+
AM_INIT_AUTOMAKE([-Wno-portability dist-xz color-tests parallel-tests])
dnl automake >= 1.11 offers --enable-silent-rules for suppressing the output from
dnl normal compilation. When a failure occurs, it will then display the full
@@ -18,6 +20,7 @@ LT_PREREQ([2.2.6])
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
+
AC_CANONICAL_HOST
AC_PROG_LIBTOOL
AC_LANG([C])
@@ -136,6 +139,13 @@ AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
+AC_CHECK_MEMBER([struct sockaddr_un.sun_len],
+ [AC_DEFINE([HAVE_STRUCT_SOCKADDR_UN_SUN_LEN],
+ 1,
+ [Define to 1 if struct sockaddr_un has a member sun_len])],
+ [],
+ [#include <sys/un.h>])
+
# Checks for library functions.
AC_FUNC_CHOWN
AC_FUNC_FORK
diff --git a/include/os_base.h b/include/os_base.h
index 4dd0555..63ac8d6 100644
--- a/include/os_base.h
+++ b/include/os_base.h
@@ -25,10 +25,6 @@
#include <config.h>
#endif /* HAVE_CONFIG_H */
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif /* _GNU_SOURCE */
-
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index 06aa086..82b5f43 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -48,10 +48,15 @@
#define UNIX_PATH_MAX 108
#endif /* UNIX_PATH_MAX */
-#if defined(QB_LINUX) || defined(QB_SOLARIS)
-#define QB_SUN_LEN(a) sizeof(*(a))
+/*
+ * SUN_LEN() does a strlen() on sun_path, but if you are trying to use the
+ * "Linux abstract namespace" (you have to set sun_path[0] == '\0')
then
+ * the strlen() doesn't work.
+ */
+#if defined(SUN_LEN)
+#define QB_SUN_LEN(a) ((a)->sun_path[0] == '\0') ? sizeof(*(a)) : SUN_LEN(a)
#else
-#define QB_SUN_LEN(a) SUN_LEN(a)
+#define QB_SUN_LEN(a) sizeof(*(a))
#endif
struct ipc_us_control {
@@ -341,8 +346,8 @@ qb_ipcc_us_sock_connect(const char *socket_name, int32_t * sock_pt)
memset(&address, 0, sizeof(struct sockaddr_un));
address.sun_family = AF_UNIX;
-#if defined(QB_BSD) || defined(QB_DARWIN)
- address.sun_len = SUN_LEN(&address);
+#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
+ address.sun_len = QB_SUN_LEN(&address);
#endif
#if defined(QB_LINUX)
--
1.7.10.1