From f92f1d0181853b989f9377debb56902e3e21c9a8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 22 Jun 2014 13:54:40 +0200 Subject: find: use sysconf(_SC_ARG_MAX) to determine the command-line size limit The find utility uses a hardcoded value of 32 * 1024 as the limit of the command-line length when calling 'find -exec ... {} +'. This results in over 4 times more execve() calls than in coreutils' find. This patch uses the limit defined in system headers. Based on the patch by Bartosz Golaszewski . Signed-off-by: Denys Vlasenko --- findutils/find.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'findutils/find.c') diff --git a/findutils/find.c b/findutils/find.c index 493f72e61..56a7ed3ab 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -419,6 +419,7 @@ struct globals { smallint need_print; smallint xdev_on; recurse_flags_t recurse_flags; + IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;) } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) #define INIT_G() do { \ @@ -428,6 +429,7 @@ struct globals { /* we have to zero it out because of NOEXEC */ \ memset(&G, 0, sizeof(G)); \ IF_FEATURE_FIND_MAXDEPTH(G.minmaxdepth[1] = INT_MAX;) \ + IF_FEATURE_FIND_EXEC_PLUS(G.max_argv_len = bb_arg_max() - 2048;) \ G.need_print = 1; \ G.recurse_flags = ACTION_RECURSE; \ } while (0) @@ -677,7 +679,7 @@ ACTF(exec) ap->file_len += strlen(fileName) + sizeof(char*) + 1; /* If we have lots of files already, exec the command */ rc = 1; - if (ap->file_len >= 32*1024) + if (ap->file_len >= G.max_argv_len) rc = do_exec(ap, NULL); return rc; } -- cgit v1.2.3