
On 05/05/2011 11:26 AM, Daniel P. Berrange wrote:
This command allows libvirt to attach to an existing QEMU instance.
$ qemu-kvm -cdrom ~/demo.iso \ -monitor unix:/tmp/demo,server,nowait \ -name foo \ -uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea & $ QEMUPID=$$
$!, not $$ (you want to attach to the background qemu, not your current shell!)
$ virsh qemu-attach $QEMUPID --- tools/virsh.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-)
+static const vshCmdOptDef opts_qemu_attach[] = { + {"pid", VSH_OT_DATA, VSH_OFLAG_REQ, N_("pid")},
s/VSH_OT_DATA/VSH_OT_INT/
+ {NULL, 0, 0, NULL} +}; + +static bool +cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom = NULL; + bool ret = false; + unsigned int flags = 0; + int pid; + + if (!vshConnectionUsability(ctl, ctl->conn)) + goto cleanup; + + if (vshCommandOptInt(cmd, "pid", &pid) < 0) {
s/</<=/ - pid is a required argument. Since you didn't initialize it, if vshCommandOptInt returns 0, you would be using whatever garbage was on the stack.
@@ -10875,6 +10921,7 @@ static const vshCmdDef hostAndHypervisorCmds[] = { {"hostname", cmdHostname, NULL, info_hostname}, {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo}, {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command, info_qemu_monitor_command}, + {"qemu-attach", cmdQemuAttach, opts_qemu_attach, info_qemu_attach},
Swap the above two lines, to keep alphabetical order. Missing tools/virsh.pod changes. You know I can't ack without documentation... :) -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org