sh: Successfully do nothing when killing a terminated job.

If a job has terminated but is still known, silently do nothing when using
the kill builtin with the job specifier. Formerly, the shell called kill()
with the process group ID that might have been reused.
This commit is contained in:
jilles 2014-03-08 19:44:34 +00:00
parent 8dfc245ef9
commit 6139448a86
4 changed files with 19 additions and 2 deletions

View File

@ -133,9 +133,15 @@ main(int argc, char *argv[])
for (errors = 0; argc; argc--, argv++) {
#ifdef SHELL
if (**argv == '%')
if (**argv == '%') {
pid = getjobpgrp(*argv);
else
/*
* Silently ignore terminated jobs, like the kernel
* silently ignores zombies.
*/
if (pid == 0)
continue;
} else
#endif
{
pid = strtol(*argv, &ep, 10);

View File

@ -645,6 +645,8 @@ getjobpgrp(char *name)
struct job *jp;
jp = getjob(name);
if (jp->state == JOBDONE)
return 0;
return -jp->ps[0].pid;
}

View File

@ -86,6 +86,7 @@ FILES+= hash3.0 hash3.0.stdout
FILES+= hash4.0
FILES+= jobid1.0
FILES+= jobid2.0
FILES+= kill1.0
FILES+= lineno.0 lineno.0.stdout
FILES+= lineno2.0
FILES+= local1.0

View File

@ -0,0 +1,8 @@
# $FreeBSD$
: &
p1=$!
: &
p2=$!
wait $p2
kill %1