hush: fix multiple redirections of the same fd (bug 227)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
54e0843e7d
commit
1dd6cf8677
@ -2646,7 +2646,9 @@ static int setup_redirects(struct command *prog, int squirrel[])
|
||||
for (redir = prog->redirects; redir; redir = redir->next) {
|
||||
if (redir->rd_type == REDIRECT_HEREDOC2) {
|
||||
/* rd_fd<<HERE case */
|
||||
if (squirrel && redir->rd_fd < 3) {
|
||||
if (squirrel && redir->rd_fd < 3
|
||||
&& squirrel[redir->rd_fd] < 0
|
||||
) {
|
||||
squirrel[redir->rd_fd] = dup(redir->rd_fd);
|
||||
}
|
||||
/* for REDIRECT_HEREDOC2, rd_filename holds _contents_
|
||||
@ -2682,7 +2684,9 @@ static int setup_redirects(struct command *prog, int squirrel[])
|
||||
}
|
||||
|
||||
if (openfd != redir->rd_fd) {
|
||||
if (squirrel && redir->rd_fd < 3) {
|
||||
if (squirrel && redir->rd_fd < 3
|
||||
&& squirrel[redir->rd_fd] < 0
|
||||
) {
|
||||
squirrel[redir->rd_fd] = dup(redir->rd_fd);
|
||||
}
|
||||
if (openfd == REDIRFD_CLOSE) {
|
||||
|
4
shell/hush_test/hush-misc/redir6.right
Normal file
4
shell/hush_test/hush-misc/redir6.right
Normal file
@ -0,0 +1,4 @@
|
||||
Testing multiple redirections to same fd
|
||||
Hello
|
||||
Done1
|
||||
Done2
|
5
shell/hush_test/hush-misc/redir6.tests
Executable file
5
shell/hush_test/hush-misc/redir6.tests
Executable file
@ -0,0 +1,5 @@
|
||||
echo "Testing multiple redirections to same fd"
|
||||
# bug was making us lose fd #1 after this:
|
||||
echo Hello >/dev/null 1>&2
|
||||
echo Done1
|
||||
echo Done2 >&2
|
Loading…
Reference in New Issue
Block a user