Age | Commit message (Collapse) | Author |
|
This patch does two things:
1. Enable line buffering for echo and yes. I found this through test
flakiness from the toybox xargs tests running in CI on devices where
"echo" is provided by toybox. For `echo y`, GNU echo does one write
of "y\n" but toybox echo was doing two writes, which makes it more
likely (4% on the heavily-loaded CI machines) for writes from the two
processes to be interleaved.
2. Fix line buffering on glibc if you're calling `toybox foo` rather
than `foo`. Otherwise we come through once and switch to unbuffered
mode, then again and switch to line buffered mode --- which doesn't
seem to actually work in glibc unless you specify a buffer (so
passing toybuf and sizeof(toybuf) works, but NULL and 0 doesn't).
I hit the second issue trying to reproduce the first issue on the desktop
rather than on Android.
(If you're scratching your head wondering "why yes(1) too, not just
echo(1)?", that represents a blind alley I went down when I mistook
which tool was in use. It seemed like the same principle should apply,
and it matches what other implementations do.)
|
|
mostly only safe to use behind a firewall or through a VPN these days.
|
|
Of course "x() { echo hello; } | tr e f; x" allows the pipe but not the call.
Ok, take out the union so you can && after a function declaration.
|
|
|
|
|
|
This got a bit out of hand. All I wanted to fix was the CR conversion to
get this part of https://tools.ietf.org/html/rfc854 right:
Therefore, the sequence "CR LF" must be treated as a single "new
line" character and used whenever their combined action is
intended; the sequence "CR NUL" must be used where a carriage
return alone is actually desired; and the CR character must be
avoided in other contexts. This rule gives assurance to systems
which must decide whether to perform a "new line" function or a
multiple-backspace that the TELNET stream contains a character
following a CR that will allow a rational decision.
But to understand the code well enough to do that, and to fix it so that
it works when IAC or CR sequences are split across multiple reads, I
ended up rewriting a lot:
* Add punctuation in help.
* Remove duplicated #include.
* Remove some unnecessary globals, enlarge the global buffers, and keep
state for correct IAC sequence processing across reads.
* Reduce code duplication and rewrite bits that made no sense.
* Handle entering/exiting raw mode more uniformly.
* Fix the prompt (the character count was wrong).
* Allow ^]^D (like BSD telnet) as well as ^]e to exit, and look less
like we crashed when doing so.
* Simplify the IAC sequence handling, but more importantly work
correctly when a sequence is split across multiple reads.
* Use more of the existing "x" functions from lib. (And remove code that
was duplicating what the "x" functions they'd just called had already
done.)
* Show "Connected to".
* Better signal handling.
I'm still not happy with TELOPT_ECHO and TELOPT_SGA in handle_wwdd(),
but don't (yet) understand them well enough to simplify them further. On
the bright side, I think TELOPT_NAWS is a lot clearer now.
It also occurs to me now I'm looking at the diff that although the IAC
output code is now better than it was, it probably still isn't pulling
its weight and might better be replaced by printf().
...but this patch has already gotten way out of hand!
|
|
After a network outage, a long-running telnetd was spinning trying to
read from a socket that was in TIME_WAIT. It's easy to reproduce this by
using the regular telnet client and typing ^]^D to exit abruptly.
I don't think these sockets should ever have been non-blocking, and we
want to give up on the client if we hit EOF. All of this needs
rewriting to be less complicated (and not use select(2)), but this seems
to be a minimal fix for the spin without harming normal usage (where by
"usage" I mean "testing the telnet client").
|
|
Handling utmp is login's job: telnetd should just pass the appropriate
option to login.
(I was investigating a different bug that caused telnetd to take 100%
CPU after a network outage and noticed an unexpected utmp fd. It turned
out to not be relevant to my actual problem, but it did remind me that
this utmp code isn't right in small details like that, but also in the
bigger picture: it's writing the wrong information, and only on logout,
not login. But rather than try to fix it, let's just let login do its
job.)
|
|
When using -t to inspect an archive, cpio would try to set the owner of
any symlink in the archive, even though the symlink wasn't created by
the command previously.
This would lead to two results, either the command fails with a "No such
file or directory" message when trying to lchown() the symlink path, or
an existing file, with the name of the symlink, is lchown()-ed.
Guard the lchown() function call with a "if (!FLAG(t))" block, and add
regression test for this.
|
|
I've been using hexedit quite a lot, mainly for _corrupting_ files, and
have been meaning to send this collection of changes for far too long
now. I saw a bug requesting editing in the ASCII pane (which this patch
_doesn't_ add), and wanted to get this sent in before it has to undergo
the third massive merge conflict of its existence...
The main "TODO" in this is that I never got round to implementing
searching for an arbitrary byte sequence. It seems like we ought to have
that feature, but personally I'm far more likely to jump to an offset or
to search for some ASCII. I haven't needed to search for arbitrary byte
sequences in all this time, so I'll fix this if/when I actually need
it...
* Enter (new) read-only mode rather than refusing to open read-only
files.
* More keys: page up/page down, home/end, and ctrl-home/ctrl-end for
beginning/end of file.
* Jump with ^J (or vi-like :). Enter absolute address or +12 or -40 for
relative jumps.
* Find with ^F (or vi-like /). No support for bytes, but useful for
finding text. (^G or n for next match, ^D or p for previous match.)
* Support all the usual suspects for "quit": vi-like q, desktop-like ^Q,
panic ^C, or even plain old Esc.
* The ASCII pane is made more readable by (hopefully) reasonable use of
color. Regular control characters are shown in red using the
appropriate letter (so a red A is 0x01, etc), printable characters are
shown normally, and top-bit set characters are just shown as a purple
question mark (since I couldn't come up with a better representation
that had any obvious value --- in my experience top-bit set characters
are either meaningless in ASCII, part of a UTF-8 sequence in modern
files, or in some random code page in ancient files). The choice of
red and purple was to deliberately make these not-actually-ASCII
characters slide into the background; before this patch they have so
many bright pixels (especially with the use of reverse video) that I
couldn't clearly see the *actual* ASCII content in the ASCII pane.
* Addresses are now shown in yellow. No real justification other than "it
looks nice".
* NUL bytes in the hex pane are shown dimmed. I find this helpful
especially when there's a lot of padding, and it can actually be a
useful clue when reverse engineering (you can "see" repeated patterns
more easily), but I can understand if this one's controversial.
* Errors are shown "vim style" in bold white text on a red background,
waiting briefly to ensure they're seen.
* The status bar shows the filename, whether the file is opened
read-only, the current offset into the file, and the total
length of the file.
* SIGWINCH handling has been added.
|
|
The new cpio test that uses setsid fails if you're using the toybox
setsid. Move the setpgrp() call before the vfork() but after the
setsid().
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cached $IFS value has to be per function context because local vars.
|
|
|
|
|
|
|
|
Remove cached blk/pout/urd and make TT.ff->blk always be populated instead
(like TT.ff, list is never empty), have current pipe (and block trailing)
redirections live in current TT.ff->blk.
Left in a bunch of commented debug printfs and a filehandle dump function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Noticed while using telnetd to manually test some telnet fixes: telnetd
would sometimes exit when I'd disconnect because it couldn't find pid 0
on its list of sessions.
I've not seen obscure exits because select() times out, but I've also
changed that `return` to an error_exit() so we'll at least know what's
happened if that ever occurs.
Also use <arpa/telnet.h> rather than manually #define'ing its constants,
use the FLAG() macro throughout, and xsetsockopt(). Don't pointlessly
set errno to 0 at the start of main and then never look at it again.
|
|
The kill(2) should be checking whether `pid` still exists, not the
process that wait(2) just told us has exited.
|
|
(fixes up some test suite tests).
|
|
I've been using toybox vi as a makeshift "less" lately. This patch
contains all the fixes I've made...
$ should go to the last character before the newline, not the newline.
Fix ^b and ^f, and ^e and ^y (which was mistakenly ^u before, which is
also a movement key, but half of ^d/^u, neither of which we actually
implement, and neither of which I've ever used myself --- I might have
large hands, but they're not _that_ large).
Fix the display of lines longer than 1024 characters.
Fix the display of the "~"s after the end of the file, and use VT100 dim
to make it a bit more obvious that they're not actually part of the
file. Also be a bit more consistent about \033 which is the most common
way to write \x1b in toybox.
Don't show the status while in ex mode.
Make what the status is showing a little less unclear by adding a "C"
for the byte offset and file size, and add a percentage (albeit one
based on bytes rather than lines).
Fix the flickering seen on updates with the usual stupid trick of
setting a large buffer.
Handle SIGWINCH.
Add support for Home/End/PageUp/PageDown.
Remove a bit of duplication around calls to draw_page().
|
|
Not fully wired up yet, probably a bunch of regressions.
|
|
I broke this when I added the masking out of the S_IFMT bits for macOS,
because string_to_mode needs the full mode with those extra bits,
specifically so that it can recognize directories for +X to work.
I've duplicated chtest rather than change chtest to explicitly set the
modes to 000 before running the given chmod command because I didn't
want to touch *all* the tests and obscure the addition of just one.
|
|
across one of the issues I forgot to fix. Added a couple comments and
renamed a variable to try to clarify the code while I was there.
|
|
It's legal for a system call to set non-zero errno and return a good
status. The caller (grep) should check return status first.
Test: 2000 loops of greping 1000+ lines each loop
Signed-off-by: Robin Hsu <robinhsu@google.com>
Change-Id: I55f7cd5d8a6289c5e8a21ed3057e995a75b9b4fa
|
|
|
|
|
|
A tar file created by toybox tar with values large enough to need
base-256 rather than ASCII octal caused a tar reader to crash, and
caused GNU tar to complain.
I note from the docs at
https://github.com/libarchive/libarchive/blob/master/libarchive/tar.5#L326
that they imply that only the top *bit* should be set to indicate this
format, not the whole top byte, to give a 95-bit or 63-bit field. But I
don't think we can hit that in practice?
Bug: http://issuetracker.google.com/181683612
|
|
|
|
|
|
Other dd implementations always show the status on exit, whether success
or failure. Fix that by using xsigatexit() (and clarify the comment for
that function a little, since it didn't previously address the "at exit"
part of its behavior at all).
This also fixes SIGUSR1 behavior so that we show the status immediately
rather than on the next trip round the read/write loop.
Tested with `dd of=/dev/full`, sending SIGUSR1 twice from another shell
(to see the status immediately each time, without exiting), then hitting
^C (to see the status and then exiting), then restarting dd and hitting
enter (to see a write error followed by the status before exiting).
Bug: https://issuetracker.google.com/177017283
|
|
|
|
My patch to fix df behavior on macOS broke the stat build on macOS.
First off, we had %s and %S the wrong way round compared to coreutils,
though since Linux always seems to use the same value for both,
no-one will ever have noticed.
Annoyingly, Linux and macOS disagree about what statfs::f_bsize
means, and whether statfs::f_iosize and statfs::f_frsize exist (each
has one or the other, depending on what f_bsize *doesn't* mean to
them). This mess is presumably why statvfs exists.
Unfortunately, statvfs on macOS at least doesn't contain the file
system type information. So we either need to do *both* statfs()
and statvfs() for macOS, or we need to take into account the different
fields.
This patch adds an #ifdef outside of portability.h because I wasn't
sure we actually wanted to add statfs_best_transfer_size() and
statfs_real_block_size() functions to lib for this. But that's an
easy cleanup if desired.
|
|
|
|
And fix one test for NUL that should be a length test for -z support
|
|
On Linux, struct statvfs' f_bsize and f_frsize seem to be
interchangeable. On macOS, they're wildly different. f_bsize is the
"preferred length of I/O requests for files on this file system"
(corresponding to statfs::f_iosize), and f_frsize is the "size in
bytes of the minimum unit of allocation on this file system"
(corresponding to statfs::f_bsize. POSIX appears to say nothing
about the interpretation of these fields, but man7.org's statvfs(2)
page is quite clear that statvfs::f_blocks, for example, is in units
of f_frsize, not f_bsize.
This is the only place in the tree where we use statvfs::f_bsize
(other than the stat(1) output that's supposed to be f_bsize and
that has a corresponding f_frsize dual anyway.
I've removed the Apple-specific #define f_frsize in portability.h
because that seems to have been from my previous attempt to understand
what was going on here. The output of the relevant stat(1) fields
on macOS are the same before/after this patch.
This makes toybox df's output match the system's df on a MacBook
Pro running macOS 11.2.1.
Tested on a Raspberry Pi 400 running Linux too, where I see no
change in the output before/after this patch.
|