Skip to content

coreutils: support --coreutils-prog utility selection - #15489

Merged
sylvestre merged 1 commit into
uutils:mainfrom
limadog9:fix/coreutils-prog-option-9575
Nov 27, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
limadog9:fix/coreutils-prog-option-9575

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Support --coreutils-prog=UTIL when invoking the multicall binary, including under an unrecognized name or through a shebang wrapper. Help and diagnostics use the selected utility name.

Add coverage for argument forwarding, exit status, invalid utilities, aliases, and shebang execution. All 20 multicall tests pass.

Closes #9575.

@oech3

oech3 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

I'm not sure if we really want to support this.

Comment thread docs/src/multicall.md Outdated
The utility can also be selected with `--coreutils-prog=UTIL`, including when
the binary is invoked under an unrecognized name. This supports script wrappers
that use the multi-call binary as their interpreter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to document this since this option is needed only for creating shebangs at build time.

@limadog9
limadog9 force-pushed the fix/coreutils-prog-option-9575 branch from fd3dbe1 to e957d89 Compare October 18, 2026 17:36
Comment thread src/uucore/src/lib/lib.rs Outdated
.into_owned()
.to_string_lossy();
if get_utility_is_second_arg() {
name.strip_prefix("--coreutils-prog=")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uucore can be used as a library. So this logic should be part of coreutils itself.

@limadog9
limadog9 force-pushed the fix/coreutils-prog-option-9575 branch from e957d89 to 71d7d8f Compare October 18, 2026 17:39
Comment thread tests/test_util_name.rs Outdated

#[test]
#[cfg(all(unix, feature = "echo"))]
fn coreutils_prog_shebang() {

This comment was marked as resolved.

@limadog9
limadog9 force-pushed the fix/coreutils-prog-option-9575 branch 2 times, most recently from ab063ca to 5a943b1 Compare October 18, 2026 17:55
Comment thread src/bin/coreutils.rs
} else if let Some(util) = args
.peek()
.and_then(|arg| arg.to_str())
.and_then(|arg| arg.strip_prefix("--coreutils-prog="))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--coreutils-prog=--list prints the list and --coreutils-prog=--version the multicall version, is that intended?
I would only accept names that are in utils here

Comment thread src/bin/coreutils.rs
.and_then(|arg| arg.to_str())
.and_then(|arg| arg.strip_prefix("--coreutils-prog="))
{
uucore::set_utility_name(util.to_owned());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also sets the name for --coreutils-prog=missing_program or an empty one, could it be set only once we know the util exists?

@sylvestre

Copy link
Copy Markdown
Contributor

please also remove the sed stripping --coreutils-prog= in util/build-gnu.sh and run the upstream test:
bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/misc/coreutils.sh

Comment thread tests/test_util_name.rs
}

#[test]
#[cfg(all(feature = "echo", feature = "true", feature = "false"))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test that an error message uses the selected name, e.g. --coreutils-prog=ls /nonexistent should start with ls:
that's the whole point of the uucore change

Comment thread tests/test_util_name.rs
assert_eq!(output.stdout, b"hello world\n");
assert!(output.stderr.is_empty());
for (name, expected) in [("true", 0), ("false", 1), ("missing_program", 1), ("", 1)] {
let output = Command::new(&scene.bin_path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also check stderr for the invalid cases, an exit code of 1 alone is weak

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we use different error message with GNU at coreutils currently which does not affect to its meaning.

@limadog9
limadog9 force-pushed the fix/coreutils-prog-option-9575 branch from 5a943b1 to 93118c8 Compare October 18, 2026 22:03
Comment thread util/build-gnu.sh Outdated
@@ -211,7 +211,6 @@ sed -i 's/^print_ver_.*/require_selinux_/' tests/runcon/runcon-no-reorder.sh
sed -i 's/^print_ver_.*/require_selinux_/' tests/chcon/chcon-fail.sh

# We use coreutils yes

@oech3 oech3 Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# We use coreutils yes

Remove this too.

@limadog9
limadog9 force-pushed the fix/coreutils-prog-option-9575 branch from 93118c8 to 81e68ed Compare October 18, 2026 22:27
@limadog9
limadog9 force-pushed the fix/coreutils-prog-option-9575 branch from 81e68ed to 8ec34b3 Compare November 23, 2026 01:06
@sylvestre
sylvestre force-pushed the fix/coreutils-prog-option-9575 branch from 8ec34b3 to c64b886 Compare November 23, 2026 21:11
@oech3

oech3 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

This breaks AppArmor profile. I think we should not implement this and consider different secure approach to mimic individual binaries.

@limadog9

Copy link
Copy Markdown
Contributor Author

Thanks for flagging this. Could you give an example of an AppArmor profile that would be affected? I’m trying to understand which rules you’d expect to apply today and what would change with this patch. Since coreutils cp already works, is your concern about the new flag itself, or about packages using it in a wrapper for /usr/bin/cp?

@sylvestre
sylvestre force-pushed the fix/coreutils-prog-option-9575 branch from c64b886 to 08b276c Compare November 27, 2026 04:57
@oech3

oech3 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

#9575 (comment)

I might misunderstanding GNU's implementation.

@oech3

oech3 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Since /usr/bin/coreutils requires overkilled profile already, coreutils cp is fine. Ubuntu should remove /usr/bin/coreutils from rust-coreutils packages.

@limadog9

limadog9 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks, the true example helps. In this patch, /usr/bin/true --coreutils-prog=ls still runs true because the code recognizes true before it checks the flag. I can add a test to cover that. Does that address your concern?

@oech3

oech3 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Does it match with GNU?

@limadog9

Copy link
Copy Markdown
Contributor Author

Yes, it matches GNU for this case. GNU checks the command name first, so true --coreutils-prog=ls still runs true.

@oech3

oech3 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Thanks. So AppArmor things is my misunderstanding, and adding the test is helpful.

Accept --coreutils-prog=UTIL for explicit utility selection, including
when the executable has an unrecognized name. Parse the option in the
multicall entry point and provide the selected display name through a
generic uucore override.

Cover argument forwarding, exit status, invalid utilities, and aliases.

Closes uutils#9575.
@limadog9
limadog9 force-pushed the fix/coreutils-prog-option-9575 branch from 08b276c to b021143 Compare November 27, 2026 05:21
@codspeed

codspeed Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 10.47%

1 warning, 1 note

⚠️ 126 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
✅ 414 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory timeout_enforced 179.6 KB 162.5 KB +10.47%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing limadog9:fix/coreutils-prog-option-9575 (b021143) with main (63e6958)

Open in CodSpeed

Footnotes

  1. 70 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. ↩

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

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

@oech3

oech3 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

invalid-name symlinked to true can run ls. But the issue is already existing on our binary and Ubuntu patch should reject it.

@sylvestre
sylvestre merged commit f4ac57c into uutils:main Nov 27, 2026
196 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coreutils: Should we really support --coreutils-prog=yes too?

3 participants