coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

chroot: use execvp directly instead of process::Command

Open mattsu2020 opened this issue 2 months ago • 13 comments

  • 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

mattsu2020 avatar Oct 25 '25 12:10 mattsu2020

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.

Arcterus avatar Oct 25 '25 12:10 Arcterus

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.

codspeed-hq[bot] avatar Oct 25 '25 12:10 codspeed-hq[bot]

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)

github-actions[bot] avatar Oct 25 '25 12:10 github-actions[bot]

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.

I made some revisions based on your feedback.

mattsu2020 avatar Oct 25 '25 12:10 mattsu2020

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Oct 25 '25 13:10 github-actions[bot]

I confirm this change fixes https://github.com/uutils/coreutils/issues/9010

Nice job! :)

fulalas avatar Oct 25 '25 13:10 fulalas

would it be possible to add a test? thanks

sylvestre avatar Oct 25 '25 18:10 sylvestre

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

github-actions[bot] avatar Oct 27 '25 02:10 github-actions[bot]

would it be possible to add a test? thanks

Done

mattsu2020 avatar Oct 30 '25 23:10 mattsu2020

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Nov 29 '25 10:11 github-actions[bot]

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Dec 05 '25 11:12 github-actions[bot]

@mattsu2020 I suggest replacing the word "refactor" with "chroot" in the title of this PR.

Ecordonnier avatar Dec 09 '25 00:12 Ecordonnier

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!

github-actions[bot] avatar Dec 09 '25 11:12 github-actions[bot]