[Toybox] [PATCH] netcat: make -l exit after handling a request

Josh Gao jmgao at google.com
Mon Jun 26 18:22:42 PDT 2017


On Sun, Jun 25, 2017 at 12:14 PM, Rob Landley <rob at landley.net> wrote:
>
> >     terminal1$ echo foo | toybox nc -l -p 1234 > bar
> >     terminal1$ cat bar
> >     bar
>
> Your call there wouldn't work with the "stop after -l" version either,
> the -p would have to come before the -l. :P


Seems to work for me?


> >     terminal2$ echo bar | toybox nc localhost 1234 > foo
> >     terminal2$ cat foo
> >     foo
>
> Um... yes? That's what it's supposed to do, and what it's doing without
> this patch?
>
> Your first hunk told it to run an instance of netcat in chat mode (no
> command to run, so instead stdin and stdout of netcat get forwarded to
> the connection). This will block until the connection is made, although
> if you're redirecting the input you can background it if you want to.
>
> The second hunk then made a connection. The "bar" you wrote to the
> second instance got written to the first instance's output, and the
> "foo" you wrote to the first instance got forwarded to the second
> instance's output. When each instance gets EOF from stdin it calls
> shutdown(fd) to let the other instance know, so both instances exit.
>
> I just built netcat from clean toybox, and it did that. I don't see the
> problem?
>

That's not what I'm seeing. With a freshly compiled tip of tree master
(279eb227), the listener doesn't ever exit:

# Terminal 1
jmgao at cyclops2:/android/upstream/toybox$ echo foo | ./toybox nc localhost
1234
foo
jmgao at cyclops2:/android/upstream/toybox$ echo bar | ./toybox nc localhost
1234
jmgao at cyclops2:/android/upstream/toybox$ echo baz | ./toybox nc localhost
1234
jmgao at cyclops2:/android/upstream/toybox$

# Terminal 2
jmgao at cyclops2:/android/upstream/toybox$ echo foo | ./toybox nc -l -p 1234
foo
bar
baz
^C
jmgao at cyclops2:/android/upstream/toybox$

`toybox nc -l -p 1234 echo foo` works fine because the process execs
without forking.
Using -l without a command will fall through to pollinate, finish, and then
try to listen again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20170626/f91c132d/attachment-0002.htm>


More information about the Toybox mailing list