{
char ebuf[1024];
char *file = NULL;
+ qemuDomainObjPrivatePtr priv = vm->privateData;
if (virAsprintf(&file, "%s/%s.xml", driver->stateDir, vm->def->name) < 0) {
virReportOOMError();
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
VIR_FREE(file);
- if (virFileDeletePid(driver->stateDir, vm->def->name) != 0)
+ if (priv->pidfile &&
+ unlink(priv->pidfile) < 0 &&
+ errno != ENOENT)
VIR_WARN("Failed to remove PID file for %s: %s",
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
-
return 0;
}
int ret;
off_t pos = -1;
char ebuf[1024];
- char *pidfile = NULL;
int logfile = -1;
char *timestamp;
qemuDomainObjPrivatePtr priv = vm->privateData;
priv->monStart = 0;
priv->gotShutdown = false;
- if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
- virReportSystemError(ret,
- _("Cannot remove stale PID file for %s"),
- vm->def->name);
+ VIR_FREE(priv->pidfile);
+ if (!(priv->pidfile = virFilePid(driver->stateDir, vm->def->name))) {
+ virReportSystemError(errno,
+ "%s", _("Failed to build pidfile path."));
goto cleanup;
}
- if (!(pidfile = virFilePid(driver->stateDir, vm->def->name))) {
+ if (unlink(priv->pidfile) < 0 &&
+ errno != ENOENT) {
virReportSystemError(errno,
- "%s", _("Failed to build pidfile path."));
+ _("Cannot remove stale PID file %s"),
+ priv->pidfile);
goto cleanup;
}
virCommandSetOutputFD(cmd, &logfile);
virCommandSetErrorFD(cmd, &logfile);
virCommandNonblockingFDs(cmd);
- virCommandSetPidFile(cmd, pidfile);
+ virCommandSetPidFile(cmd, priv->pidfile);
virCommandDaemonize(cmd);
virCommandRequireHandshake(cmd);
ret = virCommandRun(cmd, NULL);
- VIR_FREE(pidfile);
/* wait for qemu process to show up */
if (ret == 0) {
- if (virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) {
+ if (virFileReadPidPath(priv->pidfile, &vm->pid)) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("Domain %s didn't show up"), vm->def->name);
ret = -1;
priv->nvcpupids = 0;
qemuCapsFree(priv->qemuCaps);
priv->qemuCaps = NULL;
+ VIR_FREE(priv->pidfile);
/* The "release" hook cleans up additional resources */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
return rc;
}
-int virFileReadPid(const char *dir,
- const char *name,
- pid_t *pid)
+
+int virFileReadPidPath(const char *path,
+ pid_t *pid)
{
- int rc;
FILE *file;
- char *pidfile = NULL;
+ int rc;
+
*pid = 0;
- if (name == NULL || dir == NULL) {
- rc = EINVAL;
+ if (!(file = fopen(path, "r"))) {
+ rc = errno;
goto cleanup;
}
- if (!(pidfile = virFilePid(dir, name))) {
- rc = ENOMEM;
+ if (fscanf(file, "%d", pid) != 1) {
+ rc = EINVAL;
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (!(file = fopen(pidfile, "r"))) {
+ if (VIR_FCLOSE(file) < 0) {
rc = errno;
goto cleanup;
}
- if (fscanf(file, "%d", pid) != 1) {
+ rc = 0;
+
+ cleanup:
+ return rc;
+}
+
+
+int virFileReadPid(const char *dir,
+ const char *name,
+ pid_t *pid)
+{
+ int rc;
+ char *pidfile = NULL;
+ *pid = 0;
+
+ if (name == NULL || dir == NULL) {
rc = EINVAL;
- VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (VIR_FCLOSE(file) < 0) {
- rc = errno;
+ if (!(pidfile = virFilePid(dir, name))) {
+ rc = ENOMEM;
goto cleanup;
}
- rc = 0;
+ rc = virFileReadPidPath(pidfile, pid);
cleanup:
VIR_FREE(pidfile);