From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mta-snd-w07.mail.nifty.com (mta-snd-w07.mail.nifty.com [106.153.227.39]) by sourceware.org (Postfix) with ESMTPS id AA2223858D37 for ; Mon, 18 Mar 2024 04:58:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA2223858D37 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AA2223858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=106.153.227.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710737914; cv=none; b=ZvN3BgQPvAjhiSO++YPc+obT/6+d0fSyx+cktIblXkdqnevJfViIcVDHiqcxUsw29wyc3MGhuOWbDEPX089d9phOINSdmkFaEFiFS0b4ytmI9HRVOnHEZTLPAq0wDphrSkQ3iusMTTsre/gqvEW6rrS2/Ux0AsgCvYdaqaQs7xs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710737914; c=relaxed/simple; bh=Ged9r9DizXbPtLqh6xNwbFfVOgCs1u96J6QdEJFGqvw=; h=Date:From:To:Subject:Message-Id:Mime-Version; b=sERSuWi43FOqnJlW1EMFdbEaQchWB0MzwPAThbl1OsdNA7BMUXO46F233xqIFXPrA8jSsIH6n/k0fSUNs08D1xvNKC6FZBBnKQo5ZCHCJW4ZqIJBcP3ZW3R2KroyzQ7PNJ5nBlG9LB7WQNvSCDodzTfQ99oADu/spInSIVt+qrQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from HP-Z230 by dmta1007.nifty.com with ESMTP id <20240318045827809.DZLR.5813.HP-Z230@nifty.com> for ; Mon, 18 Mar 2024 13:58:27 +0900 Date: Mon, 18 Mar 2024 13:58:26 +0900 From: Takashi Yano To: cygwin@cygwin.com Subject: Re: Bogus exit code 127 from a child process Message-Id: <20240318135826.e4176868074e074eb3138cb5@nifty.ne.jp> In-Reply-To: <20240318120906.ccac3ad237a8f6c4c1b94c71@nifty.ne.jp> References: <20240317174402.4a3e73a7fca2f5978ac93913@nifty.ne.jp> <61d4fca73047915567fc9b4aac2860a3@ispras.ru> <20240317182757.84b41a596c344f395c1d8f9a@nifty.ne.jp> <20240317192116.b00f24c9ee065f16d6ac6673@nifty.ne.jp> <20240317210358.ad701873dc5cfc9a3026dc0c@nifty.ne.jp> <20240317211517.40cfbe0a664f7c7fe3d6e73d@nifty.ne.jp> <20240317213548.652be777a51f00108414d9bf@nifty.ne.jp> <8F45EC6F-A035-449B-89D0-065FAE3FC157@unified-streaming.com> <259F0ECF-9AE8-42E7-A746-8227F8B7870C@unified-streaming.com> <20240318120906.ccac3ad237a8f6c4c1b94c71@nifty.ne.jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 18 Mar 2024 12:09:06 +0900 Takashi Yano wrote: > On Sun, 17 Mar 2024 14:10:55 +0100 > Dimitry Andric wrote: > > On 17 Mar 2024, at 13:50, Dimitry Andric wrote: > > > > > > On 17 Mar 2024, at 13:35, Takashi Yano via Cygwin wrote: > > > ... > > >> > > >> I also test your test case: > > >> while bash -c 'true & true & wait -n || { echo 1: $?; exit 1; } && wait -n || { echo 2: $?; exit 1; }'; do echo $((i++)); done > > >> in Linux (Debian 12.5), and the issue reproduced! > > > > > > Yeah, same here with bash 5.1.16(1)-release on Ubuntu 22.04. It errors out with 127 after ~50-200 loops. > > > > Having built bash master (bash-5.2-27-gf3b6bd19) here, it consistently gives 127 in this area: > > > > https://git.savannah.gnu.org/cgit/bash.git/tree/builtins/wait.def#n227 > > > > 211 #if defined (JOB_CONTROL) > > 212 if (nflag) > > 213 { > > 214 if (list) > > 215 { > > 216 opt = set_waitlist (list); > > 217 if (opt == 0) > > 218 WAIT_RETURN (127); > > 219 wflags |= JWAIT_WAITING; > > 220 } > > 221 > > 222 status = wait_for_any_job (wflags, &pstat); > > 223 if (vname && status >= 0) > > 224 builtin_bind_var_to_int (vname, pstat.pid, bindflags); > > 225 > > 226 if (status < 0) > > => 227 status = 127; > > 228 if (list) > > 229 unset_waitlist (); > > 230 WAIT_RETURN (status); > > 231 } > > 232 #endif > > > > So for some reason, wait_for_any_job() returns a negative value in this particular situation. > > Line 218 looks also suspicious. Probably, this is not a bug. man bash says: If the -n option is supplied, wait waits for a single job from the list of ids or, if no ids are supplied, any job, to complete and returns its exit status. If none of the supplied arguments is a child of the shell, or if no arguments are supplied and the shell has no unwaited‐for children, the exit status is 127. If the background process exited before calling 'wait -n', it returns 127. This is very different from wait() system call, which is necessary for any background joubs, otherwise zombie remains. In the shell, it is not necessary to call wait command for background jobs, therefore exit status of the background job which already exited is not held anymore. So, actual bug is in the test case. -- Takashi Yano