1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

command -x: tweak args list size detection (re: 9ddb45b1)

src/cmd/ksh93/features/externs: ARG_EXTRA_BYTES detection:
- Improve detection of extra bytes per argument: on every loop
  iteration, recalculate the size of the environment while taking
  the amount extra bytes we're currently trying into account. Also
  count arguments (argv[]) as they are stored in the same buffer.
  On 64-bit Linux with glibc, this now detects 9 extra bytes per
  argument instead of 8. An odd number (literally and figuratively)
  but apparently it needs it; I do think my method is correct now.
  On 64-bit Solaris and macOS, this still detects 8 extra bytes.
  (On 64-bit Linux with musl C library, it detects 0 bytes. Nice.)

src/cmd/ksh93/sh/path.c: path_xargs():
- Remove the kludge subtracting twice the size of the environment.
  With the feature test fixed, this should no longer fail on Linux.
- Take into account the size of the final null element in the
  argument and environment lists.

src/cmd/ksh93/tests/path.sh:
- Do not use awk for the test due to breakage in the system awks
  on Solaris/Illumos (hangs) and AIX & UnixWare (drops arguments).
  Instead, use (wait for it...) ksh. It's a bit slower, but works.
This commit is contained in:
Martijn Dekker 2021-02-12 23:59:57 +00:00
parent 8c1e9971a7
commit 6f6b22016a
3 changed files with 31 additions and 22 deletions

View file

@ -542,7 +542,7 @@ fi
ofile=$tmp/command_x_chunks.sh
trap 'sleep_pid=; while kill -9 $pid; do :; done 2>/dev/null; err_exit "'\''command -x'\'' hung"' TERM
trap 'kill $sleep_pid; while kill -9 $pid; do :; done 2>/dev/null; trap - INT; kill -s INT $$"' INT
{ sleep 15; kill $$; } &
{ sleep 60; kill $$; } &
sleep_pid=$!
(
export LC_ALL=C
@ -558,14 +558,17 @@ sleep_pid=$!
done
print "chunks=0 expargs=$# args=0 expsize=$((${#args}+1)) size=0"
unset args
command -px awk 'BEGIN {
ARGC -= 2; # final static args
for (i=1; i<ARGC; i++)
size += length(ARGV[i]) + 1;
print ("let chunks++ args+=")(ARGC - 1)(" size+=")(size);
if(ARGV[ARGC] != "static_arg_1" || ARGV[ARGC+1] != "final_static_arg_2")
print "err_exit \"'\''command -x'\'': static final arguments for chunk $chunks incorrect\"";
}' "$@" static_arg_1 final_static_arg_2
command -x "$SHELL" -c '
integer i size=0 numargs=${#}-2
for ((i=numargs; i; i--))
do let "size += ${#1} + 1"
shift
done
print "let chunks++ args+=$numargs size+=$size"
if [[ $0 != static_argzero || $1 != final_static_arg_1 || $2 != final_static_arg_2 ]]
then print "err_exit \"'\''command -x'\'': static arguments for chunk \$chunks incorrect\""
fi
' static_argzero "$@" final_static_arg_1 final_static_arg_2
) >$ofile &
pid=$!
wait $pid