From 3c74891fcd68d37c1629943f703ac70428e3ce9f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 13 Apr 2018 12:09:34 +0100 Subject: 42630: Improve process group handling in pipelines. If process group leader exits, allow a newly forked process to become process leader. If a foreground job, reattach the shell to the terminal until that happens. Unblock signals when reading output for command subsitution so that we can do this reattaching immediately. --- Src/signals.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Src/signals.c') diff --git a/Src/signals.c b/Src/signals.c index 94f379e72..2a6aa3f24 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -537,6 +537,19 @@ wait_for_processes(void) #else update_process(pn, status); #endif + if (pn->pid == jn->gleader) { + 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)) { -- cgit v1.2.3 From 0f29b5148e6157d9bfc1ead9fdae67137358e541 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 19 Apr 2018 13:58:10 +0100 Subject: 42686: Fix previous pgrp patch. We shouldn't do any fix ups unless the process has actually exited. --- ChangeLog | 5 +++++ Src/signals.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'Src/signals.c') diff --git a/ChangeLog b/ChangeLog index c5fe925dd..41b993bfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-04-19 Peter Stephenson + + * 42686: Src/signals.c: Fix 42630 only to change process groups + on exited process. + 2018-04-17 Peter Stephenson * 42630: Src/exec.c, Src/signals.c: Improve process group diff --git a/Src/signals.c b/Src/signals.c index 2a6aa3f24..6e1215875 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -537,7 +537,8 @@ wait_for_processes(void) #else update_process(pn, status); #endif - if (pn->pid == jn->gleader) { + if (WIFEXITED(status) && + pn->pid == jn->gleader) { jn->gleader = 0; if (!(jn->stat & STAT_NOSTTY)) { /* -- cgit v1.2.3 From 9ad9c5cda1087151c64074a965a68b407a8bd229 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 23 Apr 2018 15:11:34 +0100 Subject: 42705: Another safety fix for pgrp reclaiming. Only do this if killpg(dead_pid, 0) returns -1, indicating the pgprp doesn't exist any more, else there is a race if other proceses have started using it. --- ChangeLog | 3 +++ Src/signals.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Src/signals.c') diff --git a/ChangeLog b/ChangeLog index 5bcdf2d4e..632a35717 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2018-04-23 Peter Stephenson + * 42705: Src/signals.c: another fix for 42630 --- also check + that killpg(pgrp, 0) is -1. + * 23362: Src/parse.c: Allow short loops with "while". 2018-04-20 Peter Stephenson diff --git a/Src/signals.c b/Src/signals.c index 6e1215875..f2165c005 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -538,7 +538,8 @@ wait_for_processes(void) update_process(pn, status); #endif if (WIFEXITED(status) && - pn->pid == jn->gleader) { + pn->pid == jn->gleader && + killpg(pn->pid, 0) == -1) { jn->gleader = 0; if (!(jn->stat & STAT_NOSTTY)) { /* -- cgit v1.2.3 From 449f13a46738ff303e41a8fcad1df850cae721fd Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 14 May 2018 16:47:29 +0100 Subject: 42234: Stephane: don't kill a process if not running. This could happen when kiiling a job. The processs might be reused. --- Src/signals.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'Src/signals.c') diff --git a/Src/signals.c b/Src/signals.c index f2165c005..4958534e2 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -793,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; } -- cgit v1.2.3 From f311619e30862406022d6e2ddb304eebf34f7868 Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Sat, 16 Jun 2018 01:04:26 +0000 Subject: 433029: Testing signal return type is no longer needed --- ChangeLog | 6 ++++++ Src/Modules/zftp.c | 2 +- Src/signals.c | 2 +- Src/signals.h | 2 +- configure.ac | 12 ------------ 5 files changed, 9 insertions(+), 15 deletions(-) (limited to 'Src/signals.c') diff --git a/ChangeLog b/ChangeLog index ede97e7c4..91bd039a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-06-18 Peter Stephenson + + * Eitan: 43029: Src/Modules/zftp.c, Src/signals.c, Src/signals.h, + configure.ac: remove test for signal handler return type as no + longer needed. + 2018-06-18 Oliver Kiddle * 43006: Tim Smith: Completion/Unix/Command/_git: complete diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c index 24f4b4200..4aaa1f072 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -362,7 +362,7 @@ static jmp_buf zfalrmbuf; /* The signal handler itself */ /**/ -static RETSIGTYPE +static void zfhandler(int sig) { if (sig == SIGALRM) { diff --git a/Src/signals.c b/Src/signals.c index 4958534e2..20c6fdf4a 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -588,7 +588,7 @@ wait_for_processes(void) /* the signal handler */ /**/ -mod_export RETSIGTYPE +mod_export void zhandler(int sig) { sigset_t newmask, oldmask; diff --git a/Src/signals.h b/Src/signals.h index 1904f4326..41ac88cce 100644 --- a/Src/signals.h +++ b/Src/signals.h @@ -27,7 +27,7 @@ * */ -#define SIGNAL_HANDTYPE RETSIGTYPE (*)_((int)) +#define SIGNAL_HANDTYPE void (*)_((int)) #ifndef HAVE_KILLPG # define killpg(pgrp,sig) kill(-(pgrp),sig) diff --git a/configure.ac b/configure.ac index b46e2f4c2..7644ebe52 100644 --- a/configure.ac +++ b/configure.ac @@ -955,18 +955,6 @@ dnl -------------- dnl CHECK TYPEDEFS dnl -------------- -AC_DIAGNOSE([obsolete],[your code may safely assume C89 semantics that RETSIGTYPE is void. -Remove this warning and the `AC_CACHE_CHECK' when you adjust the code.])dnl -AC_CACHE_CHECK([return type of signal handlers],[ac_cv_type_signal],[AC_COMPILE_IFELSE( -[AC_LANG_PROGRAM([#include -#include -], - [return *(signal (0, 0)) (0) == 1;])], - [ac_cv_type_signal=int], - [ac_cv_type_signal=void])]) -AC_DEFINE_UNQUOTED([RETSIGTYPE],[$ac_cv_type_signal],[Define as the return type of signal handlers - (`int' or `void').]) - AC_TYPE_PID_T AC_TYPE_OFF_T AC_CHECK_TYPE(ino_t, unsigned long) -- cgit v1.2.3