From d0bcc8d922f83e4137574f721cec6371b086b561 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 16 Nov 2017 13:59:37 -0800 Subject: 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 {} + --- toys/posix/find.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'toys/posix/find.c') 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++) -- cgit v1.2.3