[libvirt] [PATCH] qemu: Add quotes to kernel command line of direct kernel boot

When passing kernel command line arguments, it is possible to have spaces. The arguments should be protected in qoutes. In http://libvirt.org/formatdomain.html "direct kernel boot" section, there is an example. ... <os> <type>hvm</type> <loader>/usr/lib/xen/boot/hvmloader</loader> <kernel>/root/f8-i386-vmlinuz</kernel> <initrd>/root/f8-i386-initrd</initrd> <cmdline>console=ttyS0 ks=http://example.com/f8-i386/os/</cmdline> </os> ... If the contents in <cmdline> are passed as-is to qemu, then qemu will see qemu ... -append console=ttyS0 ks=http://example.com/f8-i386/os/ ... It must be quoted, so let qemu see qemu ... -append "console=ttyS0 ks=http://example.com/f8-i386/os/" ... Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- src/qemu/qemu_command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

On 08/27/2012 08:05 PM, Zhou Zheng Sheng wrote:
When passing kernel command line arguments, it is possible to have spaces. The arguments should be protected in qoutes.
NACK.
If the contents in <cmdline> are passed as-is to qemu, then qemu will see qemu ... -append console=ttyS0 ks=http://example.com/f8-i386/os/ ...
That's what shows in the guest log, because we don't (yet) properly quote arguments in the log. But if you look at what we actually pass to the exec() family,...
if (def->os.cmdline) - virCommandAddArgList(cmd, "-append", def->os.cmdline, NULL);
...this code properly passes def->os.cmdline as a single exec() argument. Remember, virCommand is NOT subject to further shell interpretation. You are getting confused by trying to treat the log output as though libvirt were invoking /bin/sh to start the command, instead of calling exec() directly. If anything, the real bug to fix would be virCommandToString to have a mode that lists the output with shell quoting as needed, and to use that mode when outputting log file information. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Thanks Eric! After reading the code of virCommandRun and virExecWithHook, I know there is no problem of passing arguments. On 08/28/2012 12:06, Eric Blake wrote:
On 08/27/2012 08:05 PM, Zhou Zheng Sheng wrote:
When passing kernel command line arguments, it is possible to have spaces. The arguments should be protected in qoutes. NACK.
If the contents in <cmdline> are passed as-is to qemu, then qemu will see qemu ... -append console=ttyS0 ks=http://example.com/f8-i386/os/ ... That's what shows in the guest log, because we don't (yet) properly quote arguments in the log. But if you look at what we actually pass to the exec() family,...
if (def->os.cmdline) - virCommandAddArgList(cmd, "-append", def->os.cmdline, NULL);
...this code properly passes def->os.cmdline as a single exec() argument. Remember, virCommand is NOT subject to further shell interpretation. You are getting confused by trying to treat the log output as though libvirt were invoking /bin/sh to start the command, instead of calling exec() directly.
If anything, the real bug to fix would be virCommandToString to have a mode that lists the output with shell quoting as needed, and to use that mode when outputting log file information.
-- Thanks and best regards! Zhou Zheng Sheng / 周征晟 E-mail: zhshzhou@linux.vnet.ibm.com Telephone: 86-10-82454397
participants (2)
-
Eric Blake
-
Zhou Zheng Sheng