/* Read the config file if it exists*/
if (remote_config_file &&
daemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- VIR_ERROR(_("Can't load config file: %s: %s"),
- err->message, remote_config_file);
- else
- VIR_ERROR(_("Can't load config file: %s"), remote_config_file);
+ VIR_ERROR(_("Can't load config file: %s: %s"),
+ virGetLastErrorMessage(), remote_config_file);
exit(EXIT_FAILURE);
}
}
if (virEventRegisterDefaultImpl() < 0) {
- virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to register event implementation: %s\n",
- err && err->message ? err->message: "Unknown error");
+ virGetLastErrorMessage());
goto cleanup;
}
goto cleanup;
if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
- virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to start keepalive protocol: %s\n",
- err && err->message ? err->message : "Unknown error");
+ virGetLastErrorMessage());
run = 0;
}
while (run) {
if (virEventRunDefaultImpl() < 0) {
- virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to run event loop: %s\n",
- err && err->message ? err->message : "Unknown error");
+ virGetLastErrorMessage());
}
}
ret = virBhyveProcessStart(data->conn, data->driver, vm,
VIR_DOMAIN_RUNNING_BOOTED, 0);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
- vm->def->name, err ? err->message : _("unknown error"));
+ vm->def->name, virGetLastErrorMessage());
}
}
virObjectUnlock(vm);
continue;
if (!(secret = virSecretLoad(secrets, de->d_name, path, configDir))) {
- virErrorPtr err = virGetLastError();
-
VIR_ERROR(_("Error reading secret: %s"),
- err != NULL ? err->message: _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
VIR_FREE(path);
continue;
}
if (virStateDriverTab[i]->stateInitialize(privileged,
callback,
opaque) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Initialization of %s state driver failed: %s"),
virStateDriverTab[i]->name,
- err && err->message ? err->message : _("Unknown problem"));
+ virGetLastErrorMessage());
return -1;
}
}
libxlDomainDestroyInternal(driver, vm);
libxlDomainCleanup(driver, vm);
if (libxlDomainStartNew(driver, vm, false) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to restart VM '%s': %s"),
- vm->def->name, err ? err->message : _("unknown error"));
+ vm->def->name, virGetLastErrorMessage());
}
endjob:
void *opaque)
{
libxlDriverPrivatePtr driver = opaque;
- virErrorPtr err;
int ret = -1;
virObjectLock(vm);
if (vm->autostart && !virDomainObjIsActive(vm) &&
libxlDomainStartNew(driver, vm, false) < 0) {
- err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
vm->def->name,
- err ? err->message : _("unknown error"));
+ virGetLastErrorMessage());
goto endjob;
}
/* Read the config file if it exists*/
if (remote_config_file &&
virLockDaemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- VIR_ERROR(_("Can't load config file: %s: %s"),
- err->message, remote_config_file);
- else
- VIR_ERROR(_("Can't load config file: %s"), remote_config_file);
+ VIR_ERROR(_("Can't load config file: %s: %s"),
+ virGetLastErrorMessage(), remote_config_file);
exit(EXIT_FAILURE);
}
/* Read the config file if it exists*/
if (remote_config_file &&
virLogDaemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- VIR_ERROR(_("Can't load config file: %s: %s"),
- err->message, remote_config_file);
- else
- VIR_ERROR(_("Can't load config file: %s"), remote_config_file);
+ VIR_ERROR(_("Can't load config file: %s: %s"),
+ virGetLastErrorMessage(), remote_config_file);
exit(EXIT_FAILURE);
}
if (ret != 0) {
VIR_DEBUG("Tearing down container");
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- fprintf(stderr, "%s\n", err->message);
- else
- fprintf(stderr, "%s\n",
- _("Unknown failure in libvirt_lxc startup"));
+ fprintf(stderr,
+ _("Failure in libvirt_lxc startup: %s\n"),
+ virGetLastErrorMessage());
}
virCommandFree(cmd);
cleanup:
if (rc < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- fprintf(stderr, "%s\n", err->message);
- else
- fprintf(stderr, "%s\n",
- _("Unknown failure in libvirt_lxc startup"));
+ fprintf(stderr,
+ _("Failure in libvirt_lxc startup: %s\n"),
+ virGetLastErrorMessage());
}
virPidFileDelete(LXC_STATE_DIR, name);
unsigned long long thepid;
if (virXPathULongLong("string(./init[1]/@pid)", ctxt, &thepid) < 0) {
- virErrorPtr err = virGetLastError();
- VIR_WARN("Failed to load init pid from state %s", err ? err->message : "null");
+ VIR_WARN("Failed to load init pid from state %s",
+ virGetLastErrorMessage());
priv->initpid = 0;
} else {
priv->initpid = thepid;
priv->initpid = initpid;
if (virLXCProcessGetNsInode(initpid, "pid", &inode) < 0) {
- virErrorPtr err = virGetLastError();
VIR_WARN("Cannot obtain pid NS inode for %llu: %s",
(unsigned long long)initpid,
- err && err->message ? err->message : "<unknown>");
+ virGetLastErrorMessage());
virResetLastError();
}
virDomainAuditInit(vm, initpid, inode);
VIR_DOMAIN_RUNNING_BOOTED);
virDomainAuditStart(vm, "booted", ret >= 0);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
vm->def->name,
- err ? err->message : "");
+ virGetLastErrorMessage());
} else {
virObjectEventPtr event =
virDomainEventLifecycleNewFromObj(vm,
virObjectLock(ctxt);
virObjectLock(sess);
if (virNetTLSContextValidCertificate(ctxt, sess) < 0) {
- virErrorPtr err = virGetLastError();
- VIR_WARN("Certificate check failed %s", err && err->message ? err->message : "<unknown>");
+ VIR_WARN("Certificate check failed %s", virGetLastErrorMessage());
if (ctxt->requireValidCert) {
virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("Failed to verify peer's certificate"));
active = false;
if (backend->checkPool &&
backend->checkPool(pool, &active) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to initialize storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
goto error;
}
if (active) {
virStoragePoolObjClearVols(pool);
if (backend->refreshPool(NULL, pool) < 0) {
- virErrorPtr err = virGetLastError();
if (backend->stopPool)
backend->stopPool(NULL, pool);
VIR_ERROR(_("Failed to restart storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
goto error;
}
}
!virStoragePoolObjIsActive(pool)) {
if (backend->startPool &&
backend->startPool(conn, pool) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
virStoragePoolObjUnlock(pool);
continue;
}
if (!stateFile ||
virStoragePoolSaveState(stateFile, pool->def) < 0 ||
backend->refreshPool(conn, pool) < 0) {
- virErrorPtr err = virGetLastError();
if (stateFile)
unlink(stateFile);
if (backend->stopPool)
backend->stopPool(conn, pool);
VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
} else {
pool->active = true;
}
ret = umlStartVMDaemon(data->conn, data->driver, vm, false);
virDomainAuditStart(vm, "booted", ret >= 0);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
- vm->def->name, err ? err->message : _("unknown error"));
+ vm->def->name, virGetLastErrorMessage());
} else {
virObjectEventPtr event =
virDomainEventLifecycleNewFromObj(vm,
main(int argc, char **argv)
{
const char *path;
- virErrorPtr err;
unsigned long long offset;
unsigned long long length;
int oflags = -1;
return 0;
error:
- err = virGetLastError();
- if (err) {
- fprintf(stderr, "%s: %s\n", program_name, err->message);
- } else {
- fprintf(stderr, _("%s: unknown failure with %s\n"),
- program_name, path);
- }
+ fprintf(stderr, _("%s: failure with %s\n: %s"),
+ program_name, path, virGetLastErrorMessage());
exit(EXIT_FAILURE);
}
ret = virCommandRun(cmd, NULL);
if (ret < 0) {
/* Convert INTERNAL_ERROR into known error. */
- virErrorPtr err = virGetLastError();
virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s",
- err ? err->message : _("unknown error"));
+ virGetLastErrorMessage());
}
virCommandFree(cmd);
VIR_DEBUG("Reattaching PCI device %s", virPCIDeviceGetName(actual));
if (virPCIDeviceReattach(actual, mgr->activePCIHostdevs,
mgr->inactivePCIHostdevs) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to re-attach PCI device: %s"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
}
}
virObjectLock(mgr->inactivePCIHostdevs);
if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to allocate PCI device list: %s"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
goto cleanup;
}
if (!actual ||
virPCIDeviceListAdd(mgr->inactivePCIHostdevs, actual) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to add PCI device %s to the inactive list"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
}
}
VIR_DEBUG("Resetting PCI device %s", virPCIDeviceGetName(pci));
if (virPCIDeviceReset(pci, mgr->activePCIHostdevs,
mgr->inactivePCIHostdevs) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to reset PCI device: %s"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
}
}