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

Re: Using "source" in a function breaks job control



On Thu, 23 Apr 2015 23:22:55 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Thu, Apr 23, 2015 at 1:13 PM, Peter Stephenson
> <p.w.stephenson@xxxxxxxxxxxx> wrote:
> > On Wed, 22 Apr 2015 21:55:39 -0700
> > Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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;



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