From patchwork Sun Jun 28 18:06:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1318620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49vz8C4B3wz9sPF for ; Mon, 29 Jun 2020 04:06:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB77A38708DC; Sun, 28 Jun 2020 18:06:16 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by sourceware.org (Postfix) with ESMTPS id 257353851C2A for ; Sun, 28 Jun 2020 18:06:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 257353851C2A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 3BDE118A2; Sun, 28 Jun 2020 20:06:13 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3hDuhwLRxPJT; Sun, 28 Jun 2020 20:06:12 +0200 (CEST) Received: from function (lfbn-bor-1-797-11.w86-234.abo.wanadoo.fr [86.234.239.11]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 29AE5CA3; Sun, 28 Jun 2020 20:06:12 +0200 (CEST) Received: from samy by function with local (Exim 4.94) (envelope-from ) id 1jpbgw-002nwl-Ny; Sun, 28 Jun 2020 20:06:10 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: make wait4 a cancellation point Date: Sun, 28 Jun 2020 20:06:10 +0200 Message-Id: <20200628180610.668610-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" and add _nocancel variant. * sysdeps/mach/hurd/Makefile [io] (sysdep_routines): Add wait4_nocancel. * sysdeps/mach/hurd/wait4.c: Include (__wait4): Surround __proc_wait with enabling async cancel, and use __USEPORT_CANCEL instead of __USEPORT. * sysdeps/mach/hurd/wait4_nocancel.c: New file, contains previous implementation of __wait4. * sysdeps/mach/hurd/not-cancel.h (__waitpid_nocancel): Replace macro with __wait4_nocancel declaration with hidden proto, and make __waitpid_nocancel call __wait4_nocancel. --- sysdeps/mach/hurd/Makefile | 3 +- sysdeps/mach/hurd/not-cancel.h | 9 +++-- sysdeps/mach/hurd/wait4.c | 10 ++++-- sysdeps/mach/hurd/wait4_nocancel.c | 54 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 sysdeps/mach/hurd/wait4_nocancel.c diff --git a/sysdeps/mach/hurd/Makefile b/sysdeps/mach/hurd/Makefile index 4bfd290c09..a1ca034175 100644 --- a/sysdeps/mach/hurd/Makefile +++ b/sysdeps/mach/hurd/Makefile @@ -198,7 +198,8 @@ endif ifeq (io, $(subdir)) sysdep_routines += f_setlk close_nocancel close_nocancel_nostatus \ open_nocancel openat_nocancel read_nocancel \ - pread64_nocancel write_nocancel pwrite64_nocancel + pread64_nocancel write_nocancel pwrite64_nocancel \ + wait4_nocancel endif ifeq (misc, $(subdir)) diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cancel.h index 7e824c5f11..69cd781f68 100644 --- a/sysdeps/mach/hurd/not-cancel.h +++ b/sysdeps/mach/hurd/not-cancel.h @@ -63,9 +63,13 @@ __typeof (__writev) __writev_nocancel; /* Non cancellable writev syscall with no status. */ void __writev_nocancel_nostatus (int fd, const struct iovec *vector, int count); -/* For now we have none. Map the name to the normal functions. */ +/* Non cancellable wait4 syscall. */ +__typeof (__wait4) __wait4_nocancel; + # define __waitpid_nocancel(pid, stat_loc, options) \ - __waitpid (pid, stat_loc, options) + __wait4_nocancel (pid, stat_loc, options, NULL) + +/* For now we have none. Map the name to the normal functions. */ #define __fcntl64_nocancel(fd, cmd, ...) \ __fcntl64 (fd, cmd, __VA_ARGS__) @@ -80,6 +84,7 @@ hidden_proto (__write_nocancel) hidden_proto (__pwrite64_nocancel) hidden_proto (__writev_nocancel) hidden_proto (__writev_nocancel_nostatus) +hidden_proto (__wait4_nocancel) #endif #endif /* NOT_CANCEL_H */ diff --git a/sysdeps/mach/hurd/wait4.c b/sysdeps/mach/hurd/wait4.c index 7cc969bf30..49c1b5d497 100644 --- a/sysdeps/mach/hurd/wait4.c +++ b/sysdeps/mach/hurd/wait4.c @@ -20,6 +20,7 @@ #include #include #include +#include pid_t __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage) @@ -29,10 +30,13 @@ __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage) struct rusage ignored; int sigcode; int dummy; + int cancel_oldtype; - err = __USEPORT (PROC, __proc_wait (port, pid, options, - stat_loc ?: &dummy, &sigcode, - usage ?: &ignored, &dead)); + cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = __USEPORT_CANCEL (PROC, __proc_wait (port, pid, options, + stat_loc ?: &dummy, &sigcode, + usage ?: &ignored, &dead)); + LIBC_CANCEL_RESET (cancel_oldtype); switch (err) { case 0: /* Got a child. */ diff --git a/sysdeps/mach/hurd/wait4_nocancel.c b/sysdeps/mach/hurd/wait4_nocancel.c new file mode 100644 index 0000000000..632f2e3ea0 --- /dev/null +++ b/sysdeps/mach/hurd/wait4_nocancel.c @@ -0,0 +1,54 @@ +/* Copyright (C) 1993-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include + +pid_t +__wait4_nocancel (pid_t pid, int *stat_loc, int options, struct rusage *usage) +{ + pid_t dead; + error_t err; + struct rusage ignored; + int sigcode; + int dummy; + + err = __USEPORT (PROC, __proc_wait (port, pid, options, + stat_loc ?: &dummy, &sigcode, + usage ?: &ignored, &dead)); + switch (err) + { + case 0: /* Got a child. */ + return dead; + case EAGAIN: + /* The RPC returns this error when the WNOHANG flag is set and no + selected children are dead (but some are living). In that + situation, our return value is zero. (The RPC can't return zero + for DEAD without also returning some garbage for the other out + parameters, so an error return is much more natural here. Hence + the difference between the RPC and the POSIX.1 interface. */ + return (pid_t) 0; + default: + return (pid_t) __hurd_fail (err); + } +} + +libc_hidden_def (__wait4_nocancel)