aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/xargs.c
AgeCommit message (Collapse)Author
2019-10-09xargs: various fixes.Elliott Hughes
Don't run the command with no arguments if we run out of input but have already run the command at least once. The implementation of "run the command at least once (unless -r was supplied)" wasn't taking into account whether or not this was our first time round the loop. Fix the exit value, and the -- already documented but not implemented -- behavior if a child exits with status 255. Also extend the tests to cover these cases, plus cases I broke while coming up with the fix. Add more tests to convince myself that we've correctly interpreted how -s is supposed to behave, and fix the corner cases at the bottom end of the range. This fixes some issues we were seeing trying to build the Android SDK for (and more importantly, on) macOS.
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-15Fix two typos.Elliott Hughes
2019-07-30Fix signed typecast bug.Rob Landley
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.)
2019-07-19xargs: don't pretend to support -I.Elliott Hughes
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
2019-07-11xargs: bug compatibility with BSD/busybox/findutils.Elliott Hughes
The other xargs implementations in the wild don't seem to count the space taken by each `char *`. Go for bug compatibility unless future experience proves that to be a bad idea.
2019-01-22Whitespace: remove tabs from indentation.Elliott Hughes
I accidentally added a tab in xargs.c, so as penance I'll clean up all the tabs.
2019-01-18xargs: make --help match reality.Elliott Hughes
Implement -p, -t, and -r. Add some missing tests. Move -L and -x back to TODO since they're not implemented and I haven't yet even understood what they're supposed to do.
2018-12-04Add FLAG(x) macro, expanding to (toys.optflags & FLAG_##x)Rob Landley
2018-08-25Coding style change: 1) Use argument letter for variable names filled out byRob Landley
that argument (so "t:" fills out TT.t), 2) go ahead and collate arguments of same type on same line. (Order's guaranteed by C99 either way.)
2017-12-26Fix xargs -0 with -n.Elliott Hughes
Also make -0 and -E mutually exclusive (rather than just ignore -E with -0). Bug: https://github.com/landley/toybox/issues/78
2017-10-01Fix xargs to obey POSIX's ARG_MAX restrictions.Elliott Hughes
This avoids "xargs: exec echo: Argument list too long" errors in practice. find(1) needs to be fixed too, but that's a bit more complicated and a working xargs provides a workaround. Bug: http://b/65818597 Test: find /proc | strace -f -e execve ./toybox xargs echo > /dev/null
2015-09-29Make defconfig build for nommu.Rob Landley
Adds XVFORK() macro, teaches xpopen_both() to call /proc/self/exe with NULL argv (and converts cpio -p to use that), adds TOYBOX_FORK guards to some unconverted commands.
2015-09-23Add xvfork() as a static inline and use it from various places.Rob Landley
Note: vfork(), like fork(), can return -1 if too many processes, and we should notice and fail loudly.
2015-05-31Move the magic list of commands needing cleanup from toys/pending/READMERob Landley
to greppable TODO annotations in the individual files. (grep -riw TODO)
2014-05-31Introduce xfork() and make commands use it, and make some WEXITSTATUS() use ↵Rob Landley
WIFEXITED() and WTERMSIG()+127.
2013-10-31Patch from William Haddon to make xargs with blank input call its command ↵Rob Landley
line once. (Tweaked slightly for whitespace and to collate variable declarations.)
2013-07-06This inlines CRC64, and nothing more.Isaac Dunham
The functions involved were called only once.
2012-11-13Reindent to two spaces per level. Remove vi: directives that haven't worked ↵Rob Landley
right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
2012-10-08New build infrastructure to generate FLAG_ macros and TT alias, #define ↵Rob Landley
FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
2012-08-25Move commands into "posix", "lsb", and "other" menus/directories.Rob Landley