Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Denys Vlasenko Newsgroups: gnu.bash.bug Subject: Re: "wait" loses signals Date: Mon, 24 Feb 2020 18:19:46 +0100 Lines: 22 Approved: bug-bash@gnu.org Message-ID: References: <750d460d-b8a4-4157-1488-9f4d9f973715@redhat.com> <35034c85-fd5a-5034-a2d5-e3903888069d@case.edu> <00620c20-19ea-e71e-dc1b-926847901f82@redhat.com> <25750.1582534783@jinx.noi.kre.to> <96ce0406-36fd-f93e-6ebc-49bd58b52148@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1582564798 15507 209.51.188.17 (24 Feb 2020 17:19:58 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Harald van Dijk , Daniel Colascione , bug-bash@gnu.org To: chet.ramey@case.edu, Robert Elz Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582564793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SUKASOV7+DiIT5lULOyaUG65zgrFlZNQUXdM56xWDH4=; b=Mnj69D1WYQo1QyObJW6qV9qoG3ZODScmi+QxYQUXzOBwfIV/haeZtTcyNwBomtKtLh4bnz PDT3H3UQQusNWiU/VKyXL6LtcuePq1jXYPpaBRfIAqHQTM/ZiD2GHlvIVWYIDaekOCnGgr +wxYKILdOPZpNfBMvxRcXuZ7lcKjhhw= X-MC-Unique: TGTXJvI2NXyWMcqTpVJuow-1 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 In-Reply-To: <96ce0406-36fd-f93e-6ebc-49bd58b52148@case.edu> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <750d460d-b8a4-4157-1488-9f4d9f973715@redhat.com> <35034c85-fd5a-5034-a2d5-e3903888069d@case.edu> <00620c20-19ea-e71e-dc1b-926847901f82@redhat.com> <25750.1582534783@jinx.noi.kre.to> <96ce0406-36fd-f93e-6ebc-49bd58b52148@case.edu> Xref: csiph.com gnu.bash.bug:15963 On 2/24/20 5:18 PM, Chet Ramey wrote: > The first case is trickier: there's always going to be a window between > the time the shell checks for pending traps and the time the wait builtin > starts to run. You can't really close it unless you're willing to run the > trap out of the signal handler, which everyone agrees is a bad idea, but > you can squeeze it down to practially nothing. dash uses something along these lines: sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, &mask); while (!pending_sig) sigsuspend(&mask); sigprocmask(SIG_SETMASK, &mask, NULL); if (pending_sig) handle_signals(pending_sig); pid = waitpid(... WNOHANG); It sleeps in sigsuspend(), not in waitpid(). This way we wait for both signals *and* children (by virtue of getting SIGCHLD for them).