summaryrefslogtreecommitdiff
path: root/Src/signals.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/signals.c')
-rw-r--r--Src/signals.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/Src/signals.c b/Src/signals.c
index 94f379e72..20c6fdf4a 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -537,6 +537,21 @@ wait_for_processes(void)
#else
update_process(pn, status);
#endif
+ if (WIFEXITED(status) &&
+ pn->pid == jn->gleader &&
+ killpg(pn->pid, 0) == -1) {
+ jn->gleader = 0;
+ if (!(jn->stat & STAT_NOSTTY)) {
+ /*
+ * This PID was in control of the terminal;
+ * reclaim terminal now it has exited.
+ * It's still possible some future forked
+ * process of this job will become group
+ * leader, however.
+ */
+ attachtty(mypgrp);
+ }
+ }
}
update_job(jn);
} else if (findproc(pid, &jn, &pn, 1)) {
@@ -573,7 +588,7 @@ wait_for_processes(void)
/* the signal handler */
/**/
-mod_export RETSIGTYPE
+mod_export void
zhandler(int sig)
{
sigset_t newmask, oldmask;
@@ -778,9 +793,21 @@ killjb(Job jn, int sig)
else
return killpg(jn->gleader, sig);
}
- for (pn = jn->procs; pn; pn = pn->next)
- if ((err = kill(pn->pid, sig)) == -1 && errno != ESRCH && sig != 0)
- return -1;
+ for (pn = jn->procs; pn; pn = pn->next) {
+ /*
+ * Do not kill this job's process if it's already dead as its
+ * pid could have been reused by the system.
+ * As the PID doesn't exist don't return an error.
+ */
+ if (pn->status == SP_RUNNING || WIFSTOPPED(pn->status)) {
+ /*
+ * kill -0 on a job is pointless. We still call kill() for each process
+ * in case the user cares about it but we ignore its outcome.
+ */
+ if ((err = kill(pn->pid, sig)) == -1 && errno != ESRCH && sig != 0)
+ return -1;
+ }
+ }
return err;
}