diff options
| author | Pekka Paalanen <ppaalanen@gmail.com> | 2012-03-22 15:02:05 +0200 |
|---|---|---|
| committer | Pekka Paalanen <ppaalanen@gmail.com> | 2012-04-25 09:37:42 +0300 |
| commit | b2eaf870cf8e8cb842ba29ea4718b596101252a6 (patch) | |
| tree | ce24bd654adfd6ad7f4634f86cc074cef2b1924c /src | |
| parent | os: wrap recvmsg(MSG_CMSG_CLOEXEC) (diff) | |
| download | wayland-b2eaf870cf8e8cb842ba29ea4718b596101252a6.tar wayland-b2eaf870cf8e8cb842ba29ea4718b596101252a6.tar.gz wayland-b2eaf870cf8e8cb842ba29ea4718b596101252a6.tar.bz2 wayland-b2eaf870cf8e8cb842ba29ea4718b596101252a6.tar.lz wayland-b2eaf870cf8e8cb842ba29ea4718b596101252a6.tar.xz wayland-b2eaf870cf8e8cb842ba29ea4718b596101252a6.tar.zst wayland-b2eaf870cf8e8cb842ba29ea4718b596101252a6.zip | |
os: wrap epoll_create
Some system C libraries do not have epoll_create1() nor EPOLL_CLOEXEC,
provide a fallback.
Add tests for the wrapper.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/event-loop.c | 3 | ||||
| -rw-r--r-- | src/wayland-os.c | 18 | ||||
| -rw-r--r-- | src/wayland-os.h | 3 |
3 files changed, 23 insertions, 1 deletions
diff --git a/src/event-loop.c b/src/event-loop.c index 3bab3df..ee2eae5 100644 --- a/src/event-loop.c +++ b/src/event-loop.c @@ -34,6 +34,7 @@ #include <unistd.h> #include <assert.h> #include "wayland-server.h" +#include "wayland-os.h" struct wl_event_loop { int epoll_fd; @@ -392,7 +393,7 @@ wl_event_loop_create(void) if (loop == NULL) return NULL; - loop->epoll_fd = epoll_create1(EPOLL_CLOEXEC); + loop->epoll_fd = wl_os_epoll_create_cloexec(); if (loop->epoll_fd < 0) { free(loop); return NULL; diff --git a/src/wayland-os.c b/src/wayland-os.c index eb53eec..a8756b6 100644 --- a/src/wayland-os.c +++ b/src/wayland-os.c @@ -25,6 +25,7 @@ #include <unistd.h> #include <fcntl.h> #include <errno.h> +#include <sys/epoll.h> #include "wayland-os.h" @@ -124,3 +125,20 @@ wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags) return recvmsg_cloexec_fallback(sockfd, msg, flags); } + +int +wl_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/src/wayland-os.h b/src/wayland-os.h index 43c317b..f6827f1 100644 --- a/src/wayland-os.h +++ b/src/wayland-os.h @@ -32,6 +32,9 @@ wl_os_dupfd_cloexec(int fd, long minfd); ssize_t wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags); +int +wl_os_epoll_create_cloexec(void); + /* * The following are for wayland-os.c and the unit tests. |
