Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for empty init arguments in the command line parser #176

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mschlumpp
Copy link

Summary of the PR

For automated scripts it is easier to keep the trailing -- separator than to separately check whether it is strictly necessary.
Without this change the crate would include the trailing -- as a kernel argument. Downstream consumers such as firecracker then proceed to append further parameters to that string (mmio parameters). The final re-assembled string looked similar to this: <kernel params> -- <mmio-args>, therefore passing the mmio parameters not to the kernel but to the init part.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

This can easily arise in automated scripts where the init args are
sometimes empty but the `--` seperator is unconditionally added.

Signed-off-by: Marco Schlumpp <[email protected]>
@roypat
Copy link
Collaborator

roypat commented Jan 30, 2024

Hi @mschlumpp,
Thank you for your PR! I think what you're trying to achieve is already partially supported by linux-loader (e.g. the first of the two test cases you add passes even without your changes). The only missing piece is that if the string passed to try_from has the form <boot args> -- (e.g. no trailing space after the --), then the -- will be considered part of the boot args instead of being stripped. For this, I think we can achieve what you want with a simpler change:

diff --git a/src/cmdline/mod.rs b/src/cmdline/mod.rs
index 2ac7c31..5687ca3 100644
--- a/src/cmdline/mod.rs
+++ b/src/cmdline/mod.rs
@@ -487,6 +487,10 @@ impl Cmdline {
             ),
         };
 
+        if boot_args.ends_with(INIT_ARGS_SEPARATOR.trim_end()) {
+            boot_args = &boot_args[..boot_args.len() - INIT_ARGS_SEPARATOR.trim().len()];
+        }
+
         boot_args = boot_args.trim();
         init_args = init_args.trim();

Given that we already trim the trailing -- if its followed by a space, that seems like a reasonable change to make, but I'd like to get some input from someone who knows more about the intricacies here (maybe @rbradford?).

Other than that, we should also adjust the documentation of try_from, to point out that it strips trailing --s. It should also get a changelog entry.

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.

2 participants