4 ms·
I believe the the part that says: > It then joins them with a single space: is incorrect: there is no space added. The system call `exec` [1] (that is used t
by silviot 5y ago
I believe the the part that says:
> It then joins them with a single space:
is incorrect: there is no space added.
The system call `exec` [1] (that is used to execute any program, often in combination with `fork`) takes the command and its arguments as parameters. The space is the way humans (at times through scripts) communicate with their shell (that does the fork-exec dance for them) to let it know what exactly to put into these arguments. But when programs like ssh invoke `exec` they just pass command and arguments as strings, with no separator involved.
Maybe it's just nitpicking, but since the article attempts at going into the details of what's going on it might be important.
[1] https://en.wikipedia.org/wiki/Exec_(system_call)#Unix,_POSIX,_and_other_multitasking_systems https://en.wikipedia.org/wiki/Exec_(system_call)#Unix,_POSIX...
- EdSchouten 5y agoNo. What it says, is correct. All of the arguments passed to SSH are joined together using a single space. This single string is then interpreted by the remote side through 'sh -c "${the entire string}"'.
- silviot 5y agoHow do you determine this? I tried on an Ubuntu machine and running `ssh machine sleep 100` I saw the `sleep 100` process as direct child of `sshd`. Also, in the man page for ssh it says: > If a command is specified, it is executed on the remote host instead of a login shell. which sounds to me like a shell is not involved in this case.
- EdSchouten 5y ago> I saw the `sleep 100` process as direct child of `sshd`. Keep in mind that shells like Bash do an implicit 'exec' in case the end of the script is detected, no traps are set, etc. etc. etc. > How do you determine this? $ ssh floeper echo foo '&&' echo bar foo bar Notice how this should have printed "foo && echo bar" if this was passed to execve() directly. > Also, in the man page for ssh it says: > > If a command is specified, it is executed on the remote host instead of a login shell. > which sounds to me like a shell is not involved in this case. The emphasis on that sentence from the man page should be on login shell. SSH always spawns a shell, regardless of whether a command is provided or not. It's just that it's not a login shell if a command is given. Your shellrc file won't be run.
- silviot 5y agoTIL about the implicit exec. Details are hard. Thanks for pointing out the way it works!