[libvirt] [PATCH] qemu: Fix escape_monitor(escape_shell(command))

Philipp Hahn hahn at univention.de
Fri Feb 11 12:59:11 UTC 2011


Suspending a VM which contains shell meta characters doesn't work with
libvirt-0.8.7:
/var/log/libvirt/qemu/andreas_231-ne\ doch\ nicht.log:
  sh: -c: line 0: syntax error near unexpected token `doch'
  sh: -c: line 0: `cat | { dd bs=4096 seek=1 if=/dev/null && dd bs=1048576; }

Although target="andreas_231-ne doch nicht" contains shell meta
characters (here: blanks), they are not properly escaped by
src/qemu/qemu_monitor_{json,text}.c#qemuMonitor{JSON,Text}MigrateToFile()

First, the filename needs to be properly escaped for the shell, than
this command line has to be properly escaped for qemu again.

For this to work, remove the old qemuMonitorEscapeArg() wrapper, rename
qemuMonitorEscape() to it removing the handling for shell=TRUE, and
implement a new qemuMonitorEscapeShell() returning strings using single
quotes.

Using double quotes or escaping special shell characters with backslashes
would also be possible, but the set of special characters heavily
depends on the concrete shell (dsh, bash, zsh) and its setting (history
expansion, interactive use, ...)

Signed-off-by: Philipp Hahn <hahn at univention.de>
---
 src/qemu/qemu_monitor.c |   65 +++++++++++++++++++++++++++-------------------
 1 files changed, 38 insertions(+), 27 deletions(-)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-qemu-Fix-escape_monitor-escape_shell-command.patch
Type: text/x-patch
Size: 2771 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110211/3970d1b1/attachment-0001.bin>


More information about the libvir-list mailing list