summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko2009-03-19 01:59:59 +0000
committerDenis Vlasenko2009-03-19 01:59:59 +0000
commit5c2b81470d0d2e0734866c57b29c2e2fa3e3bc13 (patch)
tree5c9fe95e2e69b01e2cf07e097aa4b852a955ae12
parentc1969f69b11dca4fdd8916684daea8b2abf63017 (diff)
downloadbusybox-5c2b81470d0d2e0734866c57b29c2e2fa3e3bc13.zip
busybox-5c2b81470d0d2e0734866c57b29c2e2fa3e3bc13.tar.gz
ash: fix "ash -c 'exec 1>&0'" complaining that fd 0 is busy
-rw-r--r--shell/ash.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/shell/ash.c b/shell/ash.c
index b333516..179d925 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -11684,7 +11684,8 @@ expandstr(const char *ps)
{
union node n;
- /* XXX Fix (char *) cast. */
+ /* XXX Fix (char *) cast. It _is_ a bug. ps is variable's value,
+ * and token processing _can_ alter it (delete NULs etc). */
setinputstring((char *)ps);
readtoken1(pgetc(), PSSYNTAX, nullstr, 0);
popfile();
@@ -13802,15 +13803,20 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
}
state3:
state = 4;
- if (minusc)
+ if (minusc) {
+ /* evalstring pushes parsefile stack.
+ * Ensure we don't falsely claim that 0 (stdin)
+ * is one of stacked source fds */
+ if (!sflag)
+ g_parsefile->fd = -1;
evalstring(minusc, 0);
+ }
if (sflag || minusc == NULL) {
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
if (iflag) {
const char *hp = lookupvar("HISTFILE");
-
- if (hp != NULL)
+ if (hp)
line_input_state->hist_file = hp;
}
#endif