fi
AC_SUBST(GCC_CFLAGS)
+AC_CHECK_FUNCS([accept4])
+
AC_ARG_ENABLE([scanner],
[AC_HELP_STRING([--disable-scanner],
[Disable compilation of wayland-scannner])],
* OF THIS SOFTWARE.
*/
+#define _GNU_SOURCE
+
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <sys/epoll.h>
+#include "../config.h"
#include "wayland-os.h"
static int
fd = epoll_create(1);
return set_cloexec_or_close(fd);
}
+
+int
+wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+{
+ int fd;
+
+#ifdef HAVE_ACCEPT4
+ fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC);
+ if (fd >= 0)
+ return fd;
+ if (errno != ENOSYS)
+ return -1;
+#endif
+
+ fd = accept(sockfd, addr, addrlen);
+ return set_cloexec_or_close(fd);
+}
int
wl_os_epoll_create_cloexec(void);
+int
+wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+
/*
* The following are for wayland-os.c and the unit tests.
int client_fd;
length = sizeof name;
- client_fd =
- accept4(fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC);
- if (client_fd < 0 && errno == ENOSYS) {
- client_fd = accept(fd, (struct sockaddr *) &name, &length);
- if (client_fd >= 0 && fcntl(client_fd, F_SETFD, FD_CLOEXEC) == -1)
- fprintf(stderr, "failed to set FD_CLOEXEC flag on client fd, errno: %d\n", errno);
- }
-
+ client_fd = wl_os_accept_cloexec(fd, (struct sockaddr *) &name,
+ &length);
if (client_fd < 0)
fprintf(stderr, "failed to accept, errno: %d\n", errno);
init_fallbacks(1);
do_os_wrappers_epoll_create_cloexec(2);
}
+
+/* FIXME: add tests for wl_os_accept_cloexec() */