# HG changeset patch # User jbe # Date 1435005378 -7200 # Node ID 45a425c75643925047ef1a680946e07aa0f04b8b # Parent 43a077f2ab49630a7cead809901afa9d0fbe6589 Use accept() only on Linux and only if _GNU_SOURCE is not set diff -r 43a077f2ab49 -r 45a425c75643 moonbridge.c --- a/moonbridge.c Mon Jun 22 22:26:55 2015 +0200 +++ b/moonbridge.c Mon Jun 22 22:36:18 2015 +0200 @@ -1435,8 +1435,7 @@ } else { int peerfd; do { - /* peerfd = accept4(listener->listenfd, NULL, NULL, SOCK_CLOEXEC); */ - /* use accept() instead of accept4() to avoid _GNU_SOURCE on GNU/Linux */ +#if defined(__linux__) && !defined(_GNU_SOURCE) peerfd = accept(listener->listenfd, NULL, NULL); if (peerfd != -1) { if (fcntl(peerfd, F_SETFD, FD_CLOEXEC) == -1) { @@ -1444,6 +1443,9 @@ moonbr_terminate_error(); } } +#else + peerfd = accept4(listener->listenfd, NULL, NULL, SOCK_CLOEXEC); +#endif if (peerfd == -1) { if (errno == EWOULDBLOCK) { break; diff -r 43a077f2ab49 -r 45a425c75643 moonbridge_io.c --- a/moonbridge_io.c Mon Jun 22 22:26:55 2015 +0200 +++ b/moonbridge_io.c Mon Jun 22 22:36:18 2015 +0200 @@ -1183,7 +1183,20 @@ listener->nonblocking = nonblocking; } while (1) { +#if defined(__linux__) && !defined(_GNU_SOURCE) + fd = accept(listener->listenfd, NULL, NULL); + if (fd != -1) { + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { + moonbr_io_errmsg(); + close(listener->fd); + listener->fd = -1; + close(fd); + luaL_error(L, "Unexpected error in fcntl call: %s", errmsg); + } + } +#else fd = accept4(listener->fd, NULL, NULL, SOCK_CLOEXEC); +#endif if (fd < 0) { if (nonblocking && (errno == EAGAIN || errno == EWOULDBLOCK)) { lua_pushboolean(L, 0);