[libvirt] [PATCH 05/34] Use g_strdup instead of ignoring VIR_STRDUP_QUIET's value

Ján Tomko jtomko at redhat.com
Sun Oct 20 12:55:23 UTC 2019


Replace all the occurrences of
  ignore_value(VIR_STRDUP_QUIET(a, b));
with
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/locking/lock_driver_sanlock.c |  2 +-
 src/qemu/qemu_process.c           | 14 +++++++-------
 src/util/virerror.c               | 11 +++++------
 src/util/virfile.c                |  4 ++--
 src/util/virstoragefile.c         |  2 +-
 src/util/virutil.c                |  8 ++++----
 tests/networkxml2firewalltest.c   |  4 ++--
 tests/virfilemock.c               |  2 +-
 8 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index 9cedf39578..1d1691f6ba 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -101,7 +101,7 @@ virLockManagerSanlockError(int err,
 {
     if (err <= -200) {
 #if HAVE_SANLOCK_STRERROR
-        ignore_value(VIR_STRDUP_QUIET(*message, sanlock_strerror(err)));
+        *message = g_strdup(sanlock_strerror(err));
 #else
         ignore_value(virAsprintfQuiet(message, _("sanlock error %d"), err));
 #endif
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 9eaea4edfd..843e852591 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -959,7 +959,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon G_GNUC_UNUSED,
         /* We have a SYNC API waiting for this event, dispatch it back */
         job->newstate = status;
         VIR_FREE(job->errmsg);
-        ignore_value(VIR_STRDUP_QUIET(job->errmsg, error));
+        job->errmsg = g_strdup(error);
         virDomainObjBroadcast(vm);
     } else {
         /* there is no waiting SYNC API, dispatch the update to a thread */
@@ -1749,11 +1749,11 @@ qemuProcessHandleDumpCompleted(qemuMonitorPtr mon G_GNUC_UNUSED,
     }
     priv->job.dumpCompleted = true;
     priv->job.current->stats.dump = *stats;
-    ignore_value(VIR_STRDUP_QUIET(priv->job.error, error));
+    priv->job.error = g_strdup(error);
 
     /* Force error if extracting the DUMP_COMPLETED status failed */
     if (!error && status < 0) {
-        ignore_value(VIR_STRDUP_QUIET(priv->job.error, virGetLastErrorMessage()));
+        priv->job.error = g_strdup(virGetLastErrorMessage());
         priv->job.current->stats.dump.status = QEMU_MONITOR_DUMP_STATUS_FAILED;
     }
 
@@ -3407,20 +3407,20 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
           oldReason == VIR_DOMAIN_PAUSED_STARTING_UP))) {
         newState = VIR_DOMAIN_RUNNING;
         newReason = VIR_DOMAIN_RUNNING_BOOTED;
-        ignore_value(VIR_STRDUP_QUIET(msg, "finished booting"));
+        msg = g_strdup("finished booting");
     } else if (state == VIR_DOMAIN_PAUSED && running) {
         newState = VIR_DOMAIN_RUNNING;
         newReason = VIR_DOMAIN_RUNNING_UNPAUSED;
-        ignore_value(VIR_STRDUP_QUIET(msg, "was unpaused"));
+        msg = g_strdup("was unpaused");
     } else if (state == VIR_DOMAIN_RUNNING && !running) {
         if (reason == VIR_DOMAIN_PAUSED_SHUTTING_DOWN) {
             newState = VIR_DOMAIN_SHUTDOWN;
             newReason = VIR_DOMAIN_SHUTDOWN_UNKNOWN;
-            ignore_value(VIR_STRDUP_QUIET(msg, "shutdown"));
+            msg = g_strdup("shutdown");
         } else if (reason == VIR_DOMAIN_PAUSED_CRASHED) {
             newState = VIR_DOMAIN_CRASHED;
             newReason = VIR_DOMAIN_CRASHED_PANICKED;
-            ignore_value(VIR_STRDUP_QUIET(msg, "crashed"));
+            msg = g_strdup("crashed");
         } else {
             newState = VIR_DOMAIN_PAUSED;
             newReason = reason;
diff --git a/src/util/virerror.c b/src/util/virerror.c
index b45c53b7df..512b2bc7fe 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -187,8 +187,7 @@ virErrorGenericFailure(virErrorPtr err)
     err->code = VIR_ERR_INTERNAL_ERROR;
     err->domain = VIR_FROM_NONE;
     err->level = VIR_ERR_ERROR;
-    ignore_value(VIR_STRDUP_QUIET(err->message,
-                                  _("An error occurred, but the cause is unknown")));
+    err->message = g_strdup(_("An error occurred, but the cause is unknown"));
 }
 
 
@@ -831,7 +830,7 @@ virRaiseErrorFull(const char *filename,
      * formats the message; drop message on OOM situations
      */
     if (fmt == NULL) {
-        ignore_value(VIR_STRDUP_QUIET(str, _("No error message provided")));
+        str = g_strdup(_("No error message provided"));
     } else {
         va_list ap;
         va_start(ap, fmt);
@@ -850,9 +849,9 @@ virRaiseErrorFull(const char *filename,
     to->code = code;
     to->message = str;
     to->level = level;
-    ignore_value(VIR_STRDUP_QUIET(to->str1, str1));
-    ignore_value(VIR_STRDUP_QUIET(to->str2, str2));
-    ignore_value(VIR_STRDUP_QUIET(to->str3, str3));
+    to->str1 = g_strdup(str1);
+    to->str2 = g_strdup(str2);
+    to->str3 = g_strdup(str3);
     to->int1 = int1;
     to->int2 = int2;
 
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 2fb389eeb2..15713a58d9 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1264,7 +1264,7 @@ virFileFindMountPoint(const char *type)
 
     while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) {
         if (STREQ(mb.mnt_type, type)) {
-            ignore_value(VIR_STRDUP_QUIET(ret, mb.mnt_dir));
+            ret = g_strdup(mb.mnt_dir);
             goto cleanup;
         }
     }
@@ -1667,7 +1667,7 @@ virFindFileInPath(const char *file)
     if (IS_ABSOLUTE_FILE_NAME(file)) {
         char *ret = NULL;
         if (virFileIsExecutable(file))
-            ignore_value(VIR_STRDUP_QUIET(ret, file));
+            ret = g_strdup(file);
         return ret;
     }
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 098d2684cc..64e09d7951 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1711,7 +1711,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
                 if (*parent && virStorageSourceIsLocalStorage(*parent))
                     parentDir = mdir_name((*parent)->path);
                 else
-                    ignore_value(VIR_STRDUP_QUIET(parentDir, "."));
+                    parentDir = g_strdup(".");
 
                 if (!parentDir) {
                     virReportOOMError();
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 637d19e46c..63071e2fa6 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -523,7 +523,7 @@ virGetHostnameImpl(bool quiet)
          * string as-is; it's up to callers to check whether "localhost"
          * is allowed.
          */
-        ignore_value(VIR_STRDUP_QUIET(result, hostname));
+        result = g_strdup(hostname);
         goto cleanup;
     }
 
@@ -539,7 +539,7 @@ virGetHostnameImpl(bool quiet)
         if (!quiet)
             VIR_WARN("getaddrinfo failed for '%s': %s",
                      hostname, gai_strerror(r));
-        ignore_value(VIR_STRDUP_QUIET(result, hostname));
+        result = g_strdup(hostname);
         goto cleanup;
     }
 
@@ -552,10 +552,10 @@ virGetHostnameImpl(bool quiet)
          * localhost.  Ignore the canonicalized name and just return the
          * original hostname
          */
-        ignore_value(VIR_STRDUP_QUIET(result, hostname));
+        result = g_strdup(hostname);
     else
         /* Caller frees this string. */
-        ignore_value(VIR_STRDUP_QUIET(result, info->ai_canonname));
+        result = g_strdup(info->ai_canonname);
 
     freeaddrinfo(info);
 
diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c
index e49eef6162..b8e974971a 100644
--- a/tests/networkxml2firewalltest.c
+++ b/tests/networkxml2firewalltest.c
@@ -53,8 +53,8 @@ testCommandDryRun(const char *const*args G_GNUC_UNUSED,
                   void *opaque G_GNUC_UNUSED)
 {
     *status = 0;
-    ignore_value(VIR_STRDUP_QUIET(*output, ""));
-    ignore_value(VIR_STRDUP_QUIET(*error, ""));
+    *output = g_strdup("");
+    *error = g_strdup("");
 }
 
 static int testCompareXMLToArgvFiles(const char *xml,
diff --git a/tests/virfilemock.c b/tests/virfilemock.c
index 6d1153dd9f..00efb820ad 100644
--- a/tests/virfilemock.c
+++ b/tests/virfilemock.c
@@ -190,7 +190,7 @@ canonicalize_file_name(const char *path)
         if ((p = STRSKIP(path, "/some/symlink")))
             ignore_value(virAsprintfQuiet(&ret, "/gluster%s", p));
         else
-            ignore_value(VIR_STRDUP_QUIET(ret, path));
+            ret = g_strdup(path);
 
         return ret;
     }
-- 
2.21.0




More information about the libvir-list mailing list