diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-16 11:48:02 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-16 11:48:02 +0000 |
commit | 34c73c499bae67c1a81482c1ff5c263c85e51f1d (patch) | |
tree | b4a20d920d0b56140dd96011a4236c1991d5299c | |
parent | 8334db13c31f0cc60993739e573034ebbf258f38 (diff) | |
download | busybox-w32-34c73c499bae67c1a81482c1ff5c263c85e51f1d.tar.gz busybox-w32-34c73c499bae67c1a81482c1ff5c263c85e51f1d.tar.bz2 busybox-w32-34c73c499bae67c1a81482c1ff5c263c85e51f1d.zip |
ash: fix "(cat < file)" hang introduced by rev 22944.
-rw-r--r-- | shell/ash.c | 26 | ||||
-rw-r--r-- | shell/ash_test/ash-redir/redir6.right | 2 | ||||
-rwxr-xr-x | shell/ash_test/ash-redir/redir6.tests | 3 |
3 files changed, 20 insertions, 11 deletions
diff --git a/shell/ash.c b/shell/ash.c index 3a1e1d797..d63acc2c8 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4905,7 +4905,11 @@ static int need_to_remember(struct redirtab *rp, int fd) | |||
4905 | static int is_hidden_fd(struct redirtab *rp, int fd) | 4905 | static int is_hidden_fd(struct redirtab *rp, int fd) |
4906 | { | 4906 | { |
4907 | int i; | 4907 | int i; |
4908 | struct parsefile *pf = g_parsefile; | 4908 | struct parsefile *pf; |
4909 | |||
4910 | if (fd == -1) | ||
4911 | return 0; | ||
4912 | pf = g_parsefile; | ||
4909 | while (pf) { | 4913 | while (pf) { |
4910 | if (fd == pf->fd) { | 4914 | if (fd == pf->fd) { |
4911 | return 1; | 4915 | return 1; |
@@ -5048,7 +5052,7 @@ redirect(union node *redir, int flags) | |||
5048 | * Undo the effects of the last redirection. | 5052 | * Undo the effects of the last redirection. |
5049 | */ | 5053 | */ |
5050 | static void | 5054 | static void |
5051 | popredir(int drop) | 5055 | popredir(int drop, int restore) |
5052 | { | 5056 | { |
5053 | struct redirtab *rp; | 5057 | struct redirtab *rp; |
5054 | int i; | 5058 | int i; |
@@ -5066,7 +5070,7 @@ popredir(int drop) | |||
5066 | continue; | 5070 | continue; |
5067 | } | 5071 | } |
5068 | if (copy != EMPTY) { | 5072 | if (copy != EMPTY) { |
5069 | if (!drop || (copy & COPYFD_RESTORE)) { | 5073 | if (!drop || (restore && (copy & COPYFD_RESTORE))) { |
5070 | copy &= ~COPYFD_RESTORE; | 5074 | copy &= ~COPYFD_RESTORE; |
5071 | /*close(fd);*/ | 5075 | /*close(fd);*/ |
5072 | copyfd(copy, fd | COPYFD_EXACT); | 5076 | copyfd(copy, fd | COPYFD_EXACT); |
@@ -5094,7 +5098,7 @@ clearredir(int drop) | |||
5094 | g_nullredirs = 0; | 5098 | g_nullredirs = 0; |
5095 | if (!redirlist) | 5099 | if (!redirlist) |
5096 | break; | 5100 | break; |
5097 | popredir(drop); | 5101 | popredir(drop, /*restore:*/ 0); |
5098 | } | 5102 | } |
5099 | } | 5103 | } |
5100 | 5104 | ||
@@ -7016,7 +7020,7 @@ shellexec(char **argv, const char *path, int idx) | |||
7016 | int applet_no = -1; | 7020 | int applet_no = -1; |
7017 | #endif | 7021 | #endif |
7018 | 7022 | ||
7019 | clearredir(1); | 7023 | clearredir(/*drop:*/ 1); |
7020 | envp = listvars(VEXPORT, VUNSET, 0); | 7024 | envp = listvars(VEXPORT, VUNSET, 0); |
7021 | if (strchr(argv[0], '/') != NULL | 7025 | if (strchr(argv[0], '/') != NULL |
7022 | #if ENABLE_FEATURE_SH_STANDALONE | 7026 | #if ENABLE_FEATURE_SH_STANDALONE |
@@ -7926,7 +7930,7 @@ evaltree(union node *n, int flags) | |||
7926 | evaltree(n->nredir.n, flags & EV_TESTED); | 7930 | evaltree(n->nredir.n, flags & EV_TESTED); |
7927 | status = exitstatus; | 7931 | status = exitstatus; |
7928 | } | 7932 | } |
7929 | popredir(0); | 7933 | popredir(/*drop:*/ 0, /*restore:*/ 0 /* not sure */); |
7930 | goto setstatus; | 7934 | goto setstatus; |
7931 | case NCMD: | 7935 | case NCMD: |
7932 | evalfn = evalcommand; | 7936 | evalfn = evalcommand; |
@@ -8707,11 +8711,11 @@ evalcommand(union node *cmd, int flags) | |||
8707 | char *lastarg; | 8711 | char *lastarg; |
8708 | const char *path; | 8712 | const char *path; |
8709 | int spclbltin; | 8713 | int spclbltin; |
8710 | int cmd_is_exec; | ||
8711 | int status; | 8714 | int status; |
8712 | char **nargv; | 8715 | char **nargv; |
8713 | struct builtincmd *bcmd; | 8716 | struct builtincmd *bcmd; |
8714 | int pseudovarflag = 0; | 8717 | smallint cmd_is_exec; |
8718 | smallint pseudovarflag = 0; | ||
8715 | 8719 | ||
8716 | /* First expand the arguments. */ | 8720 | /* First expand the arguments. */ |
8717 | TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); | 8721 | TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); |
@@ -8822,7 +8826,7 @@ evalcommand(union node *cmd, int flags) | |||
8822 | if (spclbltin < 0) | 8826 | if (spclbltin < 0) |
8823 | spclbltin = IS_BUILTIN_SPECIAL(cmdentry.u.cmd); | 8827 | spclbltin = IS_BUILTIN_SPECIAL(cmdentry.u.cmd); |
8824 | if (cmdentry.u.cmd == EXECCMD) | 8828 | if (cmdentry.u.cmd == EXECCMD) |
8825 | cmd_is_exec++; | 8829 | cmd_is_exec = 1; |
8826 | #if ENABLE_ASH_CMDCMD | 8830 | #if ENABLE_ASH_CMDCMD |
8827 | if (cmdentry.u.cmd == COMMANDCMD) { | 8831 | if (cmdentry.u.cmd == COMMANDCMD) { |
8828 | path = oldpath; | 8832 | path = oldpath; |
@@ -8917,7 +8921,7 @@ evalcommand(union node *cmd, int flags) | |||
8917 | } | 8921 | } |
8918 | 8922 | ||
8919 | out: | 8923 | out: |
8920 | popredir(cmd_is_exec); | 8924 | popredir(/*drop:*/ cmd_is_exec, /*restore:*/ cmd_is_exec); |
8921 | if (lastarg) { | 8925 | if (lastarg) { |
8922 | /* dsl: I think this is intended to be used to support | 8926 | /* dsl: I think this is intended to be used to support |
8923 | * '_' in 'vi' command mode during line editing... | 8927 | * '_' in 'vi' command mode during line editing... |
@@ -13485,7 +13489,7 @@ reset(void) | |||
13485 | tokpushback = 0; | 13489 | tokpushback = 0; |
13486 | checkkwd = 0; | 13490 | checkkwd = 0; |
13487 | /* from redir.c: */ | 13491 | /* from redir.c: */ |
13488 | clearredir(0); | 13492 | clearredir(/*drop:*/ 0); |
13489 | } | 13493 | } |
13490 | 13494 | ||
13491 | #if PROFILE | 13495 | #if PROFILE |
diff --git a/shell/ash_test/ash-redir/redir6.right b/shell/ash_test/ash-redir/redir6.right new file mode 100644 index 000000000..ed754df78 --- /dev/null +++ b/shell/ash_test/ash-redir/redir6.right | |||
@@ -0,0 +1,2 @@ | |||
1 | Hello | ||
2 | OK | ||
diff --git a/shell/ash_test/ash-redir/redir6.tests b/shell/ash_test/ash-redir/redir6.tests new file mode 100755 index 000000000..33b6d4cd4 --- /dev/null +++ b/shell/ash_test/ash-redir/redir6.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | # we had a bug where this would hang | ||
2 | (head -n 1 <redir6.right) | ||
3 | echo OK | ||