aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-11-16 13:59:37 -0800
committerRob Landley <rob@landley.net>2017-11-21 22:23:18 -0600
commitd0bcc8d922f83e4137574f721cec6371b086b561 (patch)
tree7a3f9d377db54368619c77a5a795a3393dfba14a
parent688e48a6285e42cb7d1ac1313a9169cb94131ee7 (diff)
downloadtoybox-d0bcc8d922f83e4137574f721cec6371b086b561.tar.gz
Make find -exec + obey ARG_MAX just like xargs.
This isn't ideal, but it matches xargs and none of us is likely to have time to do the best possible thing any time soon. Bug: http://b/65818597 Test: ./toybox find /usr/local/google/ndkports/ -exec echo {} +
-rw-r--r--toys/posix/find.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 5c72131d..762f89fc 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -61,6 +61,7 @@ GLOBALS(
struct double_list *argdata;
int topdir, xdev, depth;
time_t now;
+ long max_bytes;
)
struct execdir_data {
@@ -498,10 +499,10 @@ static int do_find(struct dirtree *new)
// Done here vs argument parsing pass so it's after dlist_terminate
aa->prev = (void *)1;
- // Flush if we pass 16 megs of environment space.
+ // Flush if the child's environment space gets too large.
// An insanely long path (>2 gigs) could wrap the counter and
// defeat this test, which could potentially trigger OOM killer.
- if ((aa->plus += sizeof(char *)+strlen(name)+1) > 1<<24) {
+ if ((aa->plus += sizeof(char *)+strlen(name)+1) > TT.max_bytes) {
aa->plus = 1;
toys.exitval |= flush_exec(new, aa);
}
@@ -543,6 +544,7 @@ void find_main(void)
char **ss = toys.optargs;
TT.topdir = -1;
+ TT.max_bytes = sysconf(_SC_ARG_MAX) - environ_bytes();
// Distinguish paths from filters
for (len = 0; toys.optargs[len]; len++)