bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange behaviour on 'read' from a pipe


From: Lluís Batlle i Rossell
Subject: Strange behaviour on 'read' from a pipe
Date: Sat, 31 Mar 2012 15:19:38 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Hello,

I have this script, that I've found to never write "DONE" in my systems, with
bash 4.0, 4.1, 4.2.. until 4.2-p20, my last test.

However, in irc some people told me it prints DONE for them. If I run the 
script with
bash under 'strace -f', it also prints DONE.

So there is some kind of race in 'read'. The current program output in my 
computer is:
reading
debug:done


If 'read' unblocked by error (SIGCHLD?), it would print reading again. If
'read' unblocked having read nothing, it would print a newline (it does not).
And of course it does not print the 'DONE' either.

Maybe it's me not understanding something? I suspect that 'read' reacts to
EINTR, and tries to read again, with the error of *reopening the pipe*
(<$PIPE), which will make it block forever.

Here the script:
-----------
#!/var/run/current-system/sw/bin/bash

PIPE=/tmp/pipe

rm -f $PIPE
mkfifo $PIPE

function spawn {
    "$@"
    echo debug:done
    echo DONE > $PIPE
}

spawn sleep 1 &

while true; do
    echo reading
    while read LINE < $PIPE; do
        echo $LINE
        exit 0
    done
done
-----------------

Regards,
Lluís.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]