summaryrefslogtreecommitdiffstats
path: root/exec.c
Commit message (Collapse)AuthorAgeFilesLines
* util: New close() wrappers to check for EBADF and preserve errnoTavian Barnes2022-01-181-7/+3
|
* exec: Add a bit of backoff during ARG_MAX bisectionTavian Barnes2021-11-231-7/+11
| | | | | This reduces the number of E2BIGs we see if binary search reaches the top of the possible range.
* exec: Find ARG_MAX with binary search after E2BIGTavian Barnes2021-11-171-14/+65
| | | | | | | | | | | | | | | | | | | | | 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
* spawn: Allow NULL envp for the current environmentTavian Barnes2021-06-131-1/+1
|
* eval: Raise RLIMIT_NOFILE if possibleTavian Barnes2021-05-201-0/+10
| | | | | | 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()).
* Use `<< {10,20,...}` instead of `*1024*1024...`Tavian Barnes2021-05-201-1/+1
|
* Include what I useTavian Barnes2020-11-121-2/+1
| | | | Thanks to https://github.com/include-what-you-use/include-what-you-use
* exec: Adjust some calling conventionsTavian Barnes2020-10-061-3/+3
|
* diag: New bfs_perror() functionTavian Barnes2020-10-051-2/+2
|
* Rename struct cmdline to bfs_ctxTavian Barnes2020-09-271-12/+12
| | | | | The API remains similar, with some added accessor functions for lazy initialization of the pwcache and mtab.
* exec: Output a human-readable description of terminating signalsTavian Barnes2020-09-231-1/+5
|
* diag: Unify debug printingTavian Barnes2020-06-021-2/+4
|
* exec: Warn if a command dies abnormallyTavian Barnes2020-03-151-7/+4
|
* exec: Mark a formatting function as BFS_FORMATTERTavian Barnes2019-07-051-0/+1
|
* exec: Assert that at_fd is the immediate parentTavian Barnes2019-06-161-0/+3
|
* diag: Unify diagnostic formattingTavian Barnes2019-01-021-6/+5
| | | | | | 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.
* exec: Reject -exec \; without a commandTavian Barnes2018-11-141-0/+5
| | | | | | | | | | | 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 {} \;
* spawn: New posix_spawn()-like API for execTavian Barnes2018-09-181-58/+40
|
* exec: Don't leave zombies around if the child fails to exec()Tavian Barnes2018-09-121-10/+10
|
* exec: More fixes for bfs_exec_debug() changing errnoTavian Barnes2018-09-101-3/+4
|
* exec: Add some debugging info about failed commandsTavian Barnes2018-07-081-5/+19
|
* exec: Make ARG_MAX accounting a bit less restrictive with large pagesTavian Barnes2018-07-071-3/+6
| | | | | | | | | | | | | | | | | | | 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>
* exec: Don't assume bfs_exec_debug() doesn't change errnoTavian Barnes2018-06-251-4/+3
|
* exec: Fix size accounting when recovering from E2BIGTavian Barnes2018-02-101-4/+6
|
* exec: Avoid a warning when building with _FORTIFY_SOURCETavian Barnes2018-02-061-1/+6
| | | | | Also, don't pass the address of errno itself to write(), since write() is allowed to modify it.
* exec: Minor whitespace consistency fixTavian Barnes2017-11-131-1/+1
|
* exec: Recover from E2BIGTavian Barnes2017-11-121-18/+77
|
* exec: Make argument size tracking robust to page-granularity accountingTavian Barnes2017-10-261-3/+8
| | | | | | | | 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.
* exec: Apply more headroom to avoid E2BIGTavian Barnes2017-10-221-4/+16
| | | | | | | | | | | | | 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.
* opt: Separate optimization from parsingTavian Barnes2017-09-161-1/+1
|
* exec: Fix more corner cases with -ok ... +Tavian Barnes2017-07-291-9/+10
| | | | -ok should look for a ; even if it sees {} +, according to POSIX.
* exec: Don't allow anything between {} and +Tavian Barnes2017-07-291-75/+30
| | | | | | | | | 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.
* util: Define O_DIRECTORY to 0 if it's not already definedTavian Barnes2017-07-291-5/+1
|
* Re-license under the BSD Zero Clause LicenseTavian Barnes2017-07-271-10/+15
|
* Handle yes/no prompts correctly according to the localeTavian Barnes2017-07-151-7/+1
|
* exec: Clear errno when a multi-exec doesn't failTavian Barnes2017-07-081-1/+6
| | | | | | | 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.
* Implement -D execTavian Barnes2017-05-091-5/+44
|
* exec: Treat -1 from _SC_ARG_MAX as "unlimited"Tavian Barnes2017-04-301-1/+1
|
* exec: Interpret ARG_MAX corretly.Tavian Barnes2017-04-151-33/+111
| | | | Thanks to https://www.in-ulm.de/~mascheck/various/argmax/
* exec: close() the working directory even if !ftwbufTavian Barnes2017-04-151-1/+1
|
* Implement -exec/-execdir ... +Tavian Barnes2017-04-151-0/+456