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: Mon, 27 Apr 2015 18:29:40 +0100	[thread overview]
Message-ID: <20150427182940.37b7c6bf@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <150424092130.ZM29016@torch.brasslantern.com>

On Fri, 24 Apr 2015 09:21:30 -0700
Bart Schaefer <schaefer@brasslantern.com> 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;


  reply	other threads:[~2015-04-27 17:29 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
2015-04-24 15:43           ` Peter Stephenson
2015-04-24 16:21           ` Bart Schaefer
2015-04-27 17:29             ` Peter Stephenson [this message]
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=20150427182940.37b7c6bf@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).