From 9fbfe9b94838cea245472b5619dc4a111fb0dd30 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 1 May 2012 13:03:33 -0400 Subject: [PATCH] Correctly handle running on a system where accept4 doesn't work. Previously, we treated EINVAL as the only errno that indicated a broken accept4. But EINVAL only appears when one of the SOCK_* options isn't supported. If the accept4 syscall itself isn't there, we'll get an ENOSYS. Reported by Azat Khuzhin. --- evutil.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/evutil.c b/evutil.c index bc512333..bc4ee99e 100644 --- a/evutil.c +++ b/evutil.c @@ -2382,8 +2382,14 @@ evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr, evutil_socket_t result; #if defined(EVENT__HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) result = accept4(sockfd, addr, addrlen, flags); - if (result >= 0 || errno != EINVAL) + if (result >= 0 || (errno != EINVAL && errno != ENOSYS)) { + /* A nonnegative result means that we succeeded, so return. + * Failing with EINVAL means that an option wasn't supported, + * and failing with ENOSYS means that the syscall wasn't + * there: in those cases we want to fall back. Otherwise, we + * got a real error, and we should return. */ return result; + } #endif result = accept(sockfd, addr, addrlen); if (result < 0) -- 2.40.0