Skip to content

Report an unparseable shim command line instead of panicking - #1181

Open
arpitjain099 wants to merge 1 commit into
containerd:mainfrom
arpitjain099:fix/shim-flag-parse-error
Open

arpitjain099 wants to merge 1 commit into
containerd:mainfrom
arpitjain099:fix/shim-flag-parse-error

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #1180.

shim_main unwraps the result of parse, so any flag the shim does not define, --version included, aborts with a panic and exit 101 instead of saying what was wrong. argv0 moves above the parse so the message can name the binary, and the error goes to stderr with exit 1.

I could not build a shim binary on macOS (procfs is Linux only), so I reproduced the two behaviours against the same containerd_shim::parse in a Linux container, one binary per shape:

--- before, unknown flag:
thread 'main' panicked at src/bin/before.rs:6:38:
called `Result::unwrap()` on an `Err` value: InvalidArgument("flag provided but not defined: -version")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
exit=101

--- after, unknown flag:
after: Failed to parse command line: flag provided but not defined: -version
exit=1

--- after, -v:
after: parsed, version flag = true
exit=0

cargo check -p containerd-shimkit and cargo fmt -p containerd-shimkit -- --check are clean, both run in a rust:1.91-slim container to match the pinned toolchain.

There is no unit test here because the branch ends in std::process::exit, which a test in this crate cannot observe. If you would rather have coverage, the parse and the exit could be split so the decision is testable, but that is a bigger change than the bug needs, so I left it.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>

This branch has not been deployed

No deployments
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.

Shims panic on an unrecognised command-line flag

1 participant