sh: Set $? to 0 for background commands.
For backgrounded pipelines and subshells, the previous value of $? was being preserved, which is incorrect. For backgrounded simple commands containing a command substitution, the status of the last command substitution was returned instead of 0. If fork() fails, this is an error.
This commit is contained in:
parent
1792d820be
commit
03b3a844d0
@ -420,7 +420,8 @@ evalsubshell(union node *n, int flags)
|
||||
INTOFF;
|
||||
exitstatus = waitforjob(jp, (int *)NULL);
|
||||
INTON;
|
||||
}
|
||||
} else
|
||||
exitstatus = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -559,7 +560,8 @@ evalpipe(union node *n)
|
||||
exitstatus = waitforjob(jp, (int *)NULL);
|
||||
TRACE(("evalpipe: job done exit status %d\n", exitstatus));
|
||||
INTON;
|
||||
}
|
||||
} else
|
||||
exitstatus = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1056,7 +1058,8 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
||||
backcmd->fd = pip[0];
|
||||
close(pip[1]);
|
||||
backcmd->jp = jp;
|
||||
}
|
||||
} else
|
||||
exitstatus = 0;
|
||||
|
||||
out:
|
||||
if (lastarg)
|
||||
|
3
tools/regression/bin/sh/execution/bg1.0
Normal file
3
tools/regression/bin/sh/execution/bg1.0
Normal file
@ -0,0 +1,3 @@
|
||||
# $FreeBSD$
|
||||
|
||||
: `false` &
|
5
tools/regression/bin/sh/execution/bg2.0
Normal file
5
tools/regression/bin/sh/execution/bg2.0
Normal file
@ -0,0 +1,5 @@
|
||||
# $FreeBSD$
|
||||
|
||||
f() { return 42; }
|
||||
f
|
||||
: | : &
|
5
tools/regression/bin/sh/execution/bg3.0
Normal file
5
tools/regression/bin/sh/execution/bg3.0
Normal file
@ -0,0 +1,5 @@
|
||||
# $FreeBSD$
|
||||
|
||||
f() { return 42; }
|
||||
f
|
||||
(:) &
|
Loading…
Reference in New Issue
Block a user