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/xargs.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'findutils/xargs.c') diff --git a/findutils/xargs.c b/findutils/xargs.c index 0ba5b566d..76c4747fe 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -523,12 +523,7 @@ int xargs_main(int argc, char **argv) argc++; } - /* -s NUM default. fileutils-4.4.2 uses 128k, but I heasitate - * to use such a big value - first need to change code to use - * growable buffer instead of fixed one. - */ - n_max_chars = 32 * 1024; - /* Make smaller if system does not allow our default value. + /* * The Open Group Base Specifications Issue 6: * "The xargs utility shall limit the command line length such that * when the command line is invoked, the combined argument @@ -536,16 +531,15 @@ int xargs_main(int argc, char **argv) * in the System Interfaces volume of IEEE Std 1003.1-2001) * shall not exceed {ARG_MAX}-2048 bytes". */ - { - long arg_max = 0; -#if defined _SC_ARG_MAX - arg_max = sysconf(_SC_ARG_MAX) - 2048; -#elif defined ARG_MAX - arg_max = ARG_MAX - 2048; -#endif - if (arg_max > 0 && n_max_chars > arg_max) - n_max_chars = arg_max; - } + n_max_chars = bb_arg_max(); + if (n_max_chars > 32 * 1024) + n_max_chars = 32 * 1024; + /* + * POSIX suggests substracting 2048 bytes from sysconf(_SC_ARG_MAX) + * so that the process may safely modify its environment. + */ + n_max_chars -= 2048; + if (opt & OPT_UPTO_SIZE) { n_max_chars = xatou_range(max_chars, 1, INT_MAX); } -- cgit v1.2.3