Backported to glibc 2.8
authorJesper Derehag <jderehag@hotmail.com>
Thu, 24 Apr 2014 08:22:50 +0000 (10:22 +0200)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 30 Apr 2014 16:50:13 +0000 (12:50 -0400)
This patch enables lttng-tools to run on top of glibc 2.8.
Overall it fixes 2 things:
1. No support for epoll_create1(..) and EPOLL_CLOEXEC.
2. No support for htobe/betoh

For 1, we revert back to epoll_create() and then sets CLOEXEC through
fcntl instead.

For 2, we define htobe/betoh as part of the compat/endian.h and make
sure that any users of those functions actually include compat/endian.h
instead of implicit include of system endian.h

Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tested-by: Jesper Derehag <jderehag@hotmail.com>
Signed-off-by: Jesper Derehag <jderehag@hotmail.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
16 files changed:
src/bin/lttng-relayd/cmd-2-2.c
src/bin/lttng-relayd/cmd-2-4.c
src/bin/lttng-relayd/live.c
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/jul-thread.c
src/bin/lttng-sessiond/jul.c
src/common/compat/compat-epoll.c
src/common/compat/endian.h
src/common/compat/poll.h
src/common/consumer-timer.c
src/common/consumer.c
src/common/index/index.c
src/common/kernel-consumer/kernel-consumer.c
src/common/relayd/relayd.c
src/common/ust-consumer/ust-consumer.c
tests/regression/tools/live/live_test.c

index b7299a5aa256ac7d22bc7bc90bf938a6edaec8bb..978a11e1f55d4359faf26b31efa60a4cd8886c07 100644 (file)
@@ -23,6 +23,8 @@
 #include <common/common.h>
 #include <common/sessiond-comm/relayd.h>
 
+#include <common/compat/endian.h>
+
 #include "cmd-generic.h"
 #include "cmd-2-1.h"
 #include "utils.h"
index 31963839cea00a1db297139b42d03af9f3ae0c43..6d927a05341a2ed503ec473cd75c4a463828c9eb 100644 (file)
@@ -23,6 +23,8 @@
 #include <common/common.h>
 #include <common/sessiond-comm/relayd.h>
 
+#include <common/compat/endian.h>
+
 #include "cmd-generic.h"
 #include "lttng-relayd.h"
 
index c60f7e4c9c4db0f3d00dff773b2c537b0cc4bd43..d8517d2f6b14ed8a8e58668a90d282020fbff19c 100644 (file)
@@ -43,6 +43,7 @@
 #include <common/common.h>
 #include <common/compat/poll.h>
 #include <common/compat/socket.h>
+#include <common/compat/endian.h>
 #include <common/defaults.h>
 #include <common/futex.h>
 #include <common/index/index.h>
index a93151ac47f560875f07c9cbf113225f9dd892cc..93b08fcaa4a32cddfb4deef66682e8a1b8ae6135 100644 (file)
@@ -44,6 +44,7 @@
 #include <common/common.h>
 #include <common/compat/poll.h>
 #include <common/compat/socket.h>
+#include <common/compat/endian.h>
 #include <common/defaults.h>
 #include <common/daemonize.h>
 #include <common/futex.h>
index cc694df81066718a82ded69fc2baf36b683b726b..9859a1071b31adf7c408a4937cb7a53939042300 100644 (file)
@@ -23,6 +23,8 @@
 #include <common/uri.h>
 #include <common/utils.h>
 
+#include <common/compat/endian.h>
+
 #include "fd-limit.h"
 #include "jul-thread.h"
 #include "lttng-sessiond.h"
index 7bb0d75bce80afe3265c4306033b4ea0cff3e47c..da4cf6782322f5c44bdcab50c1349ee7e1155324 100644 (file)
@@ -22,6 +22,8 @@
 #include <common/common.h>
 #include <common/sessiond-comm/jul.h>
 
+#include <common/compat/endian.h>
+
 #include "jul.h"
 #include "ust-app.h"
 #include "utils.h"
index ecd09a0924a43f3aef6dbcd0fdb2055a45d44bb9..368fae19f6c3615b00760ce99b07d0b3250c7cf1 100644 (file)
@@ -81,7 +81,7 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
                size = poll_max_size;
        }
 
-       ret = epoll_create1(flags);
+       ret = compat_glibc_epoll_create(size, flags);
        if (ret < 0) {
                /* At this point, every error is fatal */
                PERROR("epoll_create1");
index 2850866aa98ef28f9899e7f6d2fcdd3d6b537269..baea531971433f4a54c80886c34195e64ece7920 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef _COMPAT_ENDIAN_H
+#ifndef _COMPAT_ENDIAN_H
 #define _COMPAT_ENDIAN_H
 
 #ifdef __linux__
 #include <endian.h>
+
+/*
+ * htobe/betoh are not defined for glibc <2.9, so add them
+ * explicitly if they are missing.
+ */
+#ifdef __USE_BSD
+/* Conversion interfaces. */
+# include <byteswap.h>
+
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  ifndef htobe16
+#   define htobe16(x) __bswap_16(x)
+#  endif
+#  ifndef htole16
+#   define htole16(x) (x)
+#  endif
+#  ifndef be16toh
+#   define be16toh(x) __bswap_16(x)
+#  endif
+#  ifndef le16toh
+#   define le16toh(x) (x)
+#  endif
+
+#  ifndef htobe32
+#   define htobe32(x) __bswap_32(x)
+#  endif
+#  ifndef htole32
+#   define htole32(x) (x)
+#  endif
+#  ifndef be32toh
+#   define be32toh(x) __bswap_32(x)
+#  endif
+#  ifndef le32toh
+#   define le32toh(x) (x)
+#  endif
+
+#  ifndef htobe64
+#   define htobe64(x) __bswap_64(x)
+#  endif
+#  ifndef htole64
+#   define htole64(x) (x)
+#  endif
+#  ifndef be64toh
+#   define be64toh(x) __bswap_64(x)
+#  endif
+#  ifndef le64toh
+#   define le64toh(x) (x)
+#  endif
+
+# else /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#  ifndef htobe16
+#   define htobe16(x) (x)
+#  endif
+#  ifndef htole16
+#   define htole16(x) __bswap_16(x)
+#  endif
+#  ifndef be16toh
+#   define be16toh(x) (x)
+#  endif
+#  ifndef le16toh
+#   define le16toh(x) __bswap_16(x)
+#  endif
+
+#  ifndef htobe32
+#   define htobe32(x) (x)
+#  endif
+#  ifndef htole32
+#   define htole32(x) __bswap_32(x)
+#  endif
+#  ifndef be32toh
+#   define be32toh(x) (x)
+#  endif
+#  ifndef le32toh
+#   define le32toh(x) __bswap_32(x)
+#  endif
+
+#  ifndef htobe64
+#   define htobe64(x) (x)
+#  endif
+#  ifndef htole64
+#   define htole64(x) __bswap_64(x)
+#  endif
+#  ifndef be64toh
+#   define be64toh(x) (x)
+#  endif
+#  ifndef le64toh
+#   define le64toh(x) __bswap_64(x)
+#  endif
+
+# endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#endif /* __USE_BSD */
+
 #elif defined(__FreeBSD__)
 #include <machine/endian.h>
 #else
index b019b42c09ff12f81dfc92a12c6872e318f678ea..f892c832333eb10bdfcc4cf64d66918c17d3ab02 100644 (file)
@@ -52,6 +52,8 @@ static inline void __lttng_poll_free(void *events)
 #ifdef HAVE_EPOLL
 #include <sys/epoll.h>
 #include <stdio.h>
+#include <features.h>
+#include <common/compat/fcntl.h>
 
 /* See man epoll(7) for this define path */
 #define COMPAT_EPOLL_PROC_PATH "/proc/sys/fs/epoll/max_user_watches"
@@ -71,7 +73,17 @@ enum {
        LPOLLNVAL = EPOLLHUP,
        LPOLLRDHUP = EPOLLRDHUP,
        /* Close on exec feature of epoll */
+#if __GLIBC_PREREQ(2, 9)
        LTTNG_CLOEXEC = EPOLL_CLOEXEC,
+#else
+       /*
+        * EPOLL_CLOEXEC was added in glibc 2.8 (usually used in conjunction with
+        * epoll_create1(..)), but since neither EPOLL_CLOEXEC exists nor
+        * epoll_create1(..), we set it to FD_CLOEXEC so that we can pass it
+        * directly to fcntl(..) instead.
+        */
+       LTTNG_CLOEXEC = FD_CLOEXEC,
+#endif
 };
 
 struct compat_epoll_event {
@@ -115,6 +127,27 @@ extern int compat_epoll_create(struct lttng_poll_event *events,
 #define lttng_poll_create(events, size, flags) \
        compat_epoll_create(events, size, flags)
 
+#if __GLIBC_PREREQ(2, 9)
+static inline int compat_glibc_epoll_create(int size __attribute__((unused)),
+               int flags)
+{
+       return epoll_create1(flags);
+}
+#else
+static inline int compat_glibc_epoll_create(int size, int flags)
+{
+       /*
+        * epoll_create1 was added in glibc 2.9, but unfortunatly reverting to
+        * epoll_create(..) also means that we lose the possibility to
+        * directly set the EPOLL_CLOEXEC, so try and do it anyway but through
+        * fcntl(..).
+        */
+       int efd = epoll_create(size);
+       assert(fcntl(efd, F_SETFD, flags) != -1);
+       return efd;
+}
+#endif
+
 /*
  * Wait on epoll set with the number of fd registered to the lttng_poll_event
  * data structure (events).
index dc6f2f7fc42833e551973191e4a21e8eed2ae2b9..c659bf63333a0de56fc568f99c167fb55e12e24c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <bin/lttng-consumerd/health-consumerd.h>
 #include <common/common.h>
+#include <common/compat/endian.h>
 #include <common/kernel-ctl/kernel-ctl.h>
 #include <common/kernel-consumer/kernel-consumer.h>
 #include <common/consumer-stream.h>
index e80ac6be751fbba7eebc98404d520f9ea62c4cd5..cba4a605a4f8d119d4f324427fe81761b605c240 100644 (file)
@@ -34,6 +34,7 @@
 #include <common/common.h>
 #include <common/utils.h>
 #include <common/compat/poll.h>
+#include <common/compat/endian.h>
 #include <common/index/index.h>
 #include <common/kernel-ctl/kernel-ctl.h>
 #include <common/sessiond-comm/relayd.h>
index abc0985412fb9c715bf4839196d5589c684c4596..a462a635e78dfff933efc4dcec1253ceca37f552 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <common/common.h>
 #include <common/defaults.h>
+#include <common/compat/endian.h>
 #include <common/utils.h>
 
 #include "index.h"
index d15329ffab2f91c601a8b838af5cd805470f10ab..57dc2ba6a76767d623c62fc552cb413fd0a0e71f 100644 (file)
@@ -35,6 +35,7 @@
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/sessiond-comm/relayd.h>
 #include <common/compat/fcntl.h>
+#include <common/compat/endian.h>
 #include <common/pipe.h>
 #include <common/relayd/relayd.h>
 #include <common/utils.h>
index 3de19c28064d352ef9e1d507f14bac3cd318a823..38ebdbde229454c7c98304171786552ce4bdcbdd 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <common/common.h>
 #include <common/defaults.h>
+#include <common/compat/endian.h>
 #include <common/sessiond-comm/relayd.h>
 #include <common/index/ctf-index.h>
 
index 9f2e739a36fb59ba5bbba2df574dfcecbab2327d..b8c1a3cd9a74559e3cf7a79ba8e4610ae8038097 100644 (file)
@@ -37,6 +37,7 @@
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/relayd/relayd.h>
 #include <common/compat/fcntl.h>
+#include <common/compat/endian.h>
 #include <common/consumer-metadata-cache.h>
 #include <common/consumer-stream.h>
 #include <common/consumer-timer.h>
index aff897724e6a23f3a10b0424571e072146583767..d2c9050f615fe6e3f04a4935afca7798e45f1de6 100644 (file)
@@ -43,6 +43,8 @@
 #include <bin/lttng-relayd/lttng-viewer-abi.h>
 #include <common/index/ctf-index.h>
 
+#include <common/compat/endian.h>
+
 #define SESSION1 "test1"
 #define RELAYD_URL "net://localhost"
 #define LIVE_TIMER 2000000
This page took 0.049146 seconds and 4 git commands to generate.