Ryan Beasley | 3f6ed62 | 2019-03-29 05:06:33 -0700 | [diff] [blame] | 1 | From c6d4eb057648e53040a5ec6178bbe73e212d19d4 Mon Sep 17 00:00:00 2001 |
| 2 | From: Ryan Beasley <beasleyr@vmware.com> |
| 3 | Date: Fri, 29 Mar 2019 05:06:33 -0700 |
| 4 | Subject: [PATCH] bazel/grpc: include linux/tcp.h on Linux pre-glibc 2.17 |
| 5 | |
| 6 | Bazel 0.24.0 upgraded grpc from 1.13.0 to 1.18.0, and the latter makes use of |
| 7 | the TCP_USER_TIMEOUT socket option. Problem: grpc conditions the option on |
| 8 | the Linux kernel version but sources the option from glibc's `netinet/tcp.h`. |
| 9 | glibc != Linux kernel, and that option wasn't imported to glibc until 2.17. |
| 10 | |
| 11 | We can't just build Bazel with glibc 2.17 because we still have to support |
| 12 | CentOS 6 dev nodes which ship with glibc 2.12. So instead this change |
| 13 | tweaks the grpc headers to conditionally include <linux/tcp.h> instead of |
| 14 | <netinet/tcp.h>. |
| 15 | |
| 16 | Resolves https://github.com/bazelbuild/bazel/issues/7890. |
| 17 | --- |
| 18 | third_party/grpc/src/core/lib/iomgr/port.h | 9 +++++++++ |
| 19 | third_party/grpc/src/core/lib/iomgr/socket_utils_common_posix.cc | 4 ++++ |
| 20 | 2 files changed, 13 insertions(+) |
| 21 | |
| 22 | diff --git a/third_party/grpc/src/core/lib/iomgr/port.h b/third_party/grpc/src/core/lib/iomgr/port.h |
| 23 | index c8046b21dc..1aea6c1b3e 100644 |
| 24 | --- a/third_party/grpc/src/core/lib/iomgr/port.h |
| 25 | +++ b/third_party/grpc/src/core/lib/iomgr/port.h |
| 26 | @@ -85,6 +85,15 @@ |
| 27 | #ifdef LINUX_VERSION_CODE |
| 28 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37) |
| 29 | #define GRPC_HAVE_TCP_USER_TIMEOUT |
| 30 | +#ifdef __GLIBC_PREREQ |
| 31 | +#if !(__GLIBC_PREREQ(2, 17)) |
| 32 | +/* |
| 33 | + * TCP_USER_TIMEOUT wasn't imported to glibc until 2.17. Use Linux system |
| 34 | + * header instead. |
| 35 | + */ |
| 36 | +#define GRPC_LINUX_TCP_H 1 |
| 37 | +#endif /* __GLIBC_PREREQ(2, 17) */ |
| 38 | +#endif /* ifdef __GLIBC_PREREQ */ |
| 39 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37) */ |
| 40 | #endif /* LINUX_VERSION_CODE */ |
| 41 | #ifndef __GLIBC__ |
| 42 | diff --git a/third_party/grpc/src/core/lib/iomgr/socket_utils_common_posix.cc b/third_party/grpc/src/core/lib/iomgr/socket_utils_common_posix.cc |
| 43 | index 4c337a0521..ea0adb1f6a 100644 |
| 44 | --- a/third_party/grpc/src/core/lib/iomgr/socket_utils_common_posix.cc |
| 45 | +++ b/third_party/grpc/src/core/lib/iomgr/socket_utils_common_posix.cc |
| 46 | @@ -30,7 +30,11 @@ |
| 47 | #include <fcntl.h> |
| 48 | #include <limits.h> |
| 49 | #include <netinet/in.h> |
| 50 | +#ifdef GRPC_LINUX_TCP_H |
| 51 | +#include <linux/tcp.h> |
| 52 | +#else |
| 53 | #include <netinet/tcp.h> |
| 54 | +#endif |
| 55 | #include <stdio.h> |
| 56 | #include <string.h> |
| 57 | #include <sys/socket.h> |
| 58 | -- |
| 59 | 2.14.1 |
| 60 | |