Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zargs with -P intermittently failing in zsh 5.9 and macOS



On Thu, May 26, 2022 at 10:30 PM Jun T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
> When wait_for_processes() is called (in signal handler?), wait3(&state)
> _sometimes_ returns with WIFCONTINUED(status) set to true.
> Then wait_for_processes() calls addbgstatus(pid, val) with
> val=WEXITSTATUS(status)=19.
>
> Later the process exits normally, and addbgstatus(pid, 0) is called.
> This means bgstatus_list has two entries for the pid.
>
> When 'wait pid' calls getbgstatus(pid), it finds the entry with status=19
> and returns it.

Even if it's correct to have two entries, it's wrong to return the
least recent one.

> A simple fix would be, at line 584 of signals.c,
> (A) call addbgstatus() only if WIFCONTINUED() is not true.

I think that's insufficient ... we should be recording the most recent
state, per your question about WIFSTOPPED.

> So I guess we need to call addbgstatus() only if the process has actually
> exited (or killed). If this is the case, better solution would be
> (B) call addbgstatus() only if WIFEXITED() or WIFSIGNALED() is true.
> This it the patch below.

Does that really work?  I would expect WIFSIGNALED to be true when
each of WIFSTOPPED and WIFCONTINUED is also true, so it wouldn't
change anything?  (There isn't any way to stop/continue without using
a signal that I can think of.)

> Or, if we want to call addbgstatus() unconditionally,
> (C) modify addbgstatus() so that if there is already an entry for
> the pid then update it instead of adding a new entry.

I think either that, or

(D) Make sure getbgstatus() always returns the most recent entry.

But ... there isn't any way for a user / script to examine more than
one job status per PID, so unless we're using it internally somewhere
(?) I would think (C) is best.




Messages sorted by: Reverse Date, Date, Thread, Author