From 647f2bfd2a9214e5bebb2290252d013ccbbb290c Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 30 May 2012 15:53:43 +0300 Subject: [PATCH] window: add wrapper for EPOLL_CLOEXEC Android does not have EPOLL_CLOEXEC, so add a fallback. Signed-off-by: Pekka Paalanen --- clients/window.c | 3 ++- shared/os-compatibility.c | 17 +++++++++++++++++ shared/os-compatibility.h | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clients/window.c b/clients/window.c index 3ef648ef..ae8792e8 100644 --- a/clients/window.c +++ b/clients/window.c @@ -62,6 +62,7 @@ #include #include "../shared/cairo-util.h" #include "text-cursor-position-client-protocol.h" +#include "../shared/os-compatibility.h" #include "window.h" @@ -3299,7 +3300,7 @@ display_create(int argc, char *argv[]) return NULL; } - d->epoll_fd = epoll_create1(EPOLL_CLOEXEC); + d->epoll_fd = os_epoll_create_cloexec(); d->display_fd = wl_display_get_fd(d->display, event_mask_update, d); d->display_task.run = handle_display_data; display_watch_fd(d, d->display_fd, EPOLLIN, &d->display_task); diff --git a/shared/os-compatibility.c b/shared/os-compatibility.c index b79aa1fe..3c065e81 100644 --- a/shared/os-compatibility.c +++ b/shared/os-compatibility.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "os-compatibility.h" @@ -76,3 +77,19 @@ os_socketpair_cloexec(int domain, int type, int protocol, int *sv) return -1; } +int +os_epoll_create_cloexec(void) +{ + int fd; + +#ifdef EPOLL_CLOEXEC + fd = epoll_create1(EPOLL_CLOEXEC); + if (fd >= 0) + return fd; + if (errno != EINVAL) + return -1; +#endif + + fd = epoll_create(1); + return set_cloexec_or_close(fd); +} diff --git a/shared/os-compatibility.h b/shared/os-compatibility.h index ca753b6d..6ada7b63 100644 --- a/shared/os-compatibility.h +++ b/shared/os-compatibility.h @@ -36,4 +36,7 @@ backtrace(void **buffer, int size) int os_socketpair_cloexec(int domain, int type, int protocol, int *sv); +int +os_epoll_create_cloexec(void); + #endif /* OS_COMPATIBILITY_H */