aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2019-10-29Let "find -L -type -l" find dangling symlinks.Rob Landley
2019-10-27macOS: implement posix_fallocate().Elliott Hughes
2019-10-27Tar extract should delete files or symlinks where it's making a directory,Rob Landley
but --restrict checking should run on the path up to the last component before unlinking so tar can't be tricked into deleting random files off the system.
2019-10-26Add ln -r and relative_path() to lib, plus test.Rob Landley
And a few small cleanups while I was there.
2019-10-23Use adjtimex instead of adjtime (bionic hasn't got adjtime).Rob Landley
And check in more multicast support that's been sitting in the tree, I don't have a test enviornment for it anymore but somebody wanted this...
2019-10-21Remove getdirname(), it's _not_ a drop-in replacement for dirnameRob Landley
(it returns a malloc), and doesn't match the object lifetime of getbasename() (which always returns some or all of its argument string). The dirname() in libc modifies its argument string, but that's what posix says to do: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/dirname.html so I guess we can live with it.
2019-10-21lib: getdirname fix seqfault on null ptrJarno Mäkipää
In order to be used as drop in replacement for dirname() If path is a null pointer or points to an empty string, dirname() shall return a pointer to the string "." .
2019-10-19Use the MKPATH macros in the mkpathat() implementation.Rob Landley
2019-10-18Teach getdirname() to return "." as appropriate.Rob Landley
2019-10-12Sigh, second attempt at removing strlen() from strstart().Rob Landley
2019-10-10The __ANDROID_NDK__ symbol is missing from ndk-r20 but Dan Albert pointedRob Landley
out clang's __has_include(), and && shorts out the eval for gcc.
2019-10-09Don't strlen() potentially long target string each call to strstart().Rob Landley
The downside is we don't use assembly optimized libc comparison functions, but the common case is short/no matches until full match. Probably net win.
2019-10-03Oops, part of the old tar support fix is in lib, check that in too.Rob Landley
2019-09-18Get exit code right when command intercepts signal, make timeout useRob Landley
xwaitpid(), fix off by one in xwaitpid().
2019-08-26xargs: add --max-args synonym, -o option, and fix -p.Elliott Hughes
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).
2019-08-26Try to make ls failure more graceful. Print ? ? ? entries instead of error msg.Rob Landley
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()
2019-08-21Add xgetline (which the last sh checkin used, oops).Rob Landley
2019-08-15linestack.c: fix buffer length.Elliott Hughes
GCC 8.2 (which my laptop appears to have been quietly upgraded to) points out that the %04X of an int might actually take 8 characters; between that, the "U+", and the trailing NUL, we're gonna need a bigger boat...
2019-08-12sort: move off get_rawline.Elliott Hughes
This was the last user of get_rawline, which lets us remove it.
2019-08-09find: fix dangling symlink behavior.Elliott Hughes
ENOENT is ignored, but other errors are reported.
2019-08-04Add TOYFLAG_MAYFORK and annotate a couple commands.Rob Landley
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)...
2019-07-31Move the empty regex workaround into xregcomp.Elliott Hughes
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.
2019-07-31Fix error path and tweak comments.Rob Landley
2019-07-24Avoid double-close of fd in loopfiles_lines.Elliott Hughes
Test: no EBADF in `strace -e close ./toybox tac /proc/version`
2019-07-22Start replacing get_line() with getline().Elliott Hughes
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...
2019-07-13net.c: add missing static.Elliott Hughes
Pointed out during code review of the recent refactor.
2019-07-12pidof: fix default behavior, add -x.Elliott Hughes
Before this patch, we're effectively doing `pidof -x` all the time. This patch changes names_to_pid() to allow us to say whether or not we want to include scripts, and adjusts the callers appropriately. Also add tests for `pidof` versus `pidof -x` which pass after this patch, without regressing the existing killall tests.
2019-07-11bind/connect cleanup.Elliott Hughes
Rename the existing xbind/xconnect to xbindany/xconnectany, to make room for new xbind/xconnect that are more like 'x' versions of the regular bind and connect. Move explicit bind/connect callers over to xbind/xconnect. Of the affected commands, only netcat is actually used by Android. It was the most recent patch to netcat that made the lack of a more traditional xbind/xconnect apparent.
2019-07-10dd: iflags, oflags, fix ^C, fix the fundamental loop.Elliott Hughes
Investigating why the toybox tar tests fail on Android with toybox dd, I realized I was rewriting a part of dd I'd rewritten before! This is a re-send of my 2019-02-22 patch, rebased against the current ToT... This patch was originally motivated because after suggesting to the author of https://stackoverflow.com/questions/17157820/access-vdsolinux/54797221#54797221 that he could tell dd to work in bytes rather than blocks, I realized that our dd doesn't actually support that. But the rewrite of the main loop is necessary to fix the incorrect output from the dd calls in the tar test. Without this patch, `yes | dd bs=65536 count=1 > fweep` basically gives random output, based on how many bytes the pipe feels like giving you in your first read. (As far as I know, dd *without* bs= was fine, but I can't guarantee that that's true, just that I haven't seen it fail.) Also switch to TAGGED_ARRAY and comma_* for conv rather than add two more copies of an undesired idiom. It turned out -- contrary to the belief of cp(1) -- that comma_scan isn't suitable for this because of its magic handling of "no" prefixes. (It's actually harmless in cp because none of the --preserve options begin with "no", but some dd options do.) To this end, comma_remove is a less-magic comma_scan. I've also changed an `if` to a `while` because other implementations allow things like `--preserve=mode,mode` or `conv=sync,sync`. (If we decide this is a bug rather than a feature, we should at least fix the error message to be clear that we're rejecting the *duplication*, not the option itself.) I've also fixed the ^C behavior by simply adding a direct SIGINT handler rather than trying to be clever inside the read loop (which is why we weren't handling the SIGINT until the read returned). I've also removed `strstarteq` and just added the '=' to each literal when calling regular `strstart`. Plus basic tests.
2019-07-10Add dlist_lpop() to remove last entry (use dlist as stack).Rob Landley
2019-07-06killall: better handling of long names.Elliott Hughes
Change names_to_pid() so that we can actually match shell scripts with long names (the code to get the shell script's name was correct, but there was an extra test preventing us from actually comparing it to the sought name). In kill.c itself, remove a dead test for -l and switch to the FLAG() macro. Also extend the tests to explicitly cover long and short names.
2019-06-25lib/args.c: add quotes.Elliott Hughes
This failure was a little hard to parse: tar: Unknown option mode (see "tar --help") This would have been clearer: tar: Unknown option 'mode' (see "tar --help")
2019-06-20The O_PATH breaks stuff, have to work around Android's selinux rules for /Rob Landley
some other way.
2019-06-20Teach dlist_pop() to work on a dlist_terminate()d listRob Landley
2019-06-11Add DIRTREE_STATLESS to return entries we couldn't stat().Rob Landley
Sets ->again |= 2 when that happens and ->st is zeroed. While we're there, don't memset(st) and then memcpy(st) over it, and use O_PATH in the open().
2019-06-11Move sig_to_num and num_to_sig into portability.c.Elliott Hughes
macOS doesn't have real-time signals, and it has a slightly different set of non-portable signals from Linux. With this, the toybox `kill -l` output matches the default macOS kill(1).
2019-06-10Improve signal name<->number conversions.Elliott Hughes
Include all the signals, not just the POSIX ones. In particular, improve support for real-time signals. My attempt to switch AOSP builds over to toybox timeout got reverted when I broke the ART build bots which use SIGRTMIN+2. Also fix `kill -l 3` to show "QUIT" and `kill -l QUIT` to show "3". Also make the `kill -l` output include numbers and names, and format it to look better on a 80x24 tty, because it's always August 1978 somewhere.
2019-06-08macOS: numerous fixes.Elliott Hughes
This patch adds a BSD version of xgetmountlist (for the path == NULL case only), tested on macOS. It also papers over the differences between macOS' and Linux's xattr APIs. For once I think the macOS one is better. The imitation of mknodat I've had to write swings things back in Linux's favor though. BSD calls f_frsize by the name f_iosize instead. (FWIW, it looks like this is meaningless on Linux and actually meaningful on macOS.) I've added one #if to toys/ --- I'm calling pathconf in stat.c to work around the absence of f_namelen, and have left a TODO with an explanation. I'm not sure what the best fix is here, so punting. No-one can agree what f_fsid is, even if they're all basically the same, so work around the `val` versus `__val` issue between macOS and Linux. With this patch, it's now possible to build cp/mv/install and stat for macOS too. (Which completes the set of "toybox commands currently used on Linux as part of the AOSP build" if you ignore stuff that deals with processes, which I doubt we'll ever be able to support for lack of any API.)
2019-06-07Remove getprop, setprop, start, and stop from toyboxTom Cherry
These are Android specific, so not really helping the outside community, and are getting more and more Android dependencies to work correctly, so let's drop these from toybox and build them within Android. Change-Id: Ic6022f1f506e10868c61f55d64fa4e7c1b14eba2
2019-06-03tail: fix macOS build.Elliott Hughes
Trivial breakage from the recent refactoring. Also add tail to the default config for macOS. I'm still unconvinced that CONFIG_TAIL_SEEK makes sense in a world where inotify support is always built in, but that's an argument for another day...
2019-06-01Teach file to recognize xz archives and old style tarballs.Rob Landley
2019-05-25find: add -printf support.Elliott Hughes
This only implements the format specifiers that I've seen used in the wild (which is actually a significant fraction of the total supported by findutils' find). The most obvious gap is in the time support. I'm happy to add more, but didn't want to add stuff "just because". I'd say %A@, %C@, and -- for SELinux users -- %Z are probably the most plausibly useful formats still missing. I don't think the human-readable date formatting is particularly useful unless someone's seen it actually used in the wild. The %T+ "full ISO" format being the most likely exception to that. Anyway, this is enough for me get started building AOSP with toybox find.
2019-05-25Move notify.c into portability.c (collate the #ifdefs), move global variablesRob Landley
into a structure passed as arguments, add x prefix to functions that can fail, add overflow test.
2019-05-25tail: support -f on BSD too.Elliott Hughes
Factor out the inotify code and add a kqueue equivalent. Specifically tested on macOS 10.14, but I assume this works for other BSDs too, given that I worked from the FreeBSD man page...
2019-05-19Don't complain about short writes to stdout.Rob Landley
2019-05-16Add human_readable_long() for more than 3 digits of output.Rob Landley
2019-05-13Comment tweak.Rob Landley
2019-05-12Fix readlink0() to blank string on failure.Rob Landley
2019-05-11Teach tar to extract type 'S' sparse file headers.Rob Landley
2019-05-06Greatly simplify and speed up regexec0() using REG_STARTEND.Rob Landley
This is a 15 year old freebsd extension (presumably thus also available on MacOS) that glibc adopted in 2004, uClibc adopted in 2005, and bionic supports. The only thing that DOESN'T support it is musl, once again because its maintainer explicitly decided not to (https://www.openwall.com/lists/musl/2013/01/15/26), so add an #ifdef to let musl stay uniquely broken. (It'll stop at first NUL, everything else can match NULs). Finally fixes "s/x/y/g on a megabyte line of x's takes forever" issue.