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

keys with spaces are not supported? #1248

Open
samoht opened this issue Oct 26, 2021 · 6 comments
Open

keys with spaces are not supported? #1248

samoht opened this issue Oct 26, 2021 · 6 comments
Assignees
Labels

Comments

@samoht
Copy link
Member

samoht commented Oct 26, 2021

It seems that it's not possible to pass keys with spaces anymore:

$ dune exec -- tutorial/hello-key/main.exe --hello="built with dune"
hello_key: too many arguments, don't know what to do with `with', `dune'
Usage: hello_key [OPTION]...
Try `hello_key --help' for more information.

Not sure what is happening, but it's worth investigating.

@samoht samoht changed the title Support keys with spaces keys with spaces are not supported anymore? Oct 26, 2021
@samoht samoht added the bug label Oct 26, 2021
@TheLortex TheLortex self-assigned this Oct 26, 2021
@TheLortex
Copy link
Member

Looks like it's been like that forever. What I found is that:

  • the issue only happens at runtime (values with spaces are supported in configure)
  • Sys.argv is transformed into a string (concatenated with spaces between arguments) in mirage/mirage-bootvar-unix
  • Then the string is parsed using mirage/parse-argv

So for your example, what happens is:

Sys.argv: string array = [|"tutorial/hello-key/main.exe"; "--hello=built with dune"|]
=>
cmd_line: string = "tutorial/hello-key/main.exe --hello=built with dune"
=>
parsed_cmd_line: string list = [ "tutorial/hello-key/main.exe"; "--hello=build"; "with"; "dune" ]

Somehow Sys.argv has lost the " symbols, so parsing fails (it also happens in ocaml-freestanding)

@dinosaure
Copy link
Member

Somehow Sys.argv has lost the " symbols, so parsing fails (it also happens in ocaml-freestanding)

The shell delete quotes, the tool must surround any (or, at least, arguments with spaces) with quotes by itself.

@dinosaure
Copy link
Member

Fixed by mirage/mirage-bootvar-unix#2. About Solo5 the execution path is different and it should work (may be @hannesm can confirm that).

@hannesm
Copy link
Member

hannesm commented May 17, 2023

The fix by @dinosaure for mirage-bootvar-unix looks like it solves the issue reported for the unix target.

For solo5 (spt & hvt), there'd be some more stuff needed:

  • on the commandline, passing --hello="foo bar baz" or --hello=foo\ bar\ baz
  • solo5 hvt tender (in hvt/hvt_boot_info.c setup_cmdline, sees: argc 1: --hello=foo bar baz <- here that would need to escape the whitespaces (i.e. --hello=foo bar baz -> --hello=foo\ bar\ baz)
  • then parse_argv (used by Mirage_bootvar_solo5) should be fine to remote the backslashes again

Now, the question is what is happening on virtio / xen / muen (where we're not in control of the tender)? And is it worth it to go down this route? Apart from the simple hello world unikernel, are there actual unikernels where arguments with whitespaces are useful (and btw you can always --hello="foo\ bar\ baz" -> the shell takes the ", but the \ remains being passed through).

@samoht
Copy link
Member Author

samoht commented May 17, 2023

No strong opinion - but it's an error that I have seen many beginners hit, and the error message is not helpful. We should at least define what is allowed in these strings and raise a proper error to explain to the user what's happening.

@hannesm hannesm changed the title keys with spaces are not supported anymore? keys with spaces are not supported? Jun 20, 2023
@patricoferris
Copy link

@pitag-ha and I just hit this problem when building a simple send/recv TCP unikernel (we wanted to send/recv messages provided as command line arguments where "hello sonja!" wouldn't work for example) -- happy for mirage not to support spaces but a better error message would indeed be better :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants