bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wait -n misses signaled subprocess


From: Oğuz
Subject: Re: wait -n misses signaled subprocess
Date: Wed, 24 Jan 2024 21:50:01 +0300

On Mon, Jan 22, 2024 at 8:13 PM Steven Pelley <stevenpelley@gmail.com> wrote:
>
> Hello,
> I've encountered what I believe is a bug in bash's "wait -n".  wait -n
> fails to return for processes that terminate due to a signal prior to
> calling wait -n.  Instead, it returns 127 with an error that the
> process id cannot be found.  Calling wait <pid> (without -n) then
> returns its exit code (e.g., 143).  I expect wait -n to return each
> process through successive calls to wait -n, which is the case for
> processes that terminate in other manners even prior to calling wait
> -n.

I agree that this is a bug in bash.
jobs.c/wait_for_any_jobs() marks all dead jobs as notified after
reporting the status of the first one and misses the rest. With the
following change (not a real fix, just for demonstration), devel
branch behaves as expected:

diff --git a/jobs.c b/jobs.c
index 3e68bf24..d7c8d11b 100644
--- a/jobs.c
+++ b/jobs.c
@@ -3257,7 +3257,7 @@ wait_for_any_job (int flags, struct procstat *ps)
     {
       if ((flags & JWAIT_WAITING) && jobs[i] && IS_WAITING (i) == 0)
        continue;               /* if we don't want it, skip it */
-      if (jobs[i] && DEADJOB (i) && IS_NOTIFIED (i) == 0 &&
IS_FOREGROUND (i) == 0)
+      if (jobs[i] && DEADJOB (i) && IS_FOREGROUND (i) == 0)
        {
 return_job:
          r = job_exit_status (i);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]