bin/157013: Bizarre file descriptor race condition

jilles at FreeBSD.org jilles at FreeBSD.org
Fri May 13 23:31:05 UTC 2011


Synopsis: Bizarre file descriptor race condition

State-Changed-From-To: open->closed
State-Changed-By: jilles
State-Changed-When: Fri May 13 23:18:18 UTC 2011
State-Changed-Why: 
This is not a bug but a fairly common caveat with ssh(1).

The problem is that ssh(1) does not know if the other side wants
input and therefore it reads data and sends it to the other side.
Once data has been read from a pipe there is no way to put it back.
It would be possible with a regular file but determining the amount
to put back would be very complicated and unreliable.

If the other side is very fast, it might finish executing the
command before ssh(1) attempts its first read and the script
might work as intended.

You can solve the problem by redirecting ssh's input (either with
shell redirection or with the -n option) or by using a different
file descriptor for the list, like:

while read hostid hostname <&3; do
        echo ${hostid}:${hostname}
        ssh ${hostname} 'df -k'
done 3<${DFRTMP}/hosts


Responsible-Changed-From-To: freebsd-bugs->jilles
Responsible-Changed-By: jilles
Responsible-Changed-When: Fri May 13 23:18:18 UTC 2011
Responsible-Changed-Why: 
Track.

http://www.freebsd.org/cgi/query-pr.cgi?pr=157013


More information about the freebsd-bugs mailing list