sh: Avoid marking a job as done before it is fully created.

In r208489, I added code to reap zombies when forking new processes, to
limit the amount of zombies. However, this can lead to marking a job as done
or stopped if it consists of multiple processes and the first process ends
very quickly. Fix this by only checking for zombies before forking the first
process of a job and not marking any jobs without processes as done or
stopped.
This commit is contained in:
Jilles Tjoelker 2010-12-05 21:53:29 +00:00
parent da78facc72
commit ff304d3732
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=216208

View File

@ -766,7 +766,7 @@ forkshell(struct job *jp, union node *n, int mode)
TRACE(("forkshell(%%%td, %p, %d) called\n", jp - jobtab, (void *)n,
mode));
INTOFF;
if (mode == FORK_BG)
if (mode == FORK_BG && (jp == NULL || jp->nprocs == 0))
checkzombies();
flushall();
pid = fork();
@ -980,7 +980,7 @@ dowait(int block, struct job *job)
INTOFF;
thisjob = NULL;
for (jp = jobtab ; jp < jobtab + njobs ; jp++) {
if (jp->used) {
if (jp->used && jp->nprocs > 0) {
done = 1;
stopped = 1;
for (sp = jp->ps ; sp < jp->ps + jp->nprocs ; sp++) {