Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 'command -x' on macOS, Linux, Solaris
'command -x' (basically builtin xargs for 'command') worked for long argument lists on *BSD and HP-UX, but not on macOS and Linux, where it reliably entered into an infinite loop. The problem was that it assumed that every byte of the environment space can be used for arguments, without accounting for alignment that some OSs do. MacOS seems to be the most wasteful one: it aligns on 16-byte boundaries and requires some extra bytes per argument as well. src/cmd/ksh93/sh/path.c: - path_xargs(): When calculating how much space to subtract per argument, add 16 extra bytes to the length of each argument, then align the result on 16-byte boundaries. The extra 16 bytes is more than even macOS needs, but hopefully it is future-proof. - path_spawn(): If path_xargs() does fail, do not enter a retry loop (which always becomes an infinite loop if the argument list exceeds OS limitations), but abort with an error message.
- Loading branch information