From patchwork Thu Jul 19 23:25:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 28492 Received: (qmail 2807 invoked by alias); 19 Jul 2018 23:25:19 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 2792 invoked by uid 89); 19 Jul 2018 23:25:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Thomas Schwinge Subject: [hurd, commited] hurd: SOCK_CLOEXEC and SOCK_NONBLOCK for socketpair Date: Fri, 20 Jul 2018 01:25:13 +0200 Message-Id: <20180719232513.11503-1-samuel.thibault@ens-lyon.org> From: Thomas Schwinge * sysdeps/mach/hurd/socketpair.c (__socketpair): Handle SOCK_CLOEXEC and SOCK_NONBLOCK. --- ChangeLog | 2 ++ sysdeps/mach/hurd/socketpair.c | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 499099006d..7692a193f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,8 @@ * sysdeps/mach/hurd/socket.c (__socket): Handle SOCK_CLOEXEC and SOCK_NONBLOCK. + * sysdeps/mach/hurd/socketpair.c (__socketpair): Handle SOCK_CLOEXEC + and SOCK_NONBLOCK. 2018-07-19 Leonardo Sandoval diff --git a/sysdeps/mach/hurd/socketpair.c b/sysdeps/mach/hurd/socketpair.c index 3b18c676c0..6dce208157 100644 --- a/sysdeps/mach/hurd/socketpair.c +++ b/sysdeps/mach/hurd/socketpair.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -34,6 +35,11 @@ __socketpair (int domain, int type, int protocol, int fds[2]) error_t err; socket_t server, sock1, sock2; int d1, d2; + int flags = sock_to_o_flags (type & ~SOCK_TYPE_MASK); + type &= SOCK_TYPE_MASK; + + if (flags & ~(O_CLOEXEC | O_NONBLOCK)) + return __hurd_fail (EINVAL); if (fds == NULL) return __hurd_fail (EINVAL); @@ -56,6 +62,14 @@ __socketpair (int domain, int type, int protocol, int fds[2]) return -1; err = __socket_create (server, type, protocol, &sock1); } + /* TODO: do we need special ERR massaging here, like it is done in + __socket? */ + if (! err) + { + if (flags & O_NONBLOCK) + err = __io_set_some_openmodes (sock1, O_NONBLOCK); + /* TODO: do we need special ERR massaging after the previous call? */ + } if (err) return __hurd_fail (err); if (err = __socket_create (server, type, protocol, &sock2)) @@ -63,7 +77,12 @@ __socketpair (int domain, int type, int protocol, int fds[2]) __mach_port_deallocate (__mach_task_self (), sock1); return __hurd_fail (err); } - if (err = __socket_connect2 (sock1, sock2)) + if (flags & O_NONBLOCK) + err = __io_set_some_openmodes (sock2, O_NONBLOCK); + /* TODO: do we need special ERR massaging after the previous call? */ + if (! err) + err = __socket_connect2 (sock1, sock2); + if (err) { __mach_port_deallocate (__mach_task_self (), sock1); __mach_port_deallocate (__mach_task_self (), sock2); @@ -72,13 +91,13 @@ __socketpair (int domain, int type, int protocol, int fds[2]) /* Put the sockets into file descriptors. */ - d1 = _hurd_intern_fd (sock1, O_IGNORE_CTTY, 1); + d1 = _hurd_intern_fd (sock1, O_IGNORE_CTTY | flags, 1); if (d1 < 0) { __mach_port_deallocate (__mach_task_self (), sock2); return -1; } - d2 = _hurd_intern_fd (sock2, O_IGNORE_CTTY, 1); + d2 = _hurd_intern_fd (sock2, O_IGNORE_CTTY | flags, 1); if (d2 < 0) { err = errno;