Skip to content

Commit

Permalink
install: Fix exec helper to not swallow unexpected args
Browse files Browse the repository at this point in the history
Our `exec-in-host-mount-namespace` internal helper was intended
to be a "passthrough" that accepts whatever child arguments.

However I misunderstood how to do this in clap.  Before this
change we get:

```
$ bootc blabla
ERROR Re-exec in host mountns: Missing command
```

i.e. the exec code kicks in because `external_subcommand` takes
over *everything* unknown.

Fix things to use `trailing_var_arg` which is intended for this case.

After this patch:

```
$ bootc blabla
error: unrecognized subcommand 'blabla'

Usage: bootc <COMMAND>

For more information, try '--help'.
```

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Dec 15, 2023
1 parent e4b24ea commit 6760287
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ pub(crate) enum Opt {
/// Execute the given command in the host mount namespace
#[cfg(feature = "install")]
#[clap(hide = true)]
#[command(external_subcommand)]
ExecInHostMountNamespace(Vec<OsString>),
ExecInHostMountNamespace {
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<OsString>,
},
/// Install to the target filesystem.
#[cfg(feature = "install")]
InstallToFilesystem(crate::install::InstallToFilesystemOpts),
Expand Down Expand Up @@ -458,7 +460,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
#[cfg(feature = "install")]
Opt::InstallToFilesystem(opts) => crate::install::install_to_filesystem(opts).await,
#[cfg(feature = "install")]
Opt::ExecInHostMountNamespace(args) => {
Opt::ExecInHostMountNamespace { args } => {
crate::install::exec_in_host_mountns(args.as_slice())
}
Opt::Status(opts) => super::status::status(opts).await,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ pub(crate) fn run_in_host_mountns(cmd: &str) -> Command {

#[context("Re-exec in host mountns")]
pub(crate) fn exec_in_host_mountns(args: &[std::ffi::OsString]) -> Result<()> {
let (cmd, args) = args[1..]
let (cmd, args) = args
.split_first()
.ok_or_else(|| anyhow::anyhow!("Missing command"))?;
let pid1mountns = std::fs::File::open("/proc/1/ns/mnt")?;
Expand Down

0 comments on commit 6760287

Please sign in to comment.