mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-05-02 06:46:26 -04:00
os: Use fallback implementations when *_CLOEXEC are unavailable at build time
On platforms without F_DUPFD_CLOEXEC, MSG_CMSG_CLOEXEC, or SOCK_CLOEXEC, we should skip past their usage and just use the fcntl() fallback. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
parent
a77aa44f0e
commit
d8e90f4a16
2 changed files with 16 additions and 3 deletions
|
|
@ -75,11 +75,13 @@ wl_os_socket_cloexec(int domain, int type, int protocol)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
#ifdef SOCK_CLOEXEC
|
||||||
fd = wl_socket(domain, type | SOCK_CLOEXEC, protocol);
|
fd = wl_socket(domain, type | SOCK_CLOEXEC, protocol);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
return fd;
|
return fd;
|
||||||
if (errno != EINVAL)
|
if (errno != EINVAL)
|
||||||
return -1;
|
return -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
fd = wl_socket(domain, type, protocol);
|
fd = wl_socket(domain, type, protocol);
|
||||||
return set_cloexec_or_close(fd);
|
return set_cloexec_or_close(fd);
|
||||||
|
|
@ -148,11 +150,13 @@ wl_os_dupfd_cloexec(int fd, int minfd)
|
||||||
{
|
{
|
||||||
int newfd;
|
int newfd;
|
||||||
|
|
||||||
|
#ifdef F_DUPFD_CLOEXEC
|
||||||
newfd = wl_fcntl(fd, F_DUPFD_CLOEXEC, minfd);
|
newfd = wl_fcntl(fd, F_DUPFD_CLOEXEC, minfd);
|
||||||
if (newfd >= 0)
|
if (newfd >= 0)
|
||||||
return newfd;
|
return newfd;
|
||||||
if (errno != EINVAL)
|
if (errno != EINVAL)
|
||||||
return -1;
|
return -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
newfd = wl_fcntl(fd, F_DUPFD, minfd);
|
newfd = wl_fcntl(fd, F_DUPFD, minfd);
|
||||||
return set_cloexec_or_close(newfd);
|
return set_cloexec_or_close(newfd);
|
||||||
|
|
@ -200,7 +204,7 @@ wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags)
|
||||||
* fix (https://cgit.freebsd.org/src/commit/?id=6ceacebdf52211).
|
* fix (https://cgit.freebsd.org/src/commit/?id=6ceacebdf52211).
|
||||||
*/
|
*/
|
||||||
#pragma message("Using fallback directly since MSG_CMSG_CLOEXEC is broken.")
|
#pragma message("Using fallback directly since MSG_CMSG_CLOEXEC is broken.")
|
||||||
#else
|
#elif defined(MSG_CMSG_CLOEXEC)
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
len = wl_recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC);
|
len = wl_recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC);
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,12 @@ socket_wrapper(int domain, int type, int protocol)
|
||||||
{
|
{
|
||||||
wrapped_calls_socket++;
|
wrapped_calls_socket++;
|
||||||
|
|
||||||
|
#ifdef SOCK_CLOEXEC
|
||||||
if (fall_back && (type & SOCK_CLOEXEC)) {
|
if (fall_back && (type & SOCK_CLOEXEC)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return socket(domain, type, protocol);
|
return socket(domain, type, protocol);
|
||||||
}
|
}
|
||||||
|
|
@ -78,12 +80,16 @@ fcntl_wrapper(int fd, int cmd, ...)
|
||||||
|
|
||||||
wrapped_calls_fcntl++;
|
wrapped_calls_fcntl++;
|
||||||
|
|
||||||
|
#ifdef F_DUPFD_CLOEXEC
|
||||||
if (fall_back && (cmd == F_DUPFD_CLOEXEC)) {
|
if (fall_back && (cmd == F_DUPFD_CLOEXEC)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
#ifdef F_DUPFD_CLOEXEC
|
||||||
case F_DUPFD_CLOEXEC:
|
case F_DUPFD_CLOEXEC:
|
||||||
|
#endif
|
||||||
case F_DUPFD:
|
case F_DUPFD:
|
||||||
case F_SETFD:
|
case F_SETFD:
|
||||||
va_start(ap, cmd);
|
va_start(ap, cmd);
|
||||||
|
|
@ -110,10 +116,12 @@ recvmsg_wrapper(int sockfd, struct msghdr *msg, int flags)
|
||||||
{
|
{
|
||||||
wrapped_calls_recvmsg++;
|
wrapped_calls_recvmsg++;
|
||||||
|
|
||||||
|
#ifdef MSG_CMSG_CLOEXEC
|
||||||
if (fall_back && (flags & MSG_CMSG_CLOEXEC)) {
|
if (fall_back && (flags & MSG_CMSG_CLOEXEC)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return recvmsg(sockfd, msg, flags);
|
return recvmsg(sockfd, msg, flags);
|
||||||
}
|
}
|
||||||
|
|
@ -323,9 +331,10 @@ do_os_wrappers_recvmsg_cloexec(int n)
|
||||||
struct marshal_data data;
|
struct marshal_data data;
|
||||||
|
|
||||||
data.nr_fds_begin = count_open_fds();
|
data.nr_fds_begin = count_open_fds();
|
||||||
#if HAVE_BROKEN_MSG_CMSG_CLOEXEC
|
#if HAVE_BROKEN_MSG_CMSG_CLOEXEC || !defined(MSG_CMSG_CLOEXEC)
|
||||||
/* We call the fallback directly on FreeBSD versions with a broken
|
/* We call the fallback directly on FreeBSD versions with a broken
|
||||||
* MSG_CMSG_CLOEXEC, so we don't call the local recvmsg() wrapper. */
|
* MSG_CMSG_CLOEXEC or platforms without MSG_CMSG_CLOEXEC, so we
|
||||||
|
* don't call the local recvmsg() wrapper. */
|
||||||
data.wrapped_calls = 0;
|
data.wrapped_calls = 0;
|
||||||
#else
|
#else
|
||||||
data.wrapped_calls = n;
|
data.wrapped_calls = n;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue