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

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



On Fri, 24 Apr 2015 09:21:30 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Apr 24,  4:25pm, Peter Stephenson wrote:
> }
> } Apparently a few more verses need adding to the [Elder Edda].
> 
> Indeed, now we just have to figure these two out:
> 
> torch% vi() { source =(<<<false); vim -u NONE -N; print "vim exited $?" }
> torch% vi
> zsh: suspended  
> 
> Note we don't have the jobtext there.  If there's no "source" then we
> get the correct jobtext ("suspended  vi").  There may be one more global
> not getting the right treatment in execlist()?  The jobtext as displayed
> there comes from the loop over jn->procs in printjob().  Perhaps the
> remaining issue is that list_pipe_job isn't restored soon enough.

list_pipe_text needs handling.  It's a fxied 80-character array, but I
don't see why we can't just allocate it as needed and free it after.

It would be better to move the save and restore out of execlist(), but I
don't dare do that --- apart from traps, nothing else is currently
saving and restoring list_pipe's Wirken properly.  So this would impact
functions and a lot else.

This doesn't fix the exit status.

pws

diff --git a/Src/exec.c b/Src/exec.c
index 60b79c6..31c80a7 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1147,6 +1147,7 @@ execlist(Estate state, int dont_change_job, int exiting)
     wordcode code;
     int ret, cj, csp, ltype;
     int old_pline_level, old_list_pipe, old_list_pipe_job;
+    char *old_list_pipe_text;
     zlong oldlineno;
     /*
      * ERREXIT only forces the shell to exit if the last command in a &&
@@ -1160,10 +1161,16 @@ execlist(Estate state, int dont_change_job, int exiting)
     old_pline_level = pline_level;
     old_list_pipe = list_pipe;
     old_list_pipe_job = list_pipe_job;
+    if (*list_pipe_text)
+	old_list_pipe_text = ztrdup(list_pipe_text);
+    else
+	old_list_pipe_text = NULL;
     oldlineno = lineno;
 
-    if (sourcelevel && unset(SHINSTDIN))
+    if (sourcelevel && unset(SHINSTDIN)) {
 	pline_level = list_pipe = list_pipe_job = 0;
+	*list_pipe_text = '\0';
+    }
 
     /* Loop over all sets of comands separated by newline, *
      * semi-colon or ampersand (`sublists').               */
@@ -1399,6 +1406,12 @@ sublist_done:
     pline_level = old_pline_level;
     list_pipe = old_list_pipe;
     list_pipe_job = old_list_pipe_job;
+    if (old_list_pipe_text) {
+	strcpy(list_pipe_text, old_list_pipe_text);
+	zsfree(old_list_pipe_text);
+    } else {
+	*list_pipe_text = '\0';
+    }
     lineno = oldlineno;
     if (dont_change_job)
 	thisjob = cj;



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