From patchwork Sun Oct 22 20:51:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 23758 Received: (qmail 5404 invoked by alias); 22 Oct 2017 20:52:08 -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 5394 invoked by uid 89); 22 Oct 2017 20:52:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk0-f193.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=e0kem5fASr8Wp8h9EPDZK1Ct3vj4e0wdywWiCw94/rQ=; b=GB7Mazpf2CIz/cQTgBLk0U/CBC5YDi/PM/32ZzUw0OwE7fUOkdhpJyUU4bZKoMC8qn c+RN94dIpjxvwlsQ7HkjNIY+Niu/a8jqGbuN8OK6wCp0VQ7+R9CMmM62w0xyZvyDLX/H UAxNPI62KJwDVquH+N42epjqRLW8ZfiI7IbAd8st7rxcWvioxBd7c5OCnz7jWB1d4oRX ov+LYEzHFvJxhlnOI41OBhMPXY08lB0viiinAdyyL+3HHI3xHb9EYXBp7hUjeDyMJItv +KUPhy82VhxHy5wYZbtAKfzsQWhBdqnSSsnomfaccMl+kqPto8IVP5V39FQ4qekpJjri 7kfw== X-Gm-Message-State: AMCzsaXGq7AS6JW1ARxLvuLxsJyWTQ9PkicWZuSZEzmY2ENlnM+BNobm WXoXjry+zbqtGxHxVsXADUIOjuouS2U= X-Google-Smtp-Source: ABhQp+TxP6nmz2cp4EfeVVNcZPCVXMpkMpekj43LhNLVPWTdgdgeanwPWItQdYsc+bCenJKTtA6Z9g== X-Received: by 10.233.222.135 with SMTP id s129mr15768023qkf.261.1508705524419; Sun, 22 Oct 2017 13:52:04 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] posix: Do not use WNOHANG in waitpid call for Linux posix_spawn Date: Sun, 22 Oct 2017 18:51:57 -0200 Message-Id: <1508705517-31558-1-git-send-email-adhemerval.zanella@linaro.org> As shown in some buildbot issues on aarch64 and powerpc, calling clone (VFORK) and waitpid (WNOHANG) does not guarantee the child is ready to be collected. This patch changes the call back to 0 as before fe05e1cb6d64 fix. This change can lead to the scenario 4.3 described in the commit, where the waitpid call can hang undefinitely on the call. However this is also a very unlikely and also undefinied situation where both the caller is trying to terminate a pid before posix_spawn returns and the race pid reuse is triggered. I don't see how to correct handle this specific situation within posix_spawn. Checked on x86_64-linux-gnu, aarch64-linux-gnu and powerpc64-linux-gnu. * sysdeps/unix/sysv/linux/spawni.c (__spawnix): Use 0 instead of WNOHANG in waitpid call. --- ChangeLog | 5 +++++ sysdeps/unix/sysv/linux/spawni.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index d15fbb1..fb83c2e 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -374,12 +374,12 @@ __spawnix (pid_t * pid, const char *file, ec = args.err; if (ec > 0) /* There still an unlikely case where the child is cancelled after - setting args.err, due to a positive error value. Also due a + setting args.err, due to a positive error value. Also there is possible pid reuse race (where the kernel allocated the same pid - to unrelated process) we need not to undefinitely hang expecting - an invalid pid. In both cases an error is returned to the - caller. */ - __waitpid (new_pid, NULL, WNOHANG); + to an unrelated process). Unfortunately due synchronization + issues where the kernel might not have the process collected + the waitpid below can not use WNOHANG. */ + __waitpid (new_pid, NULL, 0); } else ec = -new_pid;