zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Bart Schaefer <schaefer@brasslantern.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Crash on jobstates since workers/49783 (commit 6a8aa2a)
Date: Mon, 28 Mar 2022 09:47:17 +0100 (BST)	[thread overview]
Message-ID: <1409134730.698961.1648457237653@mail2.virginmedia.com> (raw)
In-Reply-To: <CAH+w=7YyuhyAkCyRE9=f-ybLpPzMqfND=y1S=Ai_jS97Sq6J-g@mail.gmail.com>

> On 27 March 2022 at 06:34 Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Fri, Mar 25, 2022 at 3:32 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> >
> > The nested calls to zargs from runN all die with a SEGV on when running:
> >
> > wait ${${jobstates[(R)running:*]/#*:/}/%=*/}
> 
> Minimal reproducer:
> 
> % sleep 5 &
> [1] 171363
> % ( wait ${${jobstates[(R)running:*]/#*:/}/%=*/} )
> zsh: segmentation fault (core dumped)  ( wait
> ${${jobstates[(R)running:*]/#*:/}/%=*/}; )
> %

$jobstates was still looking at the process structures which doesn't
work in the subshell.  Previously, it didn't even look at the 
main job state in a subshell.   Obviously, the subshell doesn't know
the up-to-date state anyway, and can't actually manipulate it.
So probably the best we can do is report the last we knew about the
job state and ignore the process structures.  This probably warrants
a bit of documentation.

The code now reports "wait: can't manipulate jobs in subshell",
which I believe is a correct statement of affairs.

pws

diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo
index 2e3011e44..28c19f797 100644
--- a/Doc/Zsh/mod_parameter.yo
+++ b/Doc/Zsh/mod_parameter.yo
@@ -189,6 +189,10 @@ the var(state) describes the state of that process.
 
 Handling of the keys of the associative array is as described for
 tt(jobdirs) above.
+
+This parameter is available in a subshell, but only shows overall job
+information, not process information.  The information is current at the
+point the subshell forks from the parent shell.
 )
 vindex(nameddirs)
 item(tt(nameddirs))(
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index dbb61e474..2692766eb 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -1348,6 +1348,15 @@ pmjobstate(Job jtab, int job)
     else
 	ret = dyncat("running", cp);
 
+    if (jtab != jobtab)
+    {
+	/*
+	 * This is a saved job table so doesn't have current
+	 * process information --- bail out now.
+	 */
+	return ret;
+    }
+
     for (pn = jtab[job].procs; pn; pn = pn->next) {
 
 	if (pn->status == SP_RUNNING)


  reply	other threads:[~2022-03-28  8:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 22:32 Bart Schaefer
2022-03-27  5:34 ` Bart Schaefer
2022-03-28  8:47   ` Peter Stephenson [this message]
2022-03-28 14:49     ` Peter Stephenson
2022-03-28 15:09       ` Bart Schaefer
2022-03-28 16:14         ` Peter Stephenson
2022-03-28 16:44           ` Bart Schaefer
2022-03-28 19:52             ` Peter Stephenson
2022-03-29  3:49               ` Bart Schaefer
2022-03-29  9:08                 ` Peter Stephenson
2022-03-29 13:31                   ` Peter Stephenson
2022-03-29 15:39                     ` Bart Schaefer
2022-03-29 15:36                   ` Bart Schaefer
2022-03-29 15:41                     ` Peter Stephenson
2022-03-28 15:13     ` Bart Schaefer

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=1409134730.698961.1648457237653@mail2.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=schaefer@brasslantern.com \
    --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).