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:
parent
8dfc245ef9
commit
6139448a86
@ -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);
|
||||
|
@ -645,6 +645,8 @@ getjobpgrp(char *name)
|
||||
struct job *jp;
|
||||
|
||||
jp = getjob(name);
|
||||
if (jp->state == JOBDONE)
|
||||
return 0;
|
||||
return -jp->ps[0].pid;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
8
bin/sh/tests/builtins/kill1.0
Normal file
8
bin/sh/tests/builtins/kill1.0
Normal file
@ -0,0 +1,8 @@
|
||||
# $FreeBSD$
|
||||
|
||||
: &
|
||||
p1=$!
|
||||
: &
|
||||
p2=$!
|
||||
wait $p2
|
||||
kill %1
|
Loading…
Reference in New Issue
Block a user