aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2016-06-09 09:42:06 -0700
committerGravatar Sree Kuchibhotla <sreek@google.com>2016-06-09 09:42:06 -0700
commit727440216553c01925c0f5bc88293108bb3f051f (patch)
tree0e043706960365cdcc5db8253c953c7427e372ac
parent0553a436610201b252cfce0ed5d2cea69da15e85 (diff)
Check epoll is actually available. set GPR_LINUX_EPOLL only in GLIBC ver
2.9 and above
-rw-r--r--include/grpc/impl/codegen/port_platform.h2
-rw-r--r--src/core/lib/iomgr/ev_epoll_linux.c19
2 files changed, 20 insertions, 1 deletions
diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h
index 7a6ec53fb4..affef9e66b 100644
--- a/include/grpc/impl/codegen/port_platform.h
+++ b/include/grpc/impl/codegen/port_platform.h
@@ -189,7 +189,6 @@
#define GPR_GCC_ATOMIC 1
#define GPR_GCC_TLS 1
#define GPR_LINUX 1
-#define GPR_LINUX_EPOLL 1
#define GPR_LINUX_LOG
#define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1
#define GPR_POSIX_WAKEUP_FD 1
@@ -201,6 +200,7 @@
#ifdef __GLIBC_PREREQ
#if __GLIBC_PREREQ(2, 9)
#define GPR_LINUX_EVENTFD 1
+#define GPR_LINUX_EPOLL 1
#endif
#if __GLIBC_PREREQ(2, 10)
#define GPR_LINUX_SOCKETUTILS 1
diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c
index 66bbae52b2..d2d5d2852b 100644
--- a/src/core/lib/iomgr/ev_epoll_linux.c
+++ b/src/core/lib/iomgr/ev_epoll_linux.c
@@ -1481,7 +1481,26 @@ static const grpc_event_engine_vtable vtable = {
.shutdown_engine = shutdown_engine,
};
+/* It is possible that GLIBC has epoll but the underlying kernel doesn't.
+ * Create a dummy epoll_fd to make sure epoll support is available */
+static bool is_epoll_available() {
+ int fd = epoll_create1(EPOLL_CLOEXEC);
+ if (fd < 0) {
+ gpr_log(
+ GPR_ERROR,
+ "epoll_create1 failed with error: %d. Not using epoll polling engine",
+ fd);
+ return false;
+ }
+ close(fd);
+ return true;
+}
+
const grpc_event_engine_vtable *grpc_init_epoll_linux(void) {
+ if (!is_epoll_available()) {
+ return NULL;
+ }
+
fd_global_init();
pollset_global_init();
polling_island_global_init();