www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2024/03/18/00:59:26

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 763203858C5F
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1710737963;
bh=yll+jAult85bQ+/GBuepaHwKawwLXI30AL37E/UROMw=;
h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=KYElznE2IDGCdQqGMDvo4lOrL/63m5X2s2bj5685LB0FgptrQld5qgEVK6d+wtgUy
N27KD/YwujZq7RQnStAei227E8kr7T/ORu1l3uxHRQzCTt0AoBjHHtouKDR56klfzK
tSwg3cNTmmlt+FdX1fixlu1TMmFbguFhmxVT8EAY=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA2223858D37
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AA2223858D37
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
Date: Mon, 18 Mar 2024 13:58:26 +0900
To: cygwin AT cygwin DOT 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: <d5c90ec69060cea65c9eb31492a655ac AT ispras DOT ru>
<20240317174402 DOT 4a3e73a7fca2f5978ac93913 AT nifty DOT ne DOT jp>
<61d4fca73047915567fc9b4aac2860a3 AT ispras DOT ru>
<20240317182757 DOT 84b41a596c344f395c1d8f9a AT nifty DOT ne DOT jp>
<c587acce90e624992471b392c1f0e171 AT ispras DOT ru>
<20240317192116 DOT b00f24c9ee065f16d6ac6673 AT nifty DOT ne DOT jp>
<20240317210358 DOT ad701873dc5cfc9a3026dc0c AT nifty DOT ne DOT jp>
<20240317211517 DOT 40cfbe0a664f7c7fe3d6e73d AT nifty DOT ne DOT jp>
<20240317213548 DOT 652be777a51f00108414d9bf AT nifty DOT ne DOT jp>
<8F45EC6F-A035-449B-89D0-065FAE3FC157 AT unified-streaming DOT com>
<259F0ECF-9AE8-42E7-A746-8227F8B7870C AT unified-streaming DOT com>
<20240318120906 DOT ccac3ad237a8f6c4c1b94c71 AT nifty DOT ne DOT jp>
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Mime-Version: 1.0
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
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Takashi Yano via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

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 <dimitry AT unified-streaming DOT com> wrote:
> > > 
> > > On 17 Mar 2024, at 13:35, Takashi Yano via Cygwin <cygwin AT cygwin DOT com> 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$B!>(Bfor 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 <takashi DOT yano AT nifty DOT ne DOT jp>

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019