diff options
| author | Simon Ser <contact@emersion.fr> | 2023-06-26 12:34:59 +0200 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2023-06-27 13:31:50 +0200 |
| commit | 4ec379ebcc4d33b3ffa493df12438ade2610eb5f (patch) | |
| tree | 766b005a49ef3977a0a33b2365d0202133a4bb48 /src/wayland-os.c | |
| parent | egl: add missing ABI check test (diff) | |
| download | wayland-4ec379ebcc4d33b3ffa493df12438ade2610eb5f.tar wayland-4ec379ebcc4d33b3ffa493df12438ade2610eb5f.tar.gz wayland-4ec379ebcc4d33b3ffa493df12438ade2610eb5f.tar.bz2 wayland-4ec379ebcc4d33b3ffa493df12438ade2610eb5f.tar.lz wayland-4ec379ebcc4d33b3ffa493df12438ade2610eb5f.tar.xz wayland-4ec379ebcc4d33b3ffa493df12438ade2610eb5f.tar.zst wayland-4ec379ebcc4d33b3ffa493df12438ade2610eb5f.zip | |
tests: manually wrap libc functions
The way we're wrapping libc functions via dlsym() is pretty fragile
and breaks on FreeBSD. The failures happen in our CI and are pretty
random, see e.g. [1].
Use a more manual way to wrap via a function pointer.
[1]: https://gitlab.freedesktop.org/wayland/wayland/-/jobs/44204010
Signed-off-by: Simon Ser <contact@emersion.fr>
Diffstat (limited to 'src/wayland-os.c')
| -rw-r--r-- | src/wayland-os.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/wayland-os.c b/src/wayland-os.c index a9066ca..a0db2e8 100644 --- a/src/wayland-os.c +++ b/src/wayland-os.c @@ -42,6 +42,12 @@ #include "wayland-os.h" +/* used by tests */ +int (*wl_fcntl)(int fildes, int cmd, ...) = fcntl; +int (*wl_socket)(int domain, int type, int protocol) = socket; +ssize_t (*wl_recvmsg)(int socket, struct msghdr *message, int flags) = recvmsg; +int (*wl_epoll_create1)(int flags) = epoll_create1; + static int set_cloexec_or_close(int fd) { @@ -50,11 +56,11 @@ set_cloexec_or_close(int fd) if (fd == -1) return -1; - flags = fcntl(fd, F_GETFD); + flags = wl_fcntl(fd, F_GETFD); if (flags == -1) goto err; - if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) + if (wl_fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) goto err; return fd; @@ -69,13 +75,13 @@ wl_os_socket_cloexec(int domain, int type, int protocol) { int fd; - fd = socket(domain, type | SOCK_CLOEXEC, protocol); + fd = wl_socket(domain, type | SOCK_CLOEXEC, protocol); if (fd >= 0) return fd; if (errno != EINVAL) return -1; - fd = socket(domain, type, protocol); + fd = wl_socket(domain, type, protocol); return set_cloexec_or_close(fd); } @@ -124,13 +130,13 @@ wl_os_dupfd_cloexec(int fd, int minfd) { int newfd; - newfd = fcntl(fd, F_DUPFD_CLOEXEC, minfd); + newfd = wl_fcntl(fd, F_DUPFD_CLOEXEC, minfd); if (newfd >= 0) return newfd; if (errno != EINVAL) return -1; - newfd = fcntl(fd, F_DUPFD, minfd); + newfd = wl_fcntl(fd, F_DUPFD, minfd); return set_cloexec_or_close(newfd); } @@ -143,7 +149,7 @@ recvmsg_cloexec_fallback(int sockfd, struct msghdr *msg, int flags) int *fd; int *end; - len = recvmsg(sockfd, msg, flags); + len = wl_recvmsg(sockfd, msg, flags); if (len == -1) return -1; @@ -179,7 +185,7 @@ wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags) #else ssize_t len; - len = recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC); + len = wl_recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC); if (len >= 0) return len; if (errno != EINVAL) @@ -194,7 +200,7 @@ wl_os_epoll_create_cloexec(void) int fd; #ifdef EPOLL_CLOEXEC - fd = epoll_create1(EPOLL_CLOEXEC); + fd = wl_epoll_create1(EPOLL_CLOEXEC); if (fd >= 0) return fd; if (errno != EINVAL) |
