[libvirt] PATCH: Fix crash attempting to shutdown inactive QEMU vm

If the virDomainShutdown() op was run on an active QEMu vm, it would crash, since the def->monitor_chr was NULL. Daniel commit 49ec121fd806aaa07bbcba9668a8f9dd43dda9c4 Author: Daniel P. Berrange <berrange@redhat.com> Date: Fri Jul 31 15:50:46 2009 +0100 Fix crash when attempting to shutdown inactive QEMU vm * src/qemu_driver.c: Add check that QEMU is active before attemting to shutdown. Fix error code for check in destroy method diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 26897d3..cebbafb 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -2940,6 +2940,12 @@ static int qemudDomainShutdown(virDomainPtr dom) { goto cleanup; } + if (!virDomainIsActive(vm)) { + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + } + if (qemudMonitorCommand(vm, "system_powerdown", &info) < 0) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("shutdown operation failed")); @@ -2971,7 +2977,7 @@ static int qemudDomainDestroy(virDomainPtr dom) { goto cleanup; } if (!virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; } -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Fri, 2009-07-31 at 15:52 +0100, Daniel P. Berrange wrote:
If the virDomainShutdown() op was run on an active QEMu vm, it would crash, since the def->monitor_chr was NULL.
Daniel
commit 49ec121fd806aaa07bbcba9668a8f9dd43dda9c4 Author: Daniel P. Berrange <berrange@redhat.com> Date: Fri Jul 31 15:50:46 2009 +0100
Fix crash when attempting to shutdown inactive QEMU vm
* src/qemu_driver.c: Add check that QEMU is active before attemting to shutdown. Fix error code for check in destroy method
diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 26897d3..cebbafb 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -2940,6 +2940,12 @@ static int qemudDomainShutdown(virDomainPtr dom) { goto cleanup; }
+ if (!virDomainIsActive(vm)) { + qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + } +
Good catch. Perhaps add a NULL check in qemudMonitorSend(), since it's pretty hard to go through all the callers and be sure we're checking the domain is active for each one In any case, ACK Cheers, Mark.
participants (2)
-
Daniel P. Berrange
-
Mark McLoughlin