]> xenbits.xensource.com Git - libvirt.git/commitdiff
More usage of virGetLastErrorMessage
authorJovanka Gulicoska <jovanka.gulicoska@gmail.com>
Thu, 19 May 2016 19:10:19 +0000 (21:10 +0200)
committerCole Robinson <crobinso@redhat.com>
Thu, 19 May 2016 19:17:03 +0000 (15:17 -0400)
Convert to virGetLastErrorMessage() in the rest of the code

19 files changed:
daemon/libvirtd.c
examples/object-events/event-test.c
src/bhyve/bhyve_driver.c
src/conf/virsecretobj.c
src/libvirt.c
src/libxl/libxl_domain.c
src/libxl/libxl_driver.c
src/locking/lock_daemon.c
src/logging/log_daemon.c
src/lxc/lxc_container.c
src/lxc/lxc_controller.c
src/lxc/lxc_domain.c
src/lxc/lxc_process.c
src/rpc/virnettlscontext.c
src/storage/storage_driver.c
src/uml/uml_driver.c
src/util/iohelper.c
src/util/virhook.c
src/util/virhostdev.c

index f24fb2200726aad640c2e1e3b3074f62ecdc42d7..5617e42afa223341b2eab1eabe306ae36a298dfa 100644 (file)
@@ -1315,12 +1315,8 @@ int main(int argc, char **argv) {
     /* 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);
     }
 
index 20635365782079a93216f31258e6ca0209863bb6..c1ff4a7c854969ddedb6bab5af8ee4705762a499 100644 (file)
@@ -917,9 +917,8 @@ main(int argc, char **argv)
     }
 
     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;
     }
 
@@ -972,17 +971,15 @@ main(int argc, char **argv)
         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());
         }
     }
 
index 441c666174ac8bc49aa346a985cb067f3c88b692..c58286fd8798ae3f685d9698f29569838b96b241 100644 (file)
@@ -88,9 +88,8 @@ bhyveAutostartDomain(virDomainObjPtr vm, void *opaque)
         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);
index 4babd31549d7e94d99f0bd5f7b11a357a1e46eb7..c46d22c112d2b7514ef26283f9e2d8580e798034 100644 (file)
@@ -990,11 +990,8 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets,
             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;
         }
index 114e88ca8f9c236031f7b2d656b932c498da6f89..0e7e435bbfcb53340eae81831585ae08b115ad92 100644 (file)
@@ -770,10 +770,9 @@ virStateInitialize(bool privileged,
             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;
             }
         }
index 5fa1bd9f189185ae8c101a6659fd2f350ef28f44..113942bb8e03fb1cc15c5f1d3d8b9e755dbd5b8e 100644 (file)
@@ -515,9 +515,8 @@ libxlDomainShutdownThread(void *opaque)
     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:
index 2c19ddb36fb1fa373d0b6599e253295cc1f5da6a..b8b4c24ce215e3cb1e261241787e13f702458f82 100644 (file)
@@ -307,7 +307,6 @@ libxlAutostartDomain(virDomainObjPtr vm,
                      void *opaque)
 {
     libxlDriverPrivatePtr driver = opaque;
-    virErrorPtr err;
     int ret = -1;
 
     virObjectLock(vm);
@@ -320,10 +319,9 @@ libxlAutostartDomain(virDomainObjPtr 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;
     }
 
index f889a347dc24e53d01d580711dfe326e84d348f8..2c45349acdbd71b4da1906b57721e1072f6680bd 100644 (file)
@@ -1264,12 +1264,8 @@ int main(int argc, char **argv) {
     /* 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);
     }
 
index 90f84270ff337ef2180ca5d06c131ae5d71ac3ed..8f1ccc22c5992cc9cb8212cce89fbd1447f80a45 100644 (file)
@@ -1021,12 +1021,8 @@ int main(int argc, char **argv) {
     /* 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);
     }
 
index a909b660b3ae6efb4633519eeaa252115bd148f8..33dcfecf689c3a75e53c632a34ac9c6246ba40e2 100644 (file)
@@ -2290,12 +2290,9 @@ static int lxcContainerChild(void *data)
 
     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);
index 0304354b70ec0c0c73de2e4e9d3b57d0173c2789..dc3921b70e8d5f26165e201f3e1aeefaf6ae29c8 100644 (file)
@@ -2736,12 +2736,9 @@ int main(int argc, char *argv[])
 
  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);
index bca2bb21240816c03cc9fd99f3efd35f157c461e..f395d0dfd967794a50d88d74b2c437a7d20c4e0d 100644 (file)
@@ -353,8 +353,8 @@ virLXCDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
     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;
index 8981d9a0a1ac75de5448e43419966709f7c7e048..9f607d8a9d3ece04d922cc5e3740257122fcd4cc 100644 (file)
@@ -756,10 +756,9 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
     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);
@@ -1618,10 +1617,9 @@ virLXCProcessAutostartDomain(virDomainObjPtr vm,
                                  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,
index 947038dc38e30bbc90d6faccd185f9f11d82142d..6e78623f3f935d9ebdfb651e1d00367a9319f5e4 100644 (file)
@@ -1141,8 +1141,7 @@ int virNetTLSContextCheckCertificate(virNetTLSContextPtr ctxt,
     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"));
index 5dffcc8651b434fb2548b45644b933e1834577ab..ce31e38c1ec8a65dfca63215e10d046f4eea8881 100644 (file)
@@ -98,10 +98,8 @@ storagePoolUpdateState(virStoragePoolObjPtr pool)
     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;
     }
 
@@ -112,12 +110,10 @@ storagePoolUpdateState(virStoragePoolObjPtr pool)
     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;
         }
     }
@@ -176,10 +172,8 @@ storageDriverAutostart(void)
             !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;
             }
@@ -195,14 +189,12 @@ storageDriverAutostart(void)
             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;
             }
index 84e1df8928ba8f9e79dc81e0ca73bd895673d9e5..923c3f6e97b410131b5c268cc5697fb9580acb83 100644 (file)
@@ -188,9 +188,8 @@ umlAutostartDomain(virDomainObjPtr vm,
         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,
index 275f993abd4cf2bf57424a7b915a180713493374..00f31e7469bd1dce610ba896c06637e236deba5e 100644 (file)
@@ -218,7 +218,6 @@ int
 main(int argc, char **argv)
 {
     const char *path;
-    virErrorPtr err;
     unsigned long long offset;
     unsigned long long length;
     int oflags = -1;
@@ -303,12 +302,7 @@ main(int argc, char **argv)
     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);
 }
index ba505984ec9f89dfc3432d21e32227503f5acee4..d37d6da224848e6632bdc21d425a4c2dca44cf25 100644 (file)
@@ -297,9 +297,8 @@ virHookCall(int driver,
     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);
index 980e590ce6d5b74fd65b715ba75cedb6ddafa851..9b5ca6f41059303a071b6eb41112361ef076cc84 100644 (file)
@@ -782,10 +782,9 @@ virHostdevReattachPCIDevice(virHostdevManagerPtr mgr,
     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();
     }
 }
 
@@ -810,10 +809,9 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
     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;
     }
 
@@ -864,10 +862,9 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
         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();
         }
     }
 
@@ -909,10 +906,9 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
         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();
         }
     }