chroot: quick fix for #2687

* fixes #2687
* change error message to better mimic GNU
This commit is contained in:
Jan Scheer 2021-09-19 11:25:00 +02:00
parent 8d418cd61c
commit 94fbe1edef
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828

View file

@ -67,7 +67,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
// TODO: refactor the args and command matching
// See: https://github.com/uutils/coreutils/pull/2365#discussion_r647849967
let command: Vec<&str> = match commands.len() {
1 => {
0 => {
let shell: &str = match user_shell {
Err(_) => default_shell,
Ok(ref s) => s.as_ref(),
@ -79,10 +79,22 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
set_context(newroot, &matches);
assert!(!command.is_empty());
let pstatus = Command::new(command[0])
.args(&command[1..])
.status()
.unwrap_or_else(|e| crash!(1, "Cannot exec: {}", e));
.unwrap_or_else(|e| {
// TODO: Exit status:
// 125 if chroot itself fails
// 126 if command is found but cannot be invoked
// 127 if command cannot be found
crash!(
1,
"failed to run command {}: {}",
command[0].to_string().quote(),
e
)
});
if pstatus.success() {
0