NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/57253: xargs wraps lines after ~4k characters



    Date:        Thu,  2 Mar 2023 11:45:02 +0000 (UTC)
    From:        Marc Daniel Fege <marc%fege.net@localhost>
    Message-ID:  <20230302114502.386241A923B%mollari.NetBSD.org@localhost>

  |  Indeed, some limit will be there anyway. But do those limits need to be
  |  (artificially) defined in the userland programs themselves to handle an
  |  otherwise comming up exception of the programming language or library?

In the case of xargs, POSIX actually requires it:

	The generated command line length shall be the sum of the size
	in bytes of the utility name and each argument treated as strings,
	including a null byte terminator for each of these strings. The
	xargs utility shall limit the command line length

"shall" in POSIX means it is an absolute requirement - that must happen.

	such that when the command line is invoked, the combined argument
	and environment lists (see the exec family of functions in the System
	Interfaces volume of POSIX.1-202x) shall not exceed {ARG_MAX}-2048
	bytes. Within this constraint, if neither the -n nor the -s option
	is specified, the default command line length shall be at least
	{LINE_MAX}.

If you chase enough definitions in XCU 1.2 (Utility Limits) you'll
discover that the minimum value for LINE_MAX is 2048.  ARG_MAX is
defined in the specification of <limits.h> in XSH 14.   That ends up
being 4096 (minimum).

If you want to write a portable script, you need to expect those limits
on some systems.   I doubt our xargs limits anything to 4K, I think we
get quite close to the implementation limit (much more than you are
entitled to reply upon) - but do note that what is in the environment
counts, if you have lots of stuff there, xargs will make shorter commands
(less args) then if you have less in the environment.   Both the number
of environment variables, and the length of each of those (NAME=value)
matters.

kre



Home | Main Index | Thread Index | Old Index