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:
Jilles Tjoelker 2013-11-24 23:12:13 +00:00
parent e0c634180c
commit 1b57cec7d9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=258535
3 changed files with 10 additions and 4 deletions

View File

@ -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;

View File

@ -0,0 +1,4 @@
# $FreeBSD$
# The redirection overrides the </dev/null implicit in a background command.
echo yes | ${SH} -c '{ cat & wait; } <&0'

View File

@ -0,0 +1 @@
yes