We spawn QEMU with a -pidfile option to write its PID out to a file. This file is never removed though, so next time the guest starts there is small race condition where we might be unlucky enough to read the old PID out of the file, instead of the new QEMU PID. This patch adds a call to remove the pidfile from disk when a guest is shut down. As an extra preventative measure, we also delete it before starting a guest Daniel diff -r ba0066a358b6 src/qemu_driver.c --- a/src/qemu_driver.c Mon Apr 20 12:10:15 2009 +0100 +++ b/src/qemu_driver.c Mon Apr 20 13:52:47 2009 +0100 @@ -1389,6 +1389,14 @@ static int qemudStartVMDaemon(virConnect if (qemuPrepareHostDevices(conn, vm->def) < 0) goto cleanup; + if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) { + virReportSystemError(conn, ret, + _("Cannot remove stale PID file for %s"), + vm->def->name); + goto cleanup; + } + + vm->def->id = driver->nextvmid++; if (qemudBuildCommandLine(conn, driver, vm->def, qemuCmdFlags, &argv, &progenv, @@ -1512,6 +1520,8 @@ cleanup: static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED, struct qemud_driver *driver, virDomainObjPtr vm) { + int ret; + if (!virDomainIsActive(vm)) return; @@ -1556,6 +1566,12 @@ static void qemudShutdownVMDaemon(virCon VIR_WARN(_("Failed to remove domain status for %s"), vm->def->name); } + if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) { + char ebuf[1024]; + VIR_WARN(_("Failed to remove PID file for %s: %s"), + vm->def->name, virStrerror(errno, ebuf, sizeof ebuf)); + } + vm->pid = -1; vm->def->id = -1; vm->state = VIR_DOMAIN_SHUTOFF; -- |: 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 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list