diff options
author | Peter Stephenson <p.stephenson@samsung.com> | 2018-05-14 16:47:29 +0100 |
---|---|---|
committer | Peter Stephenson <p.stephenson@samsung.com> | 2018-05-14 16:47:29 +0100 |
commit | 449f13a46738ff303e41a8fcad1df850cae721fd (patch) | |
tree | ec2266c920fc4480a9d3a2753c6c9dfdb67579cf | |
parent | a93abe1170a438d45d94b3a7f924553f5cf69cee (diff) | |
download | zsh-449f13a46738ff303e41a8fcad1df850cae721fd.tar.gz zsh-449f13a46738ff303e41a8fcad1df850cae721fd.tar.xz zsh-449f13a46738ff303e41a8fcad1df850cae721fd.zip |
42234: Stephane: don't kill a process if not running.
This could happen when kiiling a job. The processs might be reused.
-rw-r--r-- | Src/signals.c | 18 |
1 files changed, 15 insertions, 3 deletions
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; } |