[Toybox] netcat -f bug

Rob Landley rob at landley.net
Fri May 10 10:40:22 PDT 2024


What's your use case triggering this patch? Because without that, I go off on
various design tangents, as seen below:

On 5/10/24 06:09, Yi-Yo Chiang via Toybox wrote:
> Hi,
> The -f option for netcat doesn't seem to be doing anything right now.

I should have a test for that, but to be honest I came up with netcat -f back in
busybox (commit 1cca9484db69 says 2006) before I knew about bash's <> redirector
to open a file for both reading _and_ writing (or had bash not added it yet?),
meaning the example in that commit probably _should_ have been stty 115200 -F
/dev/ttyS0 && stty raw -echo -ctlecho && cat <>/dev/ttyS0 >&0 2>&0

(I should NOT ask Chet for "{0-2}<>/dev/ttyS0" syntax operating on a filehandle
range. I should not do it. That would be... I dunno, rude? I mean in theory I'd
just want him to fix the existing {1..2} syntax to do one open() and then dup()
redirects instead of opening the device multiple times, which was the initial
problem because reopening the /dev node instead of dup() an existing filehandle
to it either gave -EBUSY or hardware reset the UART depending on the underlying
driver, and the reason chet would give me a LOOK if I asked is {brace,expansion}
is resolved _before_ variable expansion and redirection, so it literally turns
INTO 3 arguments with different numbers and thus three separate open() calls to
the char device, and making it do something else is basically a layering
violation...)

Ahem. Sorry. Tangent.

It's possible netcat -ft makes it still useful, but A) that implies there should
be some sort of tty wrapper in the nice/taskset/time/chroot/nohup mold, B) I
think -t is currently broken because I needed to rewrite it to add nommu support
(decompose forkpty() into the underlying openpty() and login_tty() calls around
the vfork() instead of fork()) and just commented it out and put it on the todo
list...

The original theory was -f should fall through to the "else" case on line 191,
and thus naturally inherit any other applicable options. Which is hard to see in
my current tree because with a bunch of half-finished work in it:

$ git diff toys/*/netcat.c | diffstat
 netcat.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 13 deletions(-)

Sorry for falling behind...

> It is
> missing a call to pollinate() after opening the specified device file.
> The patch adds back that line of pollinate().

Which makes it not work with running commands (ala -f should work like -l).

> Also make sure that the timeout handler is not armed for -f mode as -f shouldn't
> timeout. File open() should just succeed or fail immediately.

Why shouldn't -f timeout? Various /dev nodes take a while to open, automount
behind the scenes... Is there a downside to leaving that part as is? (Other than
the new case you added not alarm(0) disarming it?)

Rob


More information about the Toybox mailing list