Age | Commit message (Collapse) | Author |
|
I really needed to be able to edit a file on the device, and this was
the nearest thing handy, and it turns out to be more or less usable for
basic editing, so...
Support cursor keys.
Support :q (since there's currently no record of whether the file's
modified or not, :q is the same as :q!).
Add 'A' to insert at end of line.
Add 'n' to find next after '/'.
Fix backspace all the way to get out of ex command mode.
Fix escape sequences to not hard-code assumptions about the terminal's
default background and foreground colors.
Fix 'spesial' typo for 'special', and remove explicit array sizes.
|
|
If you accidentally configure the sha-3 sums on, but don't enable
libcrypto, you'll get toys that just output md5 sums instead. This patch
doesn't cause a build-time error (my original plan), but does at least
ensure that toybox refuses to include incorrect sha-3 sum
implementations.
|
|
does CLOEXEC (should fix macos build).
|
|
I think when I wrote this I tested the named escapes like \n and hex
escapes, and when I found \x wasn't supported I didn't even think of
octal. And I only learned about \c when I was looking at echo and printf
to compare their escape implementations a few weeks back.
Add the missing escapes and corresponding tests.
Fixes #139.
|
|
This broke a netd test (but sadly in postsubmit rather than presubmit).
Also add a trivial test that would at least have caught this bug.
Bug: http://b/140453237
|
|
|
|
Commit c26870dab3462c6176936384b090df6b9ba46dee broke ls' error
reporting for files that don't exist. `ls $F` is used by some as an
equivalent of `test -e $F`.
This patch also adds a regression test.
|
|
This fixes the case where someone's done something (weird) like:
find src/*.c -name foo.c
Previously the match would fail because one side of the comparison was
already a path.
|
|
as unusual timestamp formats
After further research and testing, I've produced a patch which handles
all filenames with special characters by copying the GNU quoting
behavior, and also treats anything following a tab as a timestamp. This
increases both ability to handle possible filenames and ability to
apply patches found in the field.
In diff, quote and escape filenames according to the following rules.
* Surround the filename with quotes if it contains a byte less than 0x20,
a byte greater than or equal to 0x80, space, backslash, or quote.
* Replace alert, backspace, form feed, newline, carriage return, tab, vertical
tab, backslash, and quote with \a, \b, \f, \n, \r, \t, \v, \\, and \",
respectively.
* Replace other bytes less than 0x20 or greater than or equal to 0x80 with a
backslash followed by the three octal digits representing the value of the
byte.
* Treat valid UTF-8 characters involving sequences of bytes greater than or
equal to 0x80 the same as other sequences of such bytes.
In patch, process quoted and escaped filenames according to the following
rules.
* If the filename does not begin with a quote, do not modify the filename.
* Remove quotes surrounding the filename.
* In quoted filenames, replace \a, \b, \f, \n, \r, \t, \v, \\, and \" with
alert, backspace, form feed, newline, carriage return, tab, vertical tab,
backslash, and quote, respectively.
* In quoted filenames, replace a backslash followed by octal digits with the
byte with that value in octal.
Also, in patch, treat anything on a +++ or --- line following a tab character
after the beginning of the filename as a timestamp, rather than part of the
filename.
|
|
if true; then if false; then echo one; elif echo two; then echo three; else echo four; fi; fi
|
|
Unlike ls, find does treat ENOENT specially. Add an extra test (and fix
the behavior) for the case of ENOENT for a path provided on the command
line --- unlike other ENOENT cases (typically dangling symlinks), ENOENT
for a command line argument should report an error.
Also remove obsolete `|sed` from the symlink loop test.
|
|
The Linux kernel uses the --max-args synonym for -n.
Barbarians who use vi need xargs' -o to be able to do something like:
find -name xargs.c | xargs vi # Sad vi.
find -name xargs.c | xargs -o vi # Happy vi.
The -p option needs fixing to read from /dev/tty because stdin is
otherwise occupied in xargs. I think xargs is the only place that needs
this, so it didn't seem sensible to make all callers to yesno() be
specific about which they wanted, hence the new function.
Also remove the documentation for the build-time XARGS_PEDANTIC option
which isn't actually implemented.
Also add a TODO for -P (which is used by at least one script in the
Linux kernel).
|
|
Tweak DIRTREE_STATLESS so it returns zero stat for any error (I'm testing
that dev, ino, and blksize are all zero), and fill in file type from readdir()
|
|
The "info" pages are something very different from the "intro" pages :-)
do_lines already closes the fd.
Also improve the error message for `man`.
|
|
macOS remains awkward, though, but this retains our Android/Linux
behavior and is closer to the platform's getconf(1) for macOS.
Strictly macOS denies all knowledge of UIO_MAXIOV, but the "undefined"
you'll get from this patch seems closer than the "1024" we used to
give.
|
|
Before:
$ ./rm
rm: Needs 1 argument
$ ./rmdir
rmdir: Needs 1 argument (see "rmdir --help")
After:
$ ./rm
rm: Needs 1 argument (see "rm --help")
|
|
|
|
The behavior with "\xAV" (where the second hex digit is invalid) is
different from the behavior with "\xVA", and echo and printf differ from
each other.
|
|
You can now run:
echo hello;
if true; then echo hello; fi;
while true; do echo hello; done
It's got the start of for loops but needs environment variable resolver
to do much with them.
|
|
|
|
|
|
Subtract the amount we actually read, not what we asked for.
|
|
(revert afe951b19c0f with the table of magic constants). If you want speed,
there's already a config option to use the libssl version instead.
|
|
This was the last user of get_rawline, which lets us remove it.
|
|
This gets the tests passing with both toybox and util-linux 2.32.1
blkid. We use -s to get around the fact that we still don't support ntfs'
$VOLUME_NAME attribute.
|
|
ENOENT is ignored, but other errors are reported.
|
|
Since this masks, it doesn't actually have the same bug as
e5942a8c90c2f52550496fdf08efddb564d8e5a3, but we may as well fix the
other example of that questionable idiom while we're thinking about it...
|
|
There's a race between LOOP_CTL_GET_FREE and LOOP_SET_FD. Work around it
by just retrying if we get EBUSY on the LOOP_SET_FD call. This is what
similar code in ChromeOS already does.
Bug: http://b/135716654
|
|
marshalling for vforked subshells, fix rc returned from run_pipeline for
variable assignment. (Well, sort of: X=$(false) still needs rc = 1.)
|
|
|
|
A TOYFLAG_NOFORK command must run in the context of toysh, but a MAYFORK
can either run standalone or run in the toysh process. MAYFORK means it
cleans up after itself: no leaked resources (malloc, mmap, filehandles, etc),
even in error_exit() paths that would longjmp() back to the shell. It also
doesn't discard anything we need to retain (don't close stdout, change
toys.optargs[] so we can't free it, etc)...
|
|
output 5 digits of octal stat data instead of 4, due to hardwired leading 0
instead of %04a sprintf prefix.
|
|
|
|
No current caller except grep needs this, but consistency seems like a
good idea.
Also change the xregcomp error message to be a bit more human-readable,
rather than mention an implementation detail.
|
|
All regcomp callers are now going through xregcomp.
|
|
We use (char *)1 and (char *)2 to indicate errors (they can never be valid
pointers because both malloc() and mmap() return aligned memory and those
align down to NULL, plus Linux maps 4k at the bottom to catch null
dereferences anyway), and then typecast it to long (trusting in LP64) to
do an integer <=2 comparison... except that needs to be UNSIGNED long or
else pointers in the top half of the virtual memory space become negative
and the <=2 false positives them as errors. (Oops.)
|
|
POSIX says there's no such thing as an empty regular expression. The
grammar excludes the possibility:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html
BSD agrees with POSIX, and Android and macOS' BSD-based implementations
reject the empty regular expression.
GNU apparently disagrees.
Luckily, BSD does accept the empty *sub* expression `()`, despite their
error message for REG_EMPTY being "empty (sub)expression". This is
presumably a bug, except there's explicit code to support it that is at
least 26 years old:
https://github.com/freebsd/freebsd/blame/master/lib/libc/regex/regcomp.c#L383
This workaround also works fine with glibc.
If we want GNU behavior, I'm struggling to come up with another way to
fake it. If we want POSIX behavior, we could easily just add a check to
reject "" on glibc.
Also switch to xregcomp().
|
|
This isn't currently used in AOSP, but it is used in some of the other
codebases I can easily search, and it's a better fix for test flakiness
than inserting a sleep.
|
|
|
|
|
|
|
|
This was basically just to help me think out loud while discussing
loopfiles_lines().
|
|
I started this last night, but thought I'd aim to send multiple small
patches rather than work through all the callers and send one big patch.
I've deliberately chosen the ugly name `allocated_length` because we've
had historical bugs where folks think this a line length in the sense of
the return value. I do wonder whether we should actually have some kind
of getline() wrapper that hides the `char *`/`size_t` pair in lib/,
which makes the function easier to use in most cases but does add the
less common gotcha that you wouldn't be able to getline() through
multiple files at once (which does happen in at least one toy).
But maybe the real fix is to look harder for places where we can just
use loopfiles_lines? Speaking of which, should we actually add two more
arguments to that? Specifically: switch it to getdelim() rather than
getline() behind the scenes, and also add a way to have the trailing
'\n' automatically removed, since that seems to be what most callers
want?
Anyway, that seemed like enough questions that it was time to send this
initial patch out before doing too much more...
|
|
|
|
This was embarrassing... A build script that was using xargs -I silently
started to ignore -I when we switched over to toybox xargs. The owner of
the script has rewritten it to use the shell read builtin instead, but
it's pretty unhelpful to silently ignore an option that radically
changes how xargs behaves. (The -I behavior sounds sufficiently
different from normal behavior that I'm not sure I've understood, and am
just sending this cleanup rather than actually implementing -I correctly.)
Bug: http://b/137832162
|
|
The change from ioctl to xioctl in
844f0d1aae28c54bbb672f53ba2cda182c572129 broke ifconfig for non-root on
Android. SIOCGIFHWADDR has been protected to prevent device tracking
since Nougat.
Bug: https://issuetracker.google.com/137671590
|
|
|
|
The first bug appeared as a memory overwrite, but was actually visible
without hwasan: basically any `grep -F` that let to multiple matches on
the same line was broken.
The second bug was another memory overwrite, visible when I ran the
existing grep tests.
Bug: http://b/137573082
|
|
This fixes the extended attribute settings for the ip route change
command; extended attributes are collected in a separate buffer
and added to the RTM message in a specific RTA_METRICS attribute.
Only added setter support for the RTAX_MTU (per-route MTU), as that
was the only option currently parsed.
Also added support for displaying extended attributes, even those
not currently settable.
|
|
Used by some ART tests and also some LLVM tests. (The motivating example
is the latter, but I noticed the former when looking for other users.)
Bug: http://b/137298656
|