Piping to functions in busybox hush shell with NOMMU CPU

Denys Vlasenko vda.linux at googlemail.com
Fri Sep 4 04:27:23 UTC 2015


On Fri, Aug 28, 2015 at 9:36 PM, Konstantin Lazarev <cnlazarev at gmail.com> wrote:
> Hello,
>
> I have issue with busybox hash built for NOMMU CPU.
>
> I am experiencing a problem with different behaviour of piping between
> functions in script when using hush on NOMMU platform and ash shells on MMU
> platform running busybox 1.23.2.
>
> I have test script which is called with parameter:
> ./script.sh /tmp
> And in hush following script is getting stuck.
> With debug output added to read implementation I figured out that it is
> stuck because "read" in test_method function is getting stdin from console
> instead of piping from calling code:
> -------------------------------------------------------------
> #!/bin/sh
>
> test_method()
> {
>   while read p; do
>     echo "$p"
>   done
> }
>
> do_ls()
> {
>   ls -1RF "$1" | test_method
> }
>
>
> processArgs()
> {
>   do_ls "$1"
> }
>
> processArgs "$@" | sort -u
> -------------------------------------------------------------
>
> The same script works as expected in busybox ash shell.
>
> And it works in busybox hush if last sort is removed.
> Also in busybox hush if I do the same without functions with following
> commands it works fine too:
> ls -1RF /tmp | while read p; do echo "$p"; done | sort -u
>
> It seems that issue is in hush NOMMU implementation in the case when piping
> happens to a function.
>
> Can anybody to be so kind to give me idea how fix this problem without
> changing test script?

Fixed in git, thanks for reporting it!

A simplified test case is:

#!/bin/sh
func()
{
        while read p; do echo "$p"; done
}
pipe_to_func()
{
        echo Ok | func
}
pipe_to_func | cat


What happens here is we lose "echo Ok |" part
when we save function body for pipe_to_func().

And when we re-execute hush to run it in a subshell
for "pipe_to_func | cat", we execute wrong
(truncated) body.

Please try current git.


More information about the busybox mailing list