<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jun 25, 2017 at 12:14 PM, Rob Landley <span dir="ltr"><<a href="mailto:rob@landley.net" target="_blank">rob@landley.net</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-m_-904431208180879113gmail-">
> terminal1$ echo foo | toybox nc -l -p 1234 > bar<br>
> terminal1$ cat bar<br>
> bar<br>
<br>
</span>Your call there wouldn't work with the "stop after -l" version either,<br>
the -p would have to come before the -l. :P</blockquote><div><br></div><div>Seems to work for me?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-m_-904431208180879113gmail-">
> terminal2$ echo bar | toybox nc localhost 1234 > foo<br>
> terminal2$ cat foo<br>
> foo<br>
<br>
</span>Um... yes? That's what it's supposed to do, and what it's doing without<br>
this patch?<br>
<br>
Your first hunk told it to run an instance of netcat in chat mode (no<br>
command to run, so instead stdin and stdout of netcat get forwarded to<br>
the connection). This will block until the connection is made, although<br>
if you're redirecting the input you can background it if you want to.<br>
<br>
The second hunk then made a connection. The "bar" you wrote to the<br>
second instance got written to the first instance's output, and the<br>
"foo" you wrote to the first instance got forwarded to the second<br>
instance's output. When each instance gets EOF from stdin it calls<br>
shutdown(fd) to let the other instance know, so both instances exit.<br>
<br>
I just built netcat from clean toybox, and it did that. I don't see the<br>
problem?<br></blockquote><div><br></div><div>That's not what I'm seeing. With a freshly compiled tip of tree master (279eb227), the listener doesn't ever exit:</div><div><br></div><div># Terminal 1</div><div><div>jmgao@cyclops2:/android/upstream/toybox$ echo foo | ./toybox nc localhost 1234</div><div>foo</div><div>jmgao@cyclops2:/android/upstream/toybox$ echo bar | ./toybox nc localhost 1234</div><div>jmgao@cyclops2:/android/upstream/toybox$ echo baz | ./toybox nc localhost 1234</div><div>jmgao@cyclops2:/android/upstream/toybox$ </div></div><div><br></div><div># Terminal 2</div><div><div>jmgao@cyclops2:/android/upstream/toybox$ echo foo | ./toybox nc -l -p 1234</div><div>foo</div><div>bar</div><div>baz</div><div>^C</div><div>jmgao@cyclops2:/android/upstream/toybox$</div></div></div><br></div><div class="gmail_extra">`toybox nc -l -p 1234 echo foo` works fine because the process execs without forking.</div><div class="gmail_extra">Using -l without a command will fall through to pollinate, finish, and then try to listen again.</div></div>