From: "Joshua Hudson" <joshudson@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: patch for "bizarre read bug" in klibc dash
Date: Wed, 14 Jun 2006 20:19:28 -0700 [thread overview]
Message-ID: <bda6d13a0606142019m439c8eavca9afd955930d324@mail.gmail.com> (raw)
I had forked ash awhile back, patched up a few things to behave the
way I wanted them.
While I was at it, I fixed the "echo X | read X ; echo $X" bug that
echoed a blank line.
I tried awhile ago to raise who was responsible for the code and got nowhere.
I suppose you think the above code is a bizarre corner case. It is
not. I use very
complex shell expressions (think loops and subshells) in pipes, with
read in the end to
get the variable I was looking for. The work-around is particularly ugly.
I was quite surprised that this bug never got squashed in dash. So, I
backported it.
Well, here's the patch.
--- usr/dash/eval.c.orig 2006-06-14 19:48:47.000000000 -0700
+++ usr/dash/eval.c 2006-06-14 20:07:58.000000000 -0700
@@ -539,7 +539,17 @@
sh_error("Pipe call failed");
}
}
- if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
+ if (!lp->next) {
+ extern void tempredir0(int prevfd);
+ /* Fix for "bizarre read bug" */
+ if (prevfd > 0) {
+ tempredir0(prevfd);
+ close(prevfd);
+ }
+ evaltree(lp->n, 0);
+ if (prevfd > 0)
+ popredir(0);
+ } else if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
INTON;
if (pip[1] >= 0) {
close(pip[0]);
--- usr/dash/redir.c.orig 2006-06-14 19:59:21.000000000 -0700
+++ usr/dash/redir.c 2006-06-14 20:03:38.000000000 -0700
@@ -310,6 +310,21 @@
}
+void tempredir0(int fd)
+{
+ struct redirtab *sv = redirlist;
+ int i;
+ sv = ckmalloc(sizeof (struct redirtab));
+ for (i = 0 ; i < 10 ; i++)
+ sv->renamed[i] = EMPTY;
+ sv->next = redirlist;
+ redirlist = sv;
+ INTOFF;
+ sv->renamed[0] = copyfd(0, 10);
+ close(0);
+ copyfd(fd, 0);
+ INTON;
+}
/*
* Undo the effects of the last redirection.
next reply other threads:[~2006-06-15 3:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-15 3:19 Joshua Hudson [this message]
2006-06-15 3:53 ` Alexander E. Patrakov
[not found] ` <bda6d13a0606142145r11628ec2w788117ee2d418e59@mail.gmail.com>
2006-06-15 5:02 ` Alexander E. Patrakov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bda6d13a0606142019m439c8eavca9afd955930d324@mail.gmail.com \
--to=joshudson@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®