[PATCH 1/2] find: use sysconf(_SC_ARG_MAX) to determine the command-line size limit
Bartosz Gołaszewski
bartekgola at gmail.com
Thu Jun 19 12:43:59 UTC 2014
2014-06-19 12:41 GMT+02:00 Denys Vlasenko <vda.linux at googlemail.com>:
> On Wed, Jun 18, 2014 at 10:11 PM, Bartosz Golaszewski
> <bartekgola at gmail.com> wrote:
>> +long FAST_FUNC bb_sc_arg_max(void)
>> +{
>> +#if defined _SC_ARG_MAX
>> + return sysconf(_SC_ARG_MAX) - 2048;
>> +#elif defined ARG_MAX
>> + return ARG_MAX - 2048;
>> +#else
>> + return 32 * 1024;
>> +#endif
>> +}
>
> If ARG_MAX is defined, it will be a function which returns constant.
> Not optimal wrt size.
True, probably should have been like this in include/libbb.h:
#if defined _SC_ARG_MAX
long bb_sc_arg_max(void) FAST_FUNC;
#elif defined ARG_MAX
#define bb_sc_arg_max() (ARG_MAX)
// ^^^ No need to substract 2048 according to linux/limits.h comments
on my system
#elif
#define bb_sc_arg_max() (32 * 1024)
#endif
or maybe even:
#if defined _SC_ARG_MAX
long bb_sc_arg_max(void) FAST_FUNC;
#define BB_ARG_MAX (bb_sc_arg_max())
#elif defined ARG_MAX
#define BB_ARG_MAX (ARG_MAX)
// ^^^ No need to substract 2048 according to comments
// in linux/limits.h on my system
#elif
#define BB_ARG_MAX (32 * 1024)
#endif
But there is still an issue - we never include <linux/limits.h> where
ARG_MAX is defined - probably should add it to platform.h. I'll
resubmit the patch in the evening.
Bartosz Gołaszewski
More information about the busybox
mailing list