-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
exec: Cmd argument in non-shell mode should not split the string #794
Comments
👀 We'll do our best. A few thoughts to aid the design discussion:
Thank you =D |
Here are some examples. For the current implementation:
For the suggested changes:
Or with the Ansible option:
|
If I understand correctly, your main goal is that we express the "command" as a list rather than as a string, is that correct? Keep in mind we still need a scenario where the user uses the "name" variable and doesn't override with a Lastly, assuming we agree on this change, are you willing to implement a polished version? |
Well, yes. I want to emphasize that "the command" is inherently a list. Currently this list is represented as a space-delimited string, and I would like to represent it as a list.
Ah. I'm not sure I'm a big fan of this feature, but, sure, the name could be interpreted as a list of one item, i.e. these two are equivalent:
and
Is that what you have in mind?
Sure. |
The behaviour of:
must still work. And I expect it would be identical to doing:
Having said that, I'm okay with this change, but I'd love it if @frebib had a look to ACK it first. Looking through the golang code, the "important" golang exec API is https://pkg.go.dev/os/exec#CommandContext (or the non ctx version) which both have argv[0] separate from the remaining args... So I suppose that's why I did it that way, Is there a good reason why it separated those two instead of just having a single argv? The only argument I can think of is that it prevents someone who controls the argv array from controlling the binary path. |
Well, all the arguments against the status quo would still apply to this shorthand, and we would need to decide what exactly is the semantics of that string. Is it Windows-like or Ansible-like? In other words, is
equivalent to
or
Neither is particularly attractive to me, and in general I personally see no value in making that shorthand work, especially given its unclear semantics.
golang works in mysterious ways. |
Echoing what I said in chat. I 100% agree with hades' take here. It's a footgun and a good piece of software will be opinionated enough to protect it's users even at the cost of apparent convenience. |
As discussed in cnfgmngmntcmp.
Currently, if
shell
is unset (the default), thecmd
parameter is interpreted as a list of arguments separated by a non-empty sequence of spaces. (E.g. "ls -l /tmp" becomes ["ls", "-l", "/tmp"])[1].While useful on the surface, this is an unusual behaviour, that I personally would least expect from this parameter, and most likely will be hard to make useful for complex commands.
Curiously, Ansible's
ansible.builtin.command
works in a similar way. However the mgmt implementation is not compatible: Ansible uses the Python's shlex module[2], which implements a parody of a working shell parser.Additionally, if this ever works on Windows, this will become even more weird. Windows uses a single string to pass parameters to the processes, so the POSIX implementation is to concatenate the array of arguments and pass it as one string. So this mgmt resource will split the string, which then will be concatenated in libc, (which then most likely will be split again in the process itself).
My suggestions (in reverse order of preference) are:
Command and (Shell, ShellCommand) would be mutually exclusive. Shell becomes optional, and ShellCommand by itself invokes the default shell.
I'd be happy to provide a path for whatever suggestion of your choice, as long as you choose correctly.
[1] https://mgmtconfig.com/docs/resources/#exec
[2] https://github.com/python/cpython/blob/3.13/Lib/shlex.py
The text was updated successfully, but these errors were encountered: