From f263b7fd113e51d0737554e8232b8669e142a260 Mon Sep 17 00:00:00 2001 From: Jesper Derehag Date: Thu, 24 Apr 2014 10:22:50 +0200 Subject: [PATCH] Backported to glibc 2.8 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 Tested-by: Jesper Derehag Signed-off-by: Jesper Derehag Signed-off-by: David Goulet --- src/bin/lttng-relayd/cmd-2-2.c | 2 + src/bin/lttng-relayd/cmd-2-4.c | 2 + src/bin/lttng-relayd/live.c | 1 + src/bin/lttng-relayd/main.c | 1 + src/bin/lttng-sessiond/jul-thread.c | 2 + src/bin/lttng-sessiond/jul.c | 2 + src/common/compat/compat-epoll.c | 2 +- src/common/compat/endian.h | 94 +++++++++++++++++++- src/common/compat/poll.h | 33 +++++++ src/common/consumer-timer.c | 1 + src/common/consumer.c | 1 + src/common/index/index.c | 1 + src/common/kernel-consumer/kernel-consumer.c | 1 + src/common/relayd/relayd.c | 1 + src/common/ust-consumer/ust-consumer.c | 1 + tests/regression/tools/live/live_test.c | 2 + 16 files changed, 145 insertions(+), 2 deletions(-) diff --git a/src/bin/lttng-relayd/cmd-2-2.c b/src/bin/lttng-relayd/cmd-2-2.c index b7299a5aa..978a11e1f 100644 --- a/src/bin/lttng-relayd/cmd-2-2.c +++ b/src/bin/lttng-relayd/cmd-2-2.c @@ -23,6 +23,8 @@ #include #include +#include + #include "cmd-generic.h" #include "cmd-2-1.h" #include "utils.h" diff --git a/src/bin/lttng-relayd/cmd-2-4.c b/src/bin/lttng-relayd/cmd-2-4.c index 31963839c..6d927a053 100644 --- a/src/bin/lttng-relayd/cmd-2-4.c +++ b/src/bin/lttng-relayd/cmd-2-4.c @@ -23,6 +23,8 @@ #include #include +#include + #include "cmd-generic.h" #include "lttng-relayd.h" diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index c60f7e4c9..d8517d2f6 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index a93151ac4..93b08fcaa 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include diff --git a/src/bin/lttng-sessiond/jul-thread.c b/src/bin/lttng-sessiond/jul-thread.c index cc694df81..9859a1071 100644 --- a/src/bin/lttng-sessiond/jul-thread.c +++ b/src/bin/lttng-sessiond/jul-thread.c @@ -23,6 +23,8 @@ #include #include +#include + #include "fd-limit.h" #include "jul-thread.h" #include "lttng-sessiond.h" diff --git a/src/bin/lttng-sessiond/jul.c b/src/bin/lttng-sessiond/jul.c index 7bb0d75bc..da4cf6782 100644 --- a/src/bin/lttng-sessiond/jul.c +++ b/src/bin/lttng-sessiond/jul.c @@ -22,6 +22,8 @@ #include #include +#include + #include "jul.h" #include "ust-app.h" #include "utils.h" diff --git a/src/common/compat/compat-epoll.c b/src/common/compat/compat-epoll.c index ecd09a092..368fae19f 100644 --- a/src/common/compat/compat-epoll.c +++ b/src/common/compat/compat-epoll.c @@ -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"); diff --git a/src/common/compat/endian.h b/src/common/compat/endian.h index 2850866aa..baea53197 100644 --- a/src/common/compat/endian.h +++ b/src/common/compat/endian.h @@ -15,11 +15,103 @@ * 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 + +/* + * htobe/betoh are not defined for glibc <2.9, so add them + * explicitly if they are missing. + */ +#ifdef __USE_BSD +/* Conversion interfaces. */ +# include + +# 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 #else diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index b019b42c0..f892c8323 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -52,6 +52,8 @@ static inline void __lttng_poll_free(void *events) #ifdef HAVE_EPOLL #include #include +#include +#include /* 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). diff --git a/src/common/consumer-timer.c b/src/common/consumer-timer.c index dc6f2f7fc..c659bf633 100644 --- a/src/common/consumer-timer.c +++ b/src/common/consumer-timer.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include diff --git a/src/common/consumer.c b/src/common/consumer.c index e80ac6be7..cba4a605a 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/src/common/index/index.c b/src/common/index/index.c index abc098541..a462a635e 100644 --- a/src/common/index/index.c +++ b/src/common/index/index.c @@ -24,6 +24,7 @@ #include #include +#include #include #include "index.h" diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index d15329ffa..57dc2ba6a 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/src/common/relayd/relayd.c b/src/common/relayd/relayd.c index 3de19c280..38ebdbde2 100644 --- a/src/common/relayd/relayd.c +++ b/src/common/relayd/relayd.c @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 9f2e739a3..b8c1a3cd9 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/regression/tools/live/live_test.c b/tests/regression/tools/live/live_test.c index aff897724..d2c9050f6 100644 --- a/tests/regression/tools/live/live_test.c +++ b/tests/regression/tools/live/live_test.c @@ -43,6 +43,8 @@ #include #include +#include + #define SESSION1 "test1" #define RELAYD_URL "net://localhost" #define LIVE_TIMER 2000000 -- 2.34.1