From: "Jun. T" <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: zargs with -P intermittently failing in zsh 5.9 and macOS
Date: Sun, 29 May 2022 23:47:19 +0900 [thread overview]
Message-ID: <758F3522-3613-435C-B2F6-3FC62220933B@kba.biglobe.ne.jp> (raw)
In-Reply-To: <CAH+w=7YSv=XsM-aFX7D9UYAs_Og9ep07k8kj3kAc883RKTMwqQ@mail.gmail.com>
> 2022/05/29 12:30, Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> OK. However, reading through your patch again ... the changed code
> kept track of stopped jobs. Has that never been necessary? Perhaps
> the right thing to do is to continue recording the state on WIFSTOPPED
> but to change to clearing the saved status on WIFCONTINUED?
If I understand correctly, {add,get}bgstatus() exists only for the wait
builtin. The only thing that needs be recored in bgstatus_list is the
exist status (including killed by a signal) of the process. Status of a
running/stopped process is kept elsewhere (jobtab[].procs).
Below is the patch including both B (signals.c) and C (jobs.c).
singnals.s is as the previous patch, but the ternary operator is
replaced by if/else.
diff --git a/Src/jobs.c b/Src/jobs.c
index a91ef787f..a8d6aeded 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -2221,6 +2221,7 @@ addbgstatus(pid_t pid, int status)
{
static long child_max;
Bgstatus bgstatus_entry;
+ LinkNode node;
if (!child_max) {
#ifdef _SC_CHILD_MAX
@@ -2244,6 +2245,18 @@ addbgstatus(pid_t pid, int status)
if (!bgstatus_list)
return;
}
+ /* See if an entry already exists for the pid */
+ for (node = firstnode(bgstatus_list); node; incnode(node)) {
+ bgstatus_entry = (Bgstatus)getdata(node);
+ if (bgstatus_entry->pid == pid) {
+ /* In theory this should not happen because addbgstatus() is
+ * called only once when the process exits or gets killed. */
+ DPUTS(1, "addbgstatus is called more than once");
+ bgstatus_entry->status = status;
+ return;
+ }
+ }
+ /* Add an entry for the pid */
if (bgstatus_count == child_max) {
/* Overflow. List is in order, remove first */
rembgstatus(firstnode(bgstatus_list));
diff --git a/Src/signals.c b/Src/signals.c
index 5c787e2a8..a61368554 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -576,12 +576,10 @@ wait_for_processes(void)
*/
if (jn && !(jn->stat & (STAT_CURSH|STAT_BUILTIN)) &&
jn - jobtab != thisjob) {
- int val = (WIFSIGNALED(status) ?
- 0200 | WTERMSIG(status) :
- (WIFSTOPPED(status) ?
- 0200 | WEXITSTATUS(status) :
- WEXITSTATUS(status)));
- addbgstatus(pid, val);
+ if (WIFEXITED(status))
+ addbgstatus(pid, WEXITSTATUS(status));
+ else if (WIFSIGNALED(status))
+ addbgstatus(pid, 0200 | WTERMSIG(status));
}
unqueue_signals();
next prev parent reply other threads:[~2022-05-29 14:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-24 16:09 Eric Nielsen
2022-05-24 17:32 ` Bart Schaefer
2022-05-24 20:21 ` Eric Nielsen
2022-05-24 20:35 ` Bart Schaefer
2022-05-26 8:57 ` Jun T
2022-05-26 11:21 ` Jun. T
2022-05-27 3:39 ` Bart Schaefer
2022-05-27 4:18 ` Lawrence Velázquez
2022-05-27 5:29 ` Jun T
2022-05-27 16:10 ` Bart Schaefer
2022-05-27 17:25 ` Jun. T
2022-05-29 3:30 ` Bart Schaefer
2022-05-29 14:47 ` Jun. T [this message]
2022-05-29 20:07 ` Bart Schaefer
2022-05-30 11:16 ` Jun T
2022-06-07 6:51 ` Jun T
2022-06-09 2:56 ` Bart Schaefer
2022-06-12 16:43 ` Eric Nielsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=758F3522-3613-435C-B2F6-3FC62220933B@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).