From patchwork Tue Dec 29 00:07:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 41578 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B1A23835092; Tue, 29 Dec 2020 00:07:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id A2A39385042C for ; Tue, 29 Dec 2020 00:07:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A2A39385042C 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 AF60A41A; Tue, 29 Dec 2020 01:07:18 +0100 (CET) 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 gwWb6dkUWmXv; Tue, 29 Dec 2020 01:07:17 +0100 (CET) Received: from function.youpi.perso.aquilenet.fr (lfbn-bor-1-56-204.w90-50.abo.wanadoo.fr [90.50.148.204]) by hera.aquilenet.fr (Postfix) with ESMTPSA id C630ED2; Tue, 29 Dec 2020 01:07:17 +0100 (CET) Received: from samy by function.youpi.perso.aquilenet.fr with local (Exim 4.94) (envelope-from ) id 1ku2Xl-003J6A-4C; Tue, 29 Dec 2020 01:07:17 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd, commited] hurd: Add WSTOPPED/WCONTINUED/WEXITED/WNOWAIT support [BZ #23091] Date: Tue, 29 Dec 2020 01:07:16 +0100 Message-Id: <20201229000716.788355-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.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" The new __proc_waitid RPC now expects WEXITED to be passed, allowing to properly implement waitid, and thus define the missing W* macros (according to FreeBSD values). --- bits/waitflags.h | 8 ++++++++ conform/data/sys/wait.h-data | 12 +++++------ sysdeps/mach/hurd/waitid.c | 40 +++++++++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/bits/waitflags.h b/bits/waitflags.h index a2f9646b22..82abdf7d50 100644 --- a/bits/waitflags.h +++ b/bits/waitflags.h @@ -24,3 +24,11 @@ /* Bits in the third argument to `waitpid'. */ #define WNOHANG 1 /* Don't block waiting. */ #define WUNTRACED 2 /* Report status of stopped children. */ + +/* Bits in the fourth argument to `waitid'. */ +#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 +# define WSTOPPED WUNTRACED /* Report stopped child. */ +# define WCONTINUED 4 /* Report continued child. */ +# define WNOWAIT 8 /* Don't reap, just poll status. */ +# define WEXITED 16 /* Report dead child. */ +#endif diff --git a/conform/data/sys/wait.h-data b/conform/data/sys/wait.h-data index c0761424da..a6713461ea 100644 --- a/conform/data/sys/wait.h-data +++ b/conform/data/sys/wait.h-data @@ -8,8 +8,7 @@ constant WUNTRACED macro WEXITSTATUS # if !defined XPG4 && !defined POSIX && !defined POSIX2008 -// Bug 23091: hurd: missing waitid support. -xfail[i386-gnu]-macro WIFCONTINUED +macro WIFCONTINUED # endif macro WIFEXITED macro WIFSIGNALED @@ -17,15 +16,14 @@ macro WIFSTOPPED macro WSTOPSIG macro WTERMSIG -// Bug 23091: hurd: missing waitid support. # if !defined XPG4 && !defined POSIX -xfail[i386-gnu]-constant WEXITED -xfail[i386-gnu]-constant WSTOPPED +constant WEXITED +constant WSTOPPED # ifndef POSIX2008 -xfail[i386-gnu]-constant WCONTINUED +constant WCONTINUED # endif constant WNOHANG -xfail[i386-gnu]-constant WNOWAIT +constant WNOWAIT # endif #if !defined XPG4 && !defined POSIX diff --git a/sysdeps/mach/hurd/waitid.c b/sysdeps/mach/hurd/waitid.c index 044a1dd8e3..eb5141e351 100644 --- a/sysdeps/mach/hurd/waitid.c +++ b/sysdeps/mach/hurd/waitid.c @@ -1,4 +1,4 @@ -/* Pseudo implementation of waitid. +/* Implementation of waitid. Hurd version. Copyright (C) 1997-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Zack Weinberg , 1997. @@ -18,14 +18,23 @@ . */ #include +#include #include #include +#include +#include +#include +#include int __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) { + struct rusage ignored; + error_t err; pid_t pid, child; + int sigcode; int status; + int cancel_oldtype; switch (idtype) { @@ -59,16 +68,19 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) return -1; } - /* Note the waitid() is a cancellation point. But since we call - waitpid() which itself is a cancellation point we do not have - to do anything here. */ - child = __waitpid (pid, &status, options); + cancel_oldtype = LIBC_CANCEL_ASYNC(); +#if HURD_INTERFACE_VERSION >= 20201227 + err = __USEPORT_CANCEL (PROC, __proc_waitid (port, pid, options, + &status, &sigcode, + &ignored, &child)); + if (err == MIG_BAD_ID || err == EOPNOTSUPP) +#endif + err = __USEPORT_CANCEL (PROC, __proc_wait (port, pid, options, + &status, &sigcode, + &ignored, &child)); + LIBC_CANCEL_RESET (cancel_oldtype); - if (child == -1) - /* `waitpid' set `errno' for us. */ - return -1; - - if (child == 0) + if (err == EAGAIN) { /* POSIX.1-2008, Technical Corrigendum 1 XSH/TC1-2008/0713 [153] states that if waitid returns because WNOHANG was specified and status is @@ -80,6 +92,9 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) return 0; } + if (err != 0) + return __hurd_fail (err); + /* Decode the status field and set infop members... */ infop->si_signo = SIGCHLD; infop->si_pid = child; @@ -100,6 +115,11 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) infop->si_code = CLD_STOPPED; infop->si_status = WSTOPSIG (status); } + else if (WIFCONTINUED (status)) + { + infop->si_code = CLD_CONTINUED; + infop->si_status = SIGCONT; + } return 0; }