Non-interactive commands

Rob Landley rob at landley.net
Sun Sep 9 15:33:30 WST 2007


On Saturday 08 September 2007 3:35:24 pm Micha Nelissen wrote:
> Hi,
>
> The following doesn't work:
>
> $ echo 'echo hello' | ssh host /bin/sh
>
> If host is running dropbear. OTOH, if host is running OpenSSH, I get
> 'hello' echoed back to me.

This sounds like a manifestation of using close() instead of shutdown().  
See "man 2 shutdown", it's this weird little piece of filehandle trivia that 
closes one direction of a bidirectional connection.

When stdin runs out of data, we need to close the outgoing half of the network 
socket so the other end can get EOF.  (Some programs block waiting to read 
all data before they produce any output.)  But we can't close the _incoming_ 
half of the network socket or we won't get any data back.

When "echo" exits, it closes its stdout so the ssh process gets EOF on stdin, 
and should pass that along through the network.  But it has to wait for the 
other end to send all its data back before exiting.  Hence shutdown().  I 
implemented this in netcat a longish time ago, the busybox netcat should get 
this right (circa 1.2.2 anyway, no idea what it looks like these days)...

I thought dropbear was already getting this right, though.

Rob
-- 
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.



More information about the Dropbear mailing list