From 9958684574bf8b0ecec6983cca57f3fa3dd7cd63 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 9 Aug 2015 00:50:36 -0700 Subject: 36022 fix bug that some loop constructs could not be interrupted, revise signal queueing There are two underlying ideas here: (1) Keeping signals queued around anything that's doing memory management (including push/pop of the heap) has become crucial. (2) Anytime the shell is going to run a command, be it buitin or external, it must be both safe and necessary to process any queued signals, so that the apparent order of signal arrival and command execution is preserved. --- Src/signals.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Src/signals.c') diff --git a/Src/signals.c b/Src/signals.c index 3950ad1a2..697c4c5ec 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -1207,6 +1207,8 @@ dotrapargs(int sig, int *sigtr, void *sigfn) } } + queue_signals(); /* Any time we manage memory or global state */ + intrap++; *sigtr |= ZSIG_IGNORED; @@ -1244,7 +1246,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn) sfcontext = SFC_SIGNAL; incompfunc = 0; - doshfunc((Shfunc)sigfn, args, 1); + doshfunc((Shfunc)sigfn, args, 1); /* manages signal queueing */ sfcontext = osc; incompfunc= old_incompfunc; freelinklist(args, (FreeFunc) NULL); @@ -1254,7 +1256,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn) trap_state = TRAP_STATE_PRIMED; trapisfunc = isfunc = 0; - execode((Eprog)sigfn, 1, 0, "trap"); + execode((Eprog)sigfn, 1, 0, "trap"); /* manages signal queueing */ } runhookdef(AFTERTRAPHOOK, NULL); @@ -1321,6 +1323,8 @@ dotrapargs(int sig, int *sigtr, void *sigfn) if (*sigtr != ZSIG_IGNORED) *sigtr &= ~ZSIG_IGNORED; intrap--; + + unqueue_signals(); } /* Standard call to execute a trap for a given signal. */ -- cgit v1.2.3 From a07f74fadd1180b42258d1fcec5359afe3f9ba00 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 10 Aug 2015 16:59:55 +0100 Subject: Don't rely on implicit value when saving background process status --- ChangeLog | 5 +++++ Src/signals.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'Src/signals.c') diff --git a/ChangeLog b/ChangeLog index f4eac9192..5390fef13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-10 Peter Stephenson + + * 36074: Src/signals.c: Don't rely on implicit value for + saving status of background process. + 2015-08-10 Frank Terbeck * 36046: Completion/Unix/Command/_tmux: _tmux: Update command line diff --git a/Src/signals.c b/Src/signals.c index 697c4c5ec..78dc75b1b 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -528,8 +528,14 @@ wait_for_processes(void) * and is not equal to the current foreground job. */ if (jn && !(jn->stat & (STAT_CURSH|STAT_BUILTIN)) && - jn - jobtab != thisjob) - addbgstatus(pid, (int)lastval2); + jn - jobtab != thisjob) { + int val = (WIFSIGNALED(status) ? + 0200 | WTERMSIG(status) : + (WIFSTOPPED(status) ? + 0200 | WEXITSTATUS(status) : + WEXITSTATUS(status))); + addbgstatus(pid, val); + } } } -- cgit v1.2.3 From 93ca77f8f73bc58041bcbf8e4319b056504806e5 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Mon, 10 Aug 2015 12:54:05 -0700 Subject: 36079: do not allow update_job() and its helpers to run the signal queue while we are processing a job exit. --- ChangeLog | 5 +++++ Src/signals.c | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'Src/signals.c') diff --git a/ChangeLog b/ChangeLog index 103e7a5d5..472551069 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-10 Barton E. Schaefer + + * 36079: Src/signals.c: do not allow update_job() and its helpers + to run the signal queue while we are processing a job exit. + 2015-08-10 Peter Stephenson * 36083: Src/builtin.c, Test/B02typeset.ztst: set array value diff --git a/Src/signals.c b/Src/signals.c index 78dc75b1b..f45c1860c 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -487,6 +487,12 @@ wait_for_processes(void) break; } + /* This is necessary to be sure queueing_enabled > 0 when + * we enter printjob() from update_job(), so that we don't + * decrement to zero in should_report_time() and improperly + * run other handlers in the middle of processing this one */ + queue_signals(); + /* * Find the process and job containing this pid and * update it. @@ -536,6 +542,8 @@ wait_for_processes(void) WEXITSTATUS(status))); addbgstatus(pid, val); } + + unqueue_signals(); } } -- cgit v1.2.3