Problem with ash redirection changing behaviour
rpurdie at rpsys.net
Wed Jun 2 14:56:20 UTC 2010
On Wed, 2010-06-02 at 14:08 +0200, Cristian Ionescu-Idbohrn wrote:
> On Wed, 2 Jun 2010, Richard Purdie wrote:
> > I have an issue having recently upgraded busybox. The change that is
> > causing me problems is:
> > http://git.busybox.net/busybox/commit/?id=6a0ad2506116f4ddc3f9f617a90ba04a57eeef88
> > which is sanity checking file descriptors before allowing redirection.
> > A script that triggers the problem is:
> > """
> > exec 9>&0 </etc/fstab
> > while read fs mnt type opts dump pass junk
> > do
> > echo $fs
> > done
> > exec 0>&9 9>&-
> > """
> That should work.
> > The idea being to save stdin, read from a file and then restore stdin
> > without forking.
> But so should this (no forks here either, and simplier):
> while read fs mnt type opts dump pass junk; do
> case $fs in
> echo $fs
> done < /etc/fstab
> Does the above work for you?
Yes, that works fine and is simpler. Its as soon as you touch the stdin
fd that things go wrong.
I already changed my script to do:
exec 9< /etc/fstab
while read fs mnt type opts dump pass junk <&9
which is still more complicated than your version but also works
> > This used to work but now when run as ". script" from ash
> Any particular reason to 'source'? You end up with environment
> Is that intentional?
Its sourced to avoid forking. As you've probably guessed, this is a
fragment of an initscript and when you stop forking for many
initscripts, it does significantly improve boot time. The environment
clutter is not intentional and something I should look into though, good
More information about the busybox