zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Re: Using "source" in a function breaks job control
Date: Fri, 24 Apr 2015 16:25:42 +0100	[thread overview]
Message-ID: <20150424162542.2efb36a3@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CAH+w=7bHO7Y+9tZg7tgjVkAPkKtbMHnRSCTDtQ4vrttL2NdgOg@mail.gmail.com>

On Thu, 23 Apr 2015 23:22:55 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Thu, Apr 23, 2015 at 1:13 PM, Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> > On Wed, 22 Apr 2015 21:55:39 -0700
> > Bart Schaefer <schaefer@brasslantern.com> wrote:
> >> It has something to do with tracking the job table.
> >
> > Looks like we lost STAT_SUPERJOB in the flags of the job that got
> > created when we forked.
> 
> That was the needed clue.  The problem is that list_pipe_job is wrong
> following the return from source().  The complications are that (1)
> list_pipe_job is static to exec.c whereas source() is in init.c, and
> (2) when I tried exporting list_pipe_job so it could be saved/restored
> in source(), it fixed this issue but caused the test for "status of
> recently exited background jobs is recorded" to fail (which confuses
> me, because I can't see any reason source() would get involved in that
> test).

The variable needs adding to the set in execlist(). I tried a few
similarly named variables last night but not that one.

Apparently a few more verses need adding to the Nibelungenlied.

 *   Allen Edeln gebiet ich Andacht,
 *   Hohen und Niedern von Heimdalls Geschlecht;
 *   Ich will list_pipe's Wirken kuenden
 *   Die aeltesten Sagen, der ich mich entsinne...

> Perhaps source() should be using execsave()/execrestore() instead of
> the stack of local copies of the job state globals that it maintains?

It's possible --- the current split between source() and execlist() is
certainly icky --- though I'm not sure whether or not source() needs to
be as boxed in as eval and similar or if it'll create subtle problems.
(Actually, if it didn't, it would be a new record.)

pws

diff --git a/Src/exec.c b/Src/exec.c
index 2a8185c..60b79c6 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1146,7 +1146,7 @@ execlist(Estate state, int dont_change_job, int exiting)
     Wordcode next;
     wordcode code;
     int ret, cj, csp, ltype;
-    int old_pline_level, old_list_pipe;
+    int old_pline_level, old_list_pipe, old_list_pipe_job;
     zlong oldlineno;
     /*
      * ERREXIT only forces the shell to exit if the last command in a &&
@@ -1159,10 +1159,11 @@ execlist(Estate state, int dont_change_job, int exiting)
     cj = thisjob;
     old_pline_level = pline_level;
     old_list_pipe = list_pipe;
+    old_list_pipe_job = list_pipe_job;
     oldlineno = lineno;
 
     if (sourcelevel && unset(SHINSTDIN))
-	pline_level = list_pipe = 0;
+	pline_level = list_pipe = list_pipe_job = 0;
 
     /* Loop over all sets of comands separated by newline, *
      * semi-colon or ampersand (`sublists').               */
@@ -1397,6 +1398,7 @@ sublist_done:
     }
     pline_level = old_pline_level;
     list_pipe = old_list_pipe;
+    list_pipe_job = old_list_pipe_job;
     lineno = oldlineno;
     if (dont_change_job)
 	thisjob = cj;


  reply	other threads:[~2015-04-24 15:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-22 18:11 Daniel Hahler
2015-04-22 20:41 ` Peter Stephenson
2015-04-22 21:26 ` Peter Stephenson
2015-04-23  4:55   ` Bart Schaefer
2015-04-23 20:13     ` Peter Stephenson
2015-04-24  6:22       ` Bart Schaefer
2015-04-24 15:25         ` Peter Stephenson [this message]
2015-04-24 15:43           ` Peter Stephenson
2015-04-24 16:21           ` Bart Schaefer
2015-04-27 17:29             ` Peter Stephenson
2015-04-28 10:18             ` Peter Stephenson
2015-04-28 15:57               ` 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=20150424162542.2efb36a3@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).