sh: Make <&0 disable the </dev/null implicit in a background command.
Although <&0 does nothing, it is a redirection affecting standard input and should therefore disable the </dev/null redirection implicit in a background command.
This commit is contained in:
parent
e0c634180c
commit
1b57cec7d9
@ -69,6 +69,7 @@ __FBSDID("$FreeBSD$");
|
||||
struct redirtab {
|
||||
struct redirtab *next;
|
||||
int renamed[10];
|
||||
int fd0_redirected;
|
||||
};
|
||||
|
||||
|
||||
@ -109,11 +110,14 @@ redirect(union node *redir, int flags)
|
||||
sv = ckmalloc(sizeof (struct redirtab));
|
||||
for (i = 0 ; i < 10 ; i++)
|
||||
sv->renamed[i] = EMPTY;
|
||||
sv->fd0_redirected = fd0_redirected;
|
||||
sv->next = redirlist;
|
||||
redirlist = sv;
|
||||
}
|
||||
for (n = redir ; n ; n = n->nfile.next) {
|
||||
fd = n->nfile.fd;
|
||||
if (fd == 0)
|
||||
fd0_redirected = 1;
|
||||
if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) &&
|
||||
n->ndup.dupfd == fd)
|
||||
continue; /* redirect from/to same file descriptor */
|
||||
@ -134,8 +138,6 @@ redirect(union node *redir, int flags)
|
||||
sv->renamed[fd] = i;
|
||||
INTON;
|
||||
}
|
||||
if (fd == 0)
|
||||
fd0_redirected++;
|
||||
openredirect(n, memory);
|
||||
}
|
||||
if (memory[1])
|
||||
@ -303,8 +305,6 @@ popredir(void)
|
||||
|
||||
for (i = 0 ; i < 10 ; i++) {
|
||||
if (rp->renamed[i] != EMPTY) {
|
||||
if (i == 0)
|
||||
fd0_redirected--;
|
||||
if (rp->renamed[i] >= 0) {
|
||||
dup2(rp->renamed[i], i);
|
||||
close(rp->renamed[i]);
|
||||
@ -314,6 +314,7 @@ popredir(void)
|
||||
}
|
||||
}
|
||||
INTOFF;
|
||||
fd0_redirected = rp->fd0_redirected;
|
||||
redirlist = rp->next;
|
||||
ckfree(rp);
|
||||
INTON;
|
||||
|
4
tools/regression/bin/sh/execution/bg10.0
Normal file
4
tools/regression/bin/sh/execution/bg10.0
Normal file
@ -0,0 +1,4 @@
|
||||
# $FreeBSD$
|
||||
# The redirection overrides the </dev/null implicit in a background command.
|
||||
|
||||
echo yes | ${SH} -c '{ cat & wait; } <&0'
|
1
tools/regression/bin/sh/execution/bg10.0.stdout
Normal file
1
tools/regression/bin/sh/execution/bg10.0.stdout
Normal file
@ -0,0 +1 @@
|
||||
yes
|
Loading…
x
Reference in New Issue
Block a user