From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25747 invoked by alias); 27 Apr 2015 17:29:49 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34979 Received: (qmail 24081 invoked from network); 27 Apr 2015 17:29:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-f794b6d000001495-68-553e720b3586 Date: Mon, 27 Apr 2015 18:29:40 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: Using "source" in a function breaks job control Message-id: <20150427182940.37b7c6bf@pwslap01u.europe.root.pri> In-reply-to: <150424092130.ZM29016@torch.brasslantern.com> References: <5537E450.9060205@thequod.de> <20150422222627.1f6154e9@ntlworld.com> <150422215539.ZM14251@torch.brasslantern.com> <20150423211331.5ea4baf0@ntlworld.com> <20150424162542.2efb36a3@pwslap01u.europe.root.pri> <150424092130.ZM29016@torch.brasslantern.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCLMWRmVeSWpSXmKPExsVy+t/xy7rcRXahBo3b9C0ONj9kcmD0WHXw A1MAYxSXTUpqTmZZapG+XQJXxqd/LcwFZ0Uqtu3awtzA+Jm/i5GTQ0LARKKp6TcLhC0mceHe erYuRi4OIYGljBINM1+wQDgzmCR2Xf3HDOFsY5T4+m0WK0gLi4CqxLSHP5lBbDYBQ4mpm2Yz djFycIgIaEu0fxQDCQsL2EhsuvWSDcTmFbCX2Lf0Ctg2TgEriesfXkBtu8EksenLDEaQBL+A vsTVv5+YIE6yl5h55QwjRLOgxI/J98CamQW0JDZva2KFsOUlNq95C3aDkIC6xI27u9knMArN QtIyC0nLLCQtCxiZVzGKppYmFxQnpeca6RUn5haX5qXrJefnbmKEhO3XHYxLj1kdYhTgYFTi 4VWYYRsqxJpYVlyZe4hRgoNZSYR3cqZdqBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHembvehwgJ pCeWpGanphakFsFkmTg4pRoY+XJeXNgbr148z0iKMX3OzYB4vo+zbBWztXZq24T1GDj1sm1N Y+D7ue1uVIb4E/vqddv/zTperxB80G3JmTjR2S33SxlvSEep94hb37757ohy5eysFS9KfnhY li07rm/zddeFzNZHx0SiU0O+OBhzu/ZcmKmU5vtiQdfdC4WhZfEKVtxabQ+UWIozEg21mIuK EwFsZkpFVwIAAA== On Fri, 24 Apr 2015 09:21:30 -0700 Bart Schaefer 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 =(<< 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;