From 3b223db8a7fc97e51dadd62da99650201a83e39e Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 28 Feb 2026 10:23:11 +0000 Subject: [PATCH] Initialize command-line-max-length with sysconf(3) * lisp/subr.el (command-line-max-length): Move from here ... * src/callproc.c (syms_of_callproc): : ... to here. Initialize by calling sysconf(3) if possible. --- lisp/subr.el | 14 -------------- src/callproc.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index b9fbd739a5a..4cae2845d96 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5089,20 +5089,6 @@ newlines." shell-file-name delete buffer nil shell-command-switch command)) -(defvar command-line-max-length - ;; Currently we use the same value everywhere. If we actually use - ;; larger values on some systems at some point, then we need to make - ;; sure we handle whether the command will be run remotely via TRAMP. - ;; FIXME: This value is very small, it might easily all be used up by - ;; `process-environment'. We really want a larger value on POSIX. - 4096 - "Maximum length of a command and its arguments on this system. -This is measured in characters. -Used by `multiple-command-partition-arguments'. Other code calls that -function for cases in which it's known to be safe to run the command -multiple times on subsequent partitions of the list of arguments. -(In a shell script, you might use the `xargs' utility.)") - (defun multiple-command-partition-arguments (command arguments &optional shellp) "Partition ARGUMENTS of COMMAND to avoid command line length limits. This function is for running commands on each element of ARGUMENTS where diff --git a/src/callproc.c b/src/callproc.c index 51b5a1c4074..abb944c3aad 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -2237,6 +2237,20 @@ the system. */); Vrcs2log_program_name = build_string ("librcs2log.so"); #endif /* !HAVE_ANDROID || ANDROID_STUBIFY */ + DEFVAR_LISP ("command-line-max-length", Vcommand_line_max_length, + doc: /* Maximum length of a command and its arguments on this system. +This is measured in characters. +Used by `multiple-command-partition-arguments'. Other code calls that +function for cases in which it's known to be safe to run the command +multiple times on subsequent partitions of the list of arguments. +(In a shell script, you might use the `xargs' utility.) */); +#if defined _SC_ARG_MAX + /* Divide it by 4 as a crude way to go bytes->characters. */ + Vcommand_line_max_length = make_fixnum (sysconf (_SC_ARG_MAX) / 4); +#else /* defined _SC_ARG_MAX */ + Vcommand_line_max_length = make_fixnum (4096); +#endif /* defined _SC_ARG_MAX */ + defsubr (&Scall_process); defsubr (&Sgetenv_internal); defsubr (&Scall_process_region);