]> xenbits.xensource.com Git - libvirt.git/commitdiff
tools: prefer g_strdup to vshStrdup
authorJán Tomko <jtomko@redhat.com>
Fri, 18 Oct 2019 15:24:02 +0000 (17:24 +0200)
committerJán Tomko <jtomko@redhat.com>
Sun, 20 Oct 2019 12:37:16 +0000 (14:37 +0200)
Remove all the uses of vshStrdup in favor of GLib's g_strdup.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
tools/virsh-checkpoint.c
tools/virsh-domain-monitor.c
tools/virsh-domain.c
tools/virsh-nodedev.c
tools/virsh-pool.c
tools/virsh-snapshot.c
tools/virsh-volume.c
tools/virsh.c
tools/virt-admin.c
tools/vsh.c

index 08f8fded86405ed3660f0710db7ab17cc1a335da..7fd3914ef219d054eb01d167182184b85be59603 100644 (file)
@@ -127,7 +127,7 @@ cmdCheckpointCreate(vshControl *ctl,
     if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0)
         goto cleanup;
     if (!from) {
-        buffer = vshStrdup(ctl, "<domaincheckpoint/>");
+        buffer = g_strdup("<domaincheckpoint/>");
     } else {
         if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
             vshSaveLibvirtError();
@@ -426,7 +426,7 @@ virshGetCheckpointParent(vshControl *ctl,
     parent = virDomainCheckpointGetParent(checkpoint, 0);
     if (parent) {
         /* API works, and virDomainCheckpointGetName will succeed */
-        *parent_name = vshStrdup(ctl, virDomainCheckpointGetName(parent));
+        *parent_name = g_strdup(virDomainCheckpointGetName(parent));
         ret = 0;
     } else if (last_error->code == VIR_ERR_NO_DOMAIN_CHECKPOINT) {
         /* API works, and we found a root with no parent */
index 739c8df381d3ed5d4ffbb66a59618b5a97154818..bfff08b0f6f8c13dcdf6bc17ab9f1bfaf47d6d39 100644 (file)
@@ -73,7 +73,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
         int errCode = virGetLastErrorCode();
 
         if (errCode == VIR_ERR_NO_DOMAIN_METADATA) {
-            desc = vshStrdup(ctl, "");
+            desc = g_strdup("");
             vshResetLibvirtError();
             return desc;
         }
@@ -92,7 +92,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
         desc = virXPathString("string(./description[1])", ctxt);
 
     if (!desc)
-        desc = vshStrdup(ctl, "");
+        desc = g_strdup("");
 
  cleanup:
     xmlXPathFreeContext(ctxt);
@@ -2419,7 +2419,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
             ip_addr_str = virBufferContentAndReset(&buf);
 
             if (!ip_addr_str)
-                ip_addr_str = vshStrdup(ctl, "");
+                ip_addr_str = g_strdup("");
 
             /* Don't repeat interface name */
             if (full || !j)
index b1618960b1df44d35f6f53ca1911cf648947cebf..2f3ac2d43007b41d5bf19e5b7520073b56cbba68 100644 (file)
@@ -5085,7 +5085,7 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
     int rv;
 
     while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
-        set_field = vshStrdup(ctl, opt->data);
+        set_field = g_strdup(opt->data);
         if (!(set_val = strchr(set_field, '='))) {
             vshError(ctl, "%s", _("Invalid syntax for --set, "
                                   "expecting name=value"));
@@ -11481,7 +11481,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
                 VIR_FREE(listen_addr);
 
                 if (uri) {
-                    listen_addr = vshStrdup(ctl, uri->server);
+                    listen_addr = g_strdup(uri->server);
                     virURIFree(uri);
                 }
             }
index 455ddedc2d4e04664974f05e45a77897b11996e7..cb2fc26d1ab9cc2e89a302994b892ee9c3399692 100644 (file)
@@ -477,13 +477,12 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
         struct virshNodeList arrays = { names, parents };
 
         for (i = 0; i < list->ndevices; i++)
-            names[i] = vshStrdup(ctl, virNodeDeviceGetName(list->devices[i]));
+            names[i] = g_strdup(virNodeDeviceGetName(list->devices[i]));
 
         for (i = 0; i < list->ndevices; i++) {
             virNodeDevicePtr dev = list->devices[i];
             if (STRNEQ(names[i], "computer")) {
-                const char *parent = virNodeDeviceGetParent(dev);
-                parents[i] = parent ? vshStrdup(ctl, parent) : NULL;
+                parents[i] = g_strdup(virNodeDeviceGetParent(dev));
             } else {
                 parents[i] = NULL;
             }
index bb25840943caf7b360594365a77e5b8f95b18a43..bd876aefdae3865618aae9352d09bc19386fd5a3 100644 (file)
@@ -1247,10 +1247,9 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
 
         /* Retrieve the autostart status of the pool */
         if (virStoragePoolGetAutostart(list->pools[i], &autostart) < 0)
-            poolInfoTexts[i].autostart = vshStrdup(ctl, _("no autostart"));
+            poolInfoTexts[i].autostart = g_strdup(_("no autostart"));
         else
-            poolInfoTexts[i].autostart = vshStrdup(ctl, autostart ?
-                                                    _("yes") : _("no"));
+            poolInfoTexts[i].autostart = g_strdup(autostart ? _("yes") : _("no"));
 
         /* Retrieve the persistence status of the pool */
         if (details) {
@@ -1258,28 +1257,27 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
             vshDebug(ctl, VSH_ERR_DEBUG, "Persistent flag value: %d\n",
                      persistent);
             if (persistent < 0)
-                poolInfoTexts[i].persistent = vshStrdup(ctl, _("unknown"));
+                poolInfoTexts[i].persistent = g_strdup(_("unknown"));
             else
-                poolInfoTexts[i].persistent = vshStrdup(ctl, persistent ?
-                                                         _("yes") : _("no"));
+                poolInfoTexts[i].persistent = g_strdup(persistent ? _("yes") : _("no"));
         }
 
         /* Collect further extended information about the pool */
         if (virStoragePoolGetInfo(list->pools[i], &info) != 0) {
             /* Something went wrong retrieving pool info, cope with it */
             vshError(ctl, "%s", _("Could not retrieve pool information"));
-            poolInfoTexts[i].state = vshStrdup(ctl, _("unknown"));
+            poolInfoTexts[i].state = g_strdup(_("unknown"));
             if (details) {
-                poolInfoTexts[i].capacity = vshStrdup(ctl, _("unknown"));
-                poolInfoTexts[i].allocation = vshStrdup(ctl, _("unknown"));
-                poolInfoTexts[i].available = vshStrdup(ctl, _("unknown"));
+                poolInfoTexts[i].capacity = g_strdup(_("unknown"));
+                poolInfoTexts[i].allocation = g_strdup(_("unknown"));
+                poolInfoTexts[i].available = g_strdup(_("unknown"));
             }
         } else {
             /* Decide which state string to display */
             if (details) {
                 const char *state = virshStoragePoolStateToString(info.state);
 
-                poolInfoTexts[i].state = vshStrdup(ctl, state);
+                poolInfoTexts[i].state = g_strdup(state);
 
                 /* Create the pool size related strings */
                 if (info.state == VIR_STORAGE_POOL_RUNNING ||
@@ -1303,17 +1301,17 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
                         goto cleanup;
                 } else {
                     /* Capacity related information isn't available */
-                    poolInfoTexts[i].capacity = vshStrdup(ctl, _("-"));
-                    poolInfoTexts[i].allocation = vshStrdup(ctl, _("-"));
-                    poolInfoTexts[i].available = vshStrdup(ctl, _("-"));
+                    poolInfoTexts[i].capacity = g_strdup(_("-"));
+                    poolInfoTexts[i].allocation = g_strdup(_("-"));
+                    poolInfoTexts[i].available = g_strdup(_("-"));
                 }
             } else {
                 /* --details option was not specified, only active/inactive
                  * state strings are used */
                 if (virStoragePoolIsActive(list->pools[i]))
-                    poolInfoTexts[i].state = vshStrdup(ctl, _("active"));
+                    poolInfoTexts[i].state = g_strdup(_("active"));
                 else
-                    poolInfoTexts[i].state = vshStrdup(ctl, _("inactive"));
+                    poolInfoTexts[i].state = g_strdup(_("inactive"));
            }
         }
     }
index eae19ecd27f971bbe713809711cb538b4496a33c..751186ebf80ce6145e6f6b4a7c946ebe06c52d22 100644 (file)
@@ -197,7 +197,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0)
         goto cleanup;
     if (!from) {
-        buffer = vshStrdup(ctl, "<domainsnapshot/>");
+        buffer = g_strdup("<domainsnapshot/>");
     } else {
         if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
             vshSaveLibvirtError();
@@ -755,7 +755,7 @@ virshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
         parent = virDomainSnapshotGetParent(snapshot, 0);
         if (parent) {
             /* API works, and virDomainSnapshotGetName will succeed */
-            *parent_name = vshStrdup(ctl, virDomainSnapshotGetName(parent));
+            *parent_name = g_strdup(virDomainSnapshotGetName(parent));
             ret = 0;
             goto cleanup;
         }
@@ -1236,7 +1236,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
                                                        count - 1, flags);
             if (count >= 0) {
                 count++;
-                names[0] = vshStrdup(ctl, fromname);
+                names[0] = g_strdup(fromname);
             }
         } else {
             count = virDomainSnapshotListChildrenNames(from, names,
index 702d0109adf8282ae97d6c35f719b8265d713fc3..d09d4435adcc105a13607e85810db5fb921cfbad 100644 (file)
@@ -1413,22 +1413,21 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
         /* Retrieve the volume path */
         if ((volInfoTexts[i].path = virStorageVolGetPath(vol)) == NULL) {
             /* Something went wrong retrieving a volume path, cope with it */
-            volInfoTexts[i].path = vshStrdup(ctl, _("unknown"));
+            volInfoTexts[i].path = g_strdup(_("unknown"));
         }
 
         /* If requested, retrieve volume type and sizing information */
         if (details) {
             if (virStorageVolGetInfo(vol, &volumeInfo) != 0) {
                 /* Something went wrong retrieving volume info, cope with it */
-                volInfoTexts[i].allocation = vshStrdup(ctl, _("unknown"));
-                volInfoTexts[i].capacity = vshStrdup(ctl, _("unknown"));
-                volInfoTexts[i].type = vshStrdup(ctl, _("unknown"));
+                volInfoTexts[i].allocation = g_strdup(_("unknown"));
+                volInfoTexts[i].capacity = g_strdup(_("unknown"));
+                volInfoTexts[i].type = g_strdup(_("unknown"));
             } else {
                 /* Convert the returned volume info into output strings */
 
                 /* Volume type */
-                volInfoTexts[i].type = vshStrdup(ctl,
-                                                 virshVolumeTypeToString(volumeInfo.type));
+                volInfoTexts[i].type = g_strdup(virshVolumeTypeToString(volumeInfo.type));
 
                 val = vshPrettyCapacity(volumeInfo.capacity, &unit);
                 if (virAsprintf(&volInfoTexts[i].capacity,
index a3553ddd36daf29f7529452f86fd592ee15a1c95..8c0e9d960d9d6f5aaa1256163f902bd0c072dfc8 100644 (file)
@@ -236,7 +236,7 @@ virshReconnect(vshControl *ctl, const char *name, bool readonly, bool force)
     } else {
         if (name) {
             VIR_FREE(ctl->connname);
-            ctl->connname = vshStrdup(ctl, name);
+            ctl->connname = g_strdup(name);
         }
 
         priv->readonly = readonly;
@@ -677,7 +677,7 @@ virshParseArgv(vshControl *ctl, int argc, char **argv)
         switch (arg) {
         case 'c':
             VIR_FREE(ctl->connname);
-            ctl->connname = vshStrdup(ctl, optarg);
+            ctl->connname = g_strdup(optarg);
             break;
         case 'd':
             if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
@@ -742,7 +742,7 @@ virshParseArgv(vshControl *ctl, int argc, char **argv)
             break;
         case 'l':
             vshCloseLogFile(ctl);
-            ctl->logfile = vshStrdup(ctl, optarg);
+            ctl->logfile = g_strdup(optarg);
             vshOpenLogFile(ctl);
             break;
         case 'q':
@@ -906,8 +906,7 @@ main(int argc, char **argv)
     }
 
     if (!ctl->connname)
-        ctl->connname = vshStrdup(ctl,
-                                  getenv("VIRSH_DEFAULT_CONNECT_URI"));
+        ctl->connname = g_strdup(getenv("VIRSH_DEFAULT_CONNECT_URI"));
 
     if (!ctl->imode) {
         ret = vshCommandRun(ctl, ctl->cmd);
index 3aada5f963c8212ca1a4ee26b52daf38580b2c6c..f3ae011cf44b2f3415d5ad6a59ab846768bc41c2 100644 (file)
@@ -343,7 +343,7 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
 
     if (name) {
         VIR_FREE(ctl->connname);
-        ctl->connname = vshStrdup(ctl, name);
+        ctl->connname = g_strdup(name);
     }
 
     vshAdmReconnect(ctl);
@@ -1295,7 +1295,7 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **argv)
         switch (arg) {
         case 'c':
             VIR_FREE(ctl->connname);
-            ctl->connname = vshStrdup(ctl, optarg);
+            ctl->connname = g_strdup(optarg);
             break;
         case 'd':
             if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
@@ -1315,7 +1315,7 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **argv)
             break;
         case 'l':
             vshCloseLogFile(ctl);
-            ctl->logfile = vshStrdup(ctl, optarg);
+            ctl->logfile = g_strdup(optarg);
             vshOpenLogFile(ctl);
             break;
         case 'q':
index 9ee3f99ff3bdf979c23dac4f9cd091f996cf9345..baba5ec314a4013f27020dfd42defb419071ae92 100644 (file)
@@ -176,7 +176,7 @@ int
 vshStringToArray(const char *str,
                  char ***array)
 {
-    char *str_copied = vshStrdup(NULL, str);
+    char *str_copied = g_strdup(str);
     char *str_tok = NULL;
     char *tmp;
     unsigned int nstr_tokens = 0;
@@ -214,10 +214,10 @@ vshStringToArray(const char *str,
             continue;
         }
         *tmp++ = '\0';
-        arr[nstr_tokens++] = vshStrdup(NULL, str_tok);
+        arr[nstr_tokens++] = g_strdup(str_tok);
         str_tok = tmp;
     }
-    arr[nstr_tokens++] = vshStrdup(NULL, str_tok);
+    arr[nstr_tokens++] = g_strdup(str_tok);
 
     *array = arr;
     VIR_FREE(str_copied);
@@ -1451,7 +1451,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
                 /* aliases need to be resolved to the actual commands */
                 if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
                     VIR_FREE(tkdata);
-                    tkdata = vshStrdup(ctl, cmd->alias);
+                    tkdata = g_strdup(cmd->alias);
                     cmd = vshCmddefSearch(tkdata);
                 }
                 if (vshCmddefOptParse(cmd, &opts_need_arg,
@@ -1472,7 +1472,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
 
                 if (optstr) {
                     *optstr = '\0'; /* convert the '=' to '\0' */
-                    optstr = vshStrdup(ctl, optstr + 1);
+                    optstr = g_strdup(optstr + 1);
                 }
                 /* Special case 'help' to ignore all spurious options */
                 if (!(opt = vshCmddefGetOption(ctl, cmd, tkdata + 2,
@@ -1582,7 +1582,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
                 vshCommandOptFree(first);
                 first = vshMalloc(ctl, sizeof(vshCmdOpt));
                 first->def = help->opts;
-                first->data = vshStrdup(ctl, cmd->name);
+                first->data = g_strdup(cmd->name);
                 first->next = NULL;
 
                 cmd = help;
@@ -1686,7 +1686,7 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res,
     bool double_quote = false;
     int sz = 0;
     char *p = parser->pos;
-    char *q = vshStrdup(ctl, p);
+    char *q = g_strdup(p);
 
     *res = q;
 
@@ -1834,11 +1834,11 @@ vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
         break;
 
     case VIR_TYPED_PARAM_BOOLEAN:
-        str = vshStrdup(ctl, item->value.b ? _("yes") : _("no"));
+        str = g_strdup(item->value.b ? _("yes") : _("no"));
         break;
 
     case VIR_TYPED_PARAM_STRING:
-        str = vshStrdup(ctl, item->value.s);
+        str = g_strdup(item->value.s);
         break;
 
     default:
@@ -2668,7 +2668,7 @@ vshReadlineCommandGenerator(const char *text)
                         virStringListFree(ret);
                         return NULL;
                     }
-                    ret[ret_size] = vshStrdup(NULL, name);
+                    ret[ret_size] = g_strdup(name);
                     ret_size++;
                     /* Terminate the string list properly. */
                     ret[ret_size] = NULL;
@@ -2820,7 +2820,7 @@ vshReadlineParse(const char *text, int state)
     char *ret = NULL;
 
     if (!state) {
-        char *buf = vshStrdup(NULL, rl_line_buffer);
+        char *buf = g_strdup(rl_line_buffer);
 
         vshCommandFree(partial);
         partial = NULL;
@@ -2882,7 +2882,7 @@ vshReadlineParse(const char *text, int state)
     }
 
     if (list) {
-        ret = vshStrdup(NULL, list[list_index]);
+        ret = g_strdup(list[list_index]);
         list_index++;
     }
 
@@ -3055,7 +3055,7 @@ vshReadline(vshControl *ctl, const char *prompt)
     if (len > 0 && r[len-1] == '\n')
         r[len-1] = '\0';
 
-    return vshStrdup(ctl, r);
+    return g_strdup(r);
 }
 
 #endif /* !WITH_READLINE */
@@ -3095,7 +3095,7 @@ vshInitDebug(vshControl *ctl)
         /* log file not set from cmdline */
         debugEnv = getenv(env);
         if (debugEnv && *debugEnv) {
-            ctl->logfile = vshStrdup(ctl, debugEnv);
+            ctl->logfile = g_strdup(debugEnv);
             vshOpenLogFile(ctl);
         }
         VIR_FREE(env);
@@ -3345,7 +3345,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
             }
             str = virBufferContentAndReset(&xmlbuf);
         } else {
-            str = vshStrdup(ctl, arg);
+            str = g_strdup(arg);
         }
 
         if (shell)