summaryrefslogtreecommitdiffstats
path: root/exec.c
AgeCommit message (Collapse)Author
2022-03-27parse: Highlight command line errorsTavian Barnes
2022-03-13exec: Check for errors when printing the -ok promptTavian Barnes
2022-03-13exec: Don't flush if the user says no to -okTavian Barnes
2022-03-13ctx: Factor out exec flushing behaviour into bfs_ctx_flush()Tavian Barnes
2022-03-12Don't shadow standard headersTavian Barnes
@italic on the AUR stated that bfs from the AUR fails to build on Manjaro. From the build log, it seems like <time.h> doesn't get included properly. I assume it's picking up ./time.h instead. I couldn't reproduce the build issue in the default configuration, but it does fail with EXTRA_CFLAGS="-I." which isn't good. So rename everything with an x prefix to stop clashing. Link: https://aur.archlinux.org/packages/bfs#comment-856102 Link: https://paste.rs/eqR
2022-02-11exec: Flush I/O streams before executing anythingTavian Barnes
Otherwise output from commands may appear unexpectedly earlier than output from bfs. We use fflush(NULL) to flush all streams, which is more than GNU find does, but seems to be a useful extension.
2022-01-18util: New close() wrappers to check for EBADF and preserve errnoTavian Barnes
2021-11-23exec: Add a bit of backoff during ARG_MAX bisectionTavian Barnes
This reduces the number of E2BIGs we see if binary search reaches the top of the possible range.
2021-11-17exec: Find ARG_MAX with binary search after E2BIGTavian Barnes
Previously we would shrink the command by one argument at a time until a successful execution. This is okay if the ARG_MAX estimate is just a little bit off, but is terribly slow when it's off by a lot. One situation where it's very far off is when a 32-bit build of bfs launches a 64-bit binary. In this case, bfs thinks the argv pointers are 4 bytes, while they actually take up 8 bytes. The performance is quite bad: $ time ./bfs-64 ~/code/linux -exec echo {} + >/dev/null ./bfs-64 ~/code/linux -exec echo {} + > /dev/null 0.03s user 0.07s system 99% cpu 0.095 total $ time ./bfs-32 ~/code/linux -exec echo {} + >/dev/null ./bfs-32 ~/code/linux -exec echo {} + > /dev/null 0.08s user 10.33s system 100% cpu 10.390 total After this change, performance is much better: $ time ./bfs-32 ~/code/linux -exec echo {} + >/dev/null ./bfs-32 ~/code/linux -exec echo {} + > /dev/null 0.03s user 0.08s system 99% cpu 0.110 total
2021-06-13spawn: Allow NULL envp for the current environmentTavian Barnes
2021-05-20eval: Raise RLIMIT_NOFILE if possibleTavian Barnes
This lets us keep more open FDs cached in bftw(). The limit is lowered before running -exec commands, in case they're incompatible with a high limit (e.g. due to select()).
2021-05-20Use `<< {10,20,...}` instead of `*1024*1024...`Tavian Barnes
2020-11-12Include what I useTavian Barnes
Thanks to https://github.com/include-what-you-use/include-what-you-use
2020-10-06exec: Adjust some calling conventionsTavian Barnes
2020-10-05diag: New bfs_perror() functionTavian Barnes
2020-09-27Rename struct cmdline to bfs_ctxTavian Barnes
The API remains similar, with some added accessor functions for lazy initialization of the pwcache and mtab.
2020-09-23exec: Output a human-readable description of terminating signalsTavian Barnes
2020-06-02diag: Unify debug printingTavian Barnes
2020-03-15exec: Warn if a command dies abnormallyTavian Barnes
2019-07-05exec: Mark a formatting function as BFS_FORMATTERTavian Barnes
2019-06-16exec: Assert that at_fd is the immediate parentTavian Barnes
2019-01-02diag: Unify diagnostic formattingTavian Barnes
This adds a bfs: prefix to error/warning messages for consistency with other command line tools, and leaves only the "error:"/"warning:" part colored like GCC. It also uniformly adds full stops after messages.
2018-11-14exec: Reject -exec \; without a commandTavian Barnes
Prior to this, we'd fork and then segfault on every file as NULL was passed to execvpe(). Found while looking through old FreeBSD find bugs: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=36521 bfs still supports the (dubious, possibly unintentional?) GNU find extension to POSIX that allows $ bfs -exec {} \;
2018-09-18spawn: New posix_spawn()-like API for execTavian Barnes
2018-09-12exec: Don't leave zombies around if the child fails to exec()Tavian Barnes
2018-09-10exec: More fixes for bfs_exec_debug() changing errnoTavian Barnes
2018-07-08exec: Add some debugging info about failed commandsTavian Barnes
2018-07-07exec: Make ARG_MAX accounting a bit less restrictive with large pagesTavian Barnes
For Linux-style accounting, we really only need to handle a single page of wasted space due to rounding. Subtracting two pages for extra headroom was reasonable on systems with 4K pages, but overkill on systems like ppc64le with 64K pages. Worse yet was the fact that Alpine Linux only gives us 128K for arguments. Instead, only subtract a single page, plus the POSIX-recommended 2048 bytes. Credit to Mike Sullivan for the initial patch and testing on Alpine ppc64le. Fixes: http://build.alpinelinux.org/buildlogs/build-edge-ppc64le/testing/bfs/bfs-1.2.2-r0.log Co-authored-by: Mike Sullivan <mksully22@gmail.com>
2018-06-25exec: Don't assume bfs_exec_debug() doesn't change errnoTavian Barnes
2018-02-10exec: Fix size accounting when recovering from E2BIGTavian Barnes
2018-02-06exec: Avoid a warning when building with _FORTIFY_SOURCETavian Barnes
Also, don't pass the address of errno itself to write(), since write() is allowed to modify it.
2017-11-13exec: Minor whitespace consistency fixTavian Barnes
2017-11-12exec: Recover from E2BIGTavian Barnes
2017-10-26exec: Make argument size tracking robust to page-granularity accountingTavian Barnes
From looking at the Linux exec() implementation, it seems a big part of the reason we needed extra headroom was that the arguments/environment are copied page-by-page, so even a small accounting difference could result in an error of an entire page size. Grow the headroom to two entire pages to account for this.
2017-10-22exec: Apply more headroom to avoid E2BIGTavian Barnes
I ran into "argument list too long" errors with a bfs -type f -exec grep pattern '{}' + command, despite the current accounting being pretty careful. Some experimentation showed that an additional 2048 bytes of headroom is always safe. While we're at it, explicitly account for the terminating NULL pointers in argv and environ.
2017-09-16opt: Separate optimization from parsingTavian Barnes
2017-07-29exec: Fix more corner cases with -ok ... +Tavian Barnes
-ok should look for a ; even if it sees {} +, according to POSIX.
2017-07-29exec: Don't allow anything between {} and +Tavian Barnes
POSIX explicitly forbids this extension: > Only a <plus-sign> that immediately follows an argument containing > only the two characters "{}" shall punctuate the end of the primary > expression. Other uses of the <plus-sign> shall not be treated as > special.
2017-07-29util: Define O_DIRECTORY to 0 if it's not already definedTavian Barnes
2017-07-27Re-license under the BSD Zero Clause LicenseTavian Barnes
2017-07-15Handle yes/no prompts correctly according to the localeTavian Barnes
2017-07-08exec: Clear errno when a multi-exec doesn't failTavian Barnes
This fixes strange "Inappropriate ioctl for device" errors when using -exec ... + with output redirection. errno was set to ENOTTY by the isatty() call during startup for color auto-detection, and never cleared before eval_exec() wants to check if anything went wrong.
2017-05-09Implement -D execTavian Barnes
2017-04-30exec: Treat -1 from _SC_ARG_MAX as "unlimited"Tavian Barnes
2017-04-15exec: Interpret ARG_MAX corretly.Tavian Barnes
Thanks to https://www.in-ulm.de/~mascheck/various/argmax/
2017-04-15exec: close() the working directory even if !ftwbufTavian Barnes
2017-04-15Implement -exec/-execdir ... +Tavian Barnes