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>
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();
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 */
int errCode = virGetLastErrorCode();
if (errCode == VIR_ERR_NO_DOMAIN_METADATA) {
- desc = vshStrdup(ctl, "");
+ desc = g_strdup("");
vshResetLibvirtError();
return desc;
}
desc = virXPathString("string(./description[1])", ctxt);
if (!desc)
- desc = vshStrdup(ctl, "");
+ desc = g_strdup("");
cleanup:
xmlXPathFreeContext(ctxt);
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)
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"));
VIR_FREE(listen_addr);
if (uri) {
- listen_addr = vshStrdup(ctl, uri->server);
+ listen_addr = g_strdup(uri->server);
virURIFree(uri);
}
}
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;
}
/* 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) {
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 ||
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"));
}
}
}
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();
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;
}
count - 1, flags);
if (count >= 0) {
count++;
- names[0] = vshStrdup(ctl, fromname);
+ names[0] = g_strdup(fromname);
}
} else {
count = virDomainSnapshotListChildrenNames(from, names,
/* 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,
} else {
if (name) {
VIR_FREE(ctl->connname);
- ctl->connname = vshStrdup(ctl, name);
+ ctl->connname = g_strdup(name);
}
priv->readonly = readonly;
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) {
break;
case 'l':
vshCloseLogFile(ctl);
- ctl->logfile = vshStrdup(ctl, optarg);
+ ctl->logfile = g_strdup(optarg);
vshOpenLogFile(ctl);
break;
case 'q':
}
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);
if (name) {
VIR_FREE(ctl->connname);
- ctl->connname = vshStrdup(ctl, name);
+ ctl->connname = g_strdup(name);
}
vshAdmReconnect(ctl);
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) {
break;
case 'l':
vshCloseLogFile(ctl);
- ctl->logfile = vshStrdup(ctl, optarg);
+ ctl->logfile = g_strdup(optarg);
vshOpenLogFile(ctl);
break;
case 'q':
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;
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);
/* 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,
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,
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;
bool double_quote = false;
int sz = 0;
char *p = parser->pos;
- char *q = vshStrdup(ctl, p);
+ char *q = g_strdup(p);
*res = q;
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:
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;
char *ret = NULL;
if (!state) {
- char *buf = vshStrdup(NULL, rl_line_buffer);
+ char *buf = g_strdup(rl_line_buffer);
vshCommandFree(partial);
partial = NULL;
}
if (list) {
- ret = vshStrdup(NULL, list[list_index]);
+ ret = g_strdup(list[list_index]);
list_index++;
}
if (len > 0 && r[len-1] == '\n')
r[len-1] = '\0';
- return vshStrdup(ctl, r);
+ return g_strdup(r);
}
#endif /* !WITH_READLINE */
/* 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);
}
str = virBufferContentAndReset(&xmlbuf);
} else {
- str = vshStrdup(ctl, arg);
+ str = g_strdup(arg);
}
if (shell)