Re: [Toybox] [PATCH v2 1/1] teach head -c
On 26/06, Rob Landley wrote: > On 06/01/2017 01:36 AM, Ilya Kuzmich wrote: > > ping? > > Let's see... > > >> Not POSIX, but implemented in coreutils, busybox and freebsd. > > 1) Do you have a use case for this? Or did you implement this because > it's there? Denys added it to Busybox on February 25, 2013 but no > message titles in the busybox mailing list around then mention "head" (I > checked from February 2013 back to the previous November). I couldn't a > bug report in https://bugs.busybox.net/buglist.cgi?quicksearch=head > either. So it looks like when busybox was ~15 years old Denys added this > because he could, not because anybody requested it or particularly > noticed it was missing... Convenience and compatibility. It's widely used syntax, on github alone `"head -c" language:shell` query returns 22,602 code results. Personal perspective: my embedded linux $DAYJOB uses head -c alot. > > 2) On ubuntu "echo hello | head -c 0" produces no output. This one looks > like it falls back to line based behavior? No, it does not. I've just tested my implementation and it produces no output either. > > 3) The ubuntu version has a more complicated -c behavior than you > implemented, "head -c -6600 README" currently prints the first 24 bytes > of that file. Why did you stop there? Why do we need this part but not > all of it? (Our tail already implements the -c +k behavior, but somebody > had an existing use case that needed it...) It's just that I don't need negative values. But hey - we could merge head.c and tail.c together. > > 4) I am really uncomfortable pointing to posix _and_ a man page as a > spec. (The old saying "A person with one watch always knows the time, a > person with two is never sure."*) There are two other files that use man > pages as their spec, and it's because neither posix nor lsb specify > nsenter/unshare/partprobe. I'd rather just add it to a "deviations from > posix" section if it's a posix command... Reasonable. > > *shrug* I admit this a more convenient syntax than doing it with dd > (which is the first thing that comes to mind for me), but could you > explain your reasoning for this patch a bit more? And/or any second > opinions out there? > > Thanks, > > Rob > > * A person with three or more is going to have an endlessly expanding > todo list, you can just tell. I say this having spent months wrestling > with https://www.navcen.uscg.gov/pubs/gps/sigspec/gpssps1.pdf which > requires _5_ nanosecond-accurate clocks to accurately tell you where you > are. 4 in the satellites, one in the receiver. ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH] netcat: make -l exit after handling a request
On Sun, Jun 25, 2017 at 12:14 PM, Rob Landley 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@cyclops2:/android/upstream/toybox$ echo foo | ./toybox nc localhost 1234 foo jmgao@cyclops2:/android/upstream/toybox$ echo bar | ./toybox nc localhost 1234 jmgao@cyclops2:/android/upstream/toybox$ echo baz | ./toybox nc localhost 1234 jmgao@cyclops2:/android/upstream/toybox$ # Terminal 2 jmgao@cyclops2:/android/upstream/toybox$ echo foo | ./toybox nc -l -p 1234 foo bar baz ^C jmgao@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. ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net
Re: [Toybox] [PATCH v2 1/1] teach head -c
On 06/01/2017 01:36 AM, Ilya Kuzmich wrote: > ping? Let's see... >> Not POSIX, but implemented in coreutils, busybox and freebsd. 1) Do you have a use case for this? Or did you implement this because it's there? Denys added it to Busybox on February 25, 2013 but no message titles in the busybox mailing list around then mention "head" (I checked from February 2013 back to the previous November). I couldn't a bug report in https://bugs.busybox.net/buglist.cgi?quicksearch=head either. So it looks like when busybox was ~15 years old Denys added this because he could, not because anybody requested it or particularly noticed it was missing... 2) On ubuntu "echo hello | head -c 0" produces no output. This one looks like it falls back to line based behavior? 3) The ubuntu version has a more complicated -c behavior than you implemented, "head -c -6600 README" currently prints the first 24 bytes of that file. Why did you stop there? Why do we need this part but not all of it? (Our tail already implements the -c +k behavior, but somebody had an existing use case that needed it...) 4) I am really uncomfortable pointing to posix _and_ a man page as a spec. (The old saying "A person with one watch always knows the time, a person with two is never sure."*) There are two other files that use man pages as their spec, and it's because neither posix nor lsb specify nsenter/unshare/partprobe. I'd rather just add it to a "deviations from posix" section if it's a posix command... *shrug* I admit this a more convenient syntax than doing it with dd (which is the first thing that comes to mind for me), but could you explain your reasoning for this patch a bit more? And/or any second opinions out there? Thanks, Rob * A person with three or more is going to have an endlessly expanding todo list, you can just tell. I say this having spent months wrestling with https://www.navcen.uscg.gov/pubs/gps/sigspec/gpssps1.pdf which requires _5_ nanosecond-accurate clocks to accurately tell you where you are. 4 in the satellites, one in the receiver. ___ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net