chroot: use execvp directly instead of process::Command
- Replace process::Command execution with direct execvp call via libc for improved performance by avoiding process forking
- Add validation to detect and error on commands containing null bytes
- Capture and handle execution errors using the last OS error after execvp failure
fix this issue https://github.com/uutils/coreutils/issues/9010
Rather than using execvp() directly, it'd probably be better to rely on the Command::exec() function provided by CommandExt.
CommandExt actually provides a number of things we do here manually with libc, so we might be able to move e.g. the actual chroot() and uid/gid changes and so on to the stdlib.
CodSpeed Performance Report
Merging #9013 will not alter performance
Comparing mattsu2020:fix_chroot (5240be4) with main (aaa0610)
Summary
✅ 127 untouched
⏩ 6 skipped[^skipped]
[^skipped]: 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
GNU testsuite comparison:
Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)
Rather than using
execvp()directly, it'd probably be better to rely on theCommand::exec()function provided byCommandExt.
CommandExtactually provides a number of things we do here manually withlibc, so we might be able to move e.g. the actualchroot()anduid/gidchanges and so on to the stdlib.
I made some revisions based on your feedback.
GNU testsuite comparison:
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
I confirm this change fixes https://github.com/uutils/coreutils/issues/9010
Nice job! :)
would it be possible to add a test? thanks
GNU testsuite comparison:
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
would it be possible to add a test? thanks
Done
GNU testsuite comparison:
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
GNU testsuite comparison:
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)
@mattsu2020 I suggest replacing the word "refactor" with "chroot" in the title of this PR.
GNU testsuite comparison:
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!