ash: fix "(cat < file)" hang introduced by rev 22944.
This commit is contained in:
parent
8334db13c3
commit
34c73c499b
26
shell/ash.c
26
shell/ash.c
@ -4905,7 +4905,11 @@ static int need_to_remember(struct redirtab *rp, int fd)
|
|||||||
static int is_hidden_fd(struct redirtab *rp, int fd)
|
static int is_hidden_fd(struct redirtab *rp, int fd)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct parsefile *pf = g_parsefile;
|
struct parsefile *pf;
|
||||||
|
|
||||||
|
if (fd == -1)
|
||||||
|
return 0;
|
||||||
|
pf = g_parsefile;
|
||||||
while (pf) {
|
while (pf) {
|
||||||
if (fd == pf->fd) {
|
if (fd == pf->fd) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -5048,7 +5052,7 @@ redirect(union node *redir, int flags)
|
|||||||
* Undo the effects of the last redirection.
|
* Undo the effects of the last redirection.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
popredir(int drop)
|
popredir(int drop, int restore)
|
||||||
{
|
{
|
||||||
struct redirtab *rp;
|
struct redirtab *rp;
|
||||||
int i;
|
int i;
|
||||||
@ -5066,7 +5070,7 @@ popredir(int drop)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (copy != EMPTY) {
|
if (copy != EMPTY) {
|
||||||
if (!drop || (copy & COPYFD_RESTORE)) {
|
if (!drop || (restore && (copy & COPYFD_RESTORE))) {
|
||||||
copy &= ~COPYFD_RESTORE;
|
copy &= ~COPYFD_RESTORE;
|
||||||
/*close(fd);*/
|
/*close(fd);*/
|
||||||
copyfd(copy, fd | COPYFD_EXACT);
|
copyfd(copy, fd | COPYFD_EXACT);
|
||||||
@ -5094,7 +5098,7 @@ clearredir(int drop)
|
|||||||
g_nullredirs = 0;
|
g_nullredirs = 0;
|
||||||
if (!redirlist)
|
if (!redirlist)
|
||||||
break;
|
break;
|
||||||
popredir(drop);
|
popredir(drop, /*restore:*/ 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7016,7 +7020,7 @@ shellexec(char **argv, const char *path, int idx)
|
|||||||
int applet_no = -1;
|
int applet_no = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
clearredir(1);
|
clearredir(/*drop:*/ 1);
|
||||||
envp = listvars(VEXPORT, VUNSET, 0);
|
envp = listvars(VEXPORT, VUNSET, 0);
|
||||||
if (strchr(argv[0], '/') != NULL
|
if (strchr(argv[0], '/') != NULL
|
||||||
#if ENABLE_FEATURE_SH_STANDALONE
|
#if ENABLE_FEATURE_SH_STANDALONE
|
||||||
@ -7926,7 +7930,7 @@ evaltree(union node *n, int flags)
|
|||||||
evaltree(n->nredir.n, flags & EV_TESTED);
|
evaltree(n->nredir.n, flags & EV_TESTED);
|
||||||
status = exitstatus;
|
status = exitstatus;
|
||||||
}
|
}
|
||||||
popredir(0);
|
popredir(/*drop:*/ 0, /*restore:*/ 0 /* not sure */);
|
||||||
goto setstatus;
|
goto setstatus;
|
||||||
case NCMD:
|
case NCMD:
|
||||||
evalfn = evalcommand;
|
evalfn = evalcommand;
|
||||||
@ -8707,11 +8711,11 @@ evalcommand(union node *cmd, int flags)
|
|||||||
char *lastarg;
|
char *lastarg;
|
||||||
const char *path;
|
const char *path;
|
||||||
int spclbltin;
|
int spclbltin;
|
||||||
int cmd_is_exec;
|
|
||||||
int status;
|
int status;
|
||||||
char **nargv;
|
char **nargv;
|
||||||
struct builtincmd *bcmd;
|
struct builtincmd *bcmd;
|
||||||
int pseudovarflag = 0;
|
smallint cmd_is_exec;
|
||||||
|
smallint pseudovarflag = 0;
|
||||||
|
|
||||||
/* First expand the arguments. */
|
/* First expand the arguments. */
|
||||||
TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
|
TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags));
|
||||||
@ -8822,7 +8826,7 @@ evalcommand(union node *cmd, int flags)
|
|||||||
if (spclbltin < 0)
|
if (spclbltin < 0)
|
||||||
spclbltin = IS_BUILTIN_SPECIAL(cmdentry.u.cmd);
|
spclbltin = IS_BUILTIN_SPECIAL(cmdentry.u.cmd);
|
||||||
if (cmdentry.u.cmd == EXECCMD)
|
if (cmdentry.u.cmd == EXECCMD)
|
||||||
cmd_is_exec++;
|
cmd_is_exec = 1;
|
||||||
#if ENABLE_ASH_CMDCMD
|
#if ENABLE_ASH_CMDCMD
|
||||||
if (cmdentry.u.cmd == COMMANDCMD) {
|
if (cmdentry.u.cmd == COMMANDCMD) {
|
||||||
path = oldpath;
|
path = oldpath;
|
||||||
@ -8917,7 +8921,7 @@ evalcommand(union node *cmd, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
popredir(cmd_is_exec);
|
popredir(/*drop:*/ cmd_is_exec, /*restore:*/ cmd_is_exec);
|
||||||
if (lastarg) {
|
if (lastarg) {
|
||||||
/* dsl: I think this is intended to be used to support
|
/* dsl: I think this is intended to be used to support
|
||||||
* '_' in 'vi' command mode during line editing...
|
* '_' in 'vi' command mode during line editing...
|
||||||
@ -13485,7 +13489,7 @@ reset(void)
|
|||||||
tokpushback = 0;
|
tokpushback = 0;
|
||||||
checkkwd = 0;
|
checkkwd = 0;
|
||||||
/* from redir.c: */
|
/* from redir.c: */
|
||||||
clearredir(0);
|
clearredir(/*drop:*/ 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PROFILE
|
#if PROFILE
|
||||||
|
2
shell/ash_test/ash-redir/redir6.right
Normal file
2
shell/ash_test/ash-redir/redir6.right
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Hello
|
||||||
|
OK
|
3
shell/ash_test/ash-redir/redir6.tests
Executable file
3
shell/ash_test/ash-redir/redir6.tests
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
# we had a bug where this would hang
|
||||||
|
(head -n 1 <redir6.right)
|
||||||
|
echo OK
|
Loading…
x
Reference in New Issue
Block a user