From patchwork Tue Jun 2 13:46:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 11583875 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52E161391 for ; Tue, 2 Jun 2020 13:46:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3BE08207D8 for ; Tue, 2 Jun 2020 13:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725958AbgFBNqv (ORCPT ); Tue, 2 Jun 2020 09:46:51 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:56392 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbgFBNqv (ORCPT ); Tue, 2 Jun 2020 09:46:51 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1jg7Fg-0000Se-CB; Tue, 02 Jun 2020 23:46:49 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Tue, 02 Jun 2020 23:46:48 +1000 Date: Tue, 2 Jun 2020 23:46:48 +1000 From: Herbert Xu To: dash@vger.kernel.org Subject: [PATCH] jobs: Fix waitcmd busy loop Message-ID: <20200602134648.GA17275@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org We need to clear gotsigchld in waitproc because it is used as a loop conditional for the waitcmd case. Without it waitcmd may busy loop after a SIGCHLD. This patch also changes gotsigchld into a volatile sig_atomic_t to prevent compilers from optimising its accesses away. Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...") Signed-off-by: Herbert Xu diff --git a/src/jobs.c b/src/jobs.c index 94bf47e..3417633 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -1135,7 +1135,6 @@ static int dowait(int block, struct job *jp) rpid = 1; do { - gotsigchld = 0; pid = waitone(block, jp); rpid &= !!pid; @@ -1175,6 +1174,7 @@ waitproc(int block, int *status) #endif do { + gotsigchld = 0; do err = wait3(status, flags, NULL); while (err < 0 && errno == EINTR); diff --git a/src/trap.c b/src/trap.c index 82e7ece..cd84814 100644 --- a/src/trap.c +++ b/src/trap.c @@ -76,7 +76,7 @@ static char gotsig[NSIG - 1]; /* last pending signal */ volatile sig_atomic_t pending_sig; /* received SIGCHLD */ -int gotsigchld; +volatile sig_atomic_t gotsigchld; extern char *signal_names[]; diff --git a/src/trap.h b/src/trap.h index 4c455a8..beaf660 100644 --- a/src/trap.h +++ b/src/trap.h @@ -39,7 +39,7 @@ extern int trapcnt; extern char sigmode[]; extern volatile sig_atomic_t pending_sig; -extern int gotsigchld; +extern volatile sig_atomic_t gotsigchld; int trapcmd(int, char **); void setsignal(int);