Repository navigation
coreutils: support --coreutils-prog utility selection - #15489
Conversation
|
I'm not sure if we really want to support this. |
| 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. | ||
|
|
There was a problem hiding this comment.
I think we don't need to document this since this option is needed only for creating shebangs at build time.
fd3dbe1 to
e957d89
Compare
| .into_owned() | ||
| .to_string_lossy(); | ||
| if get_utility_is_second_arg() { | ||
| name.strip_prefix("--coreutils-prog=") |
There was a problem hiding this comment.
uucore can be used as a library. So this logic should be part of coreutils itself.
e957d89 to
71d7d8f
Compare
|
|
||
| #[test] | ||
| #[cfg(all(unix, feature = "echo"))] | ||
| fn coreutils_prog_shebang() { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ab063ca to
5a943b1
Compare
| } else if let Some(util) = args | ||
| .peek() | ||
| .and_then(|arg| arg.to_str()) | ||
| .and_then(|arg| arg.strip_prefix("--coreutils-prog=")) |
There was a problem hiding this comment.
--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
| .and_then(|arg| arg.to_str()) | ||
| .and_then(|arg| arg.strip_prefix("--coreutils-prog=")) | ||
| { | ||
| uucore::set_utility_name(util.to_owned()); |
There was a problem hiding this comment.
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?
|
please also remove the |
| } | ||
|
|
||
| #[test] | ||
| #[cfg(all(feature = "echo", feature = "true", feature = "false"))] |
There was a problem hiding this comment.
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
| 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) |
There was a problem hiding this comment.
please also check stderr for the invalid cases, an exit code of 1 alone is weak
There was a problem hiding this comment.
But we use different error message with GNU at coreutils currently which does not affect to its meaning.
5a943b1 to
93118c8
Compare
| @@ -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 | |||
There was a problem hiding this comment.
| # We use coreutils yes |
Remove this too.
93118c8 to
81e68ed
Compare
81e68ed to
8ec34b3
Compare
8ec34b3 to
c64b886
Compare
|
This breaks AppArmor profile. I think we should not implement this and consider different secure approach to mimic individual binaries. |
|
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? |
c64b886 to
08b276c
Compare
|
I might misunderstanding GNU's implementation. |
|
Since |
|
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? |
|
Does it match with GNU? |
|
Yes, it matches GNU for this case. GNU checks the command name first, so true --coreutils-prog=ls still runs true. |
|
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.
08b276c to
b021143
Compare
Merging this PR will improve performance by 10.47%1 warning, 1 note
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
|
GNU testsuite comparison: |
|
|
|
Thanks for your PR |
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.