if (virMacAddrParse(iface, &macaddr) == 0)
virMacAddrFormat(&macaddr, macstr);
- if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address = '%s') or "
- " (target/@dev = '%s')]",
- macstr, iface) < 0)
- return NULL;
+ xpath = g_strdup_printf("/domain/devices/interface[(mac/@address = '%s') or "
+ " (target/@dev = '%s')]", macstr,
+ iface);
if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0)
return NULL;
if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0)
return NULL;
size = vshPrettyCapacity(byteval, &suffix);
- if (virAsprintf(&ret, "%.0f%s", size, suffix) < 0)
- return NULL;
+ ret = g_strdup_printf("%.0f%s", size, suffix);
return ret;
}
return NULL;
if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) > 0) {
- if (virAsprintf(&path,
- "/capabilities/host/topology/cells/cell[@id=\"%s\"]/pages",
- cellnum) < 0)
- return NULL;
+ path = g_strdup_printf("/capabilities/host/topology/cells/cell[@id=\"%s\"]/pages",
+ cellnum);
} else {
- if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0)
- return NULL;
+ path = g_strdup("/capabilities/host/cpu/pages");
}
npages = virXPathNodeSet(path, ctxt, &pages);
if (virStringListHasString((const char **)inputList, options[i]))
continue;
- if (inputCopy && virAsprintf(&ret[nret], "%s,%s", inputCopy, options[i]) < 0)
- return NULL;
- if (!inputCopy)
+ if (inputCopy)
+ ret[nret] = g_strdup_printf("%s,%s", inputCopy, options[i]);
+ else
ret[nret] = g_strdup(options[i]);
nret++;
*alloc = g_strdup("-");
*phy = g_strdup("-");
} else if (!human) {
- if (virAsprintf(cap, "%llu", info->capacity) < 0 ||
- virAsprintf(alloc, "%llu", info->allocation) < 0 ||
- virAsprintf(phy, "%llu", info->physical) < 0)
- return false;
+ *cap = g_strdup_printf("%llu", info->capacity);
+ *alloc = g_strdup_printf("%llu", info->allocation);
+ *phy = g_strdup_printf("%llu", info->physical);
} else {
double val_cap, val_alloc, val_phy;
const char *unit_cap, *unit_alloc, *unit_phy;
val_alloc = vshPrettyCapacity(info->allocation, &unit_alloc);
val_phy = vshPrettyCapacity(info->physical, &unit_phy);
- if (virAsprintf(cap, "%.3lf %s", val_cap, unit_cap) < 0 ||
- virAsprintf(alloc, "%.3lf %s", val_alloc, unit_alloc) < 0 ||
- virAsprintf(phy, "%.3lf %s", val_phy, unit_phy) < 0)
- return false;
+ *cap = g_strdup_printf("%.3lf %s", val_cap, unit_cap);
+ *alloc = g_strdup_printf("%.3lf %s", val_alloc, unit_alloc);
+ *phy = g_strdup_printf("%.3lf %s", val_phy, unit_phy);
}
return true;
if (virMacAddrParse(iface, &macaddr) == 0)
virMacAddrFormat(&macaddr, macstr);
- if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address = '%s') or "
- " (target/@dev = '%s')]",
- macstr, iface) < 0)
- goto cleanup;
+ xpath = g_strdup_printf("/domain/devices/interface[(mac/@address = '%s') or "
+ " (target/@dev = '%s')]", macstr,
+ iface);
if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) {
vshError(ctl, _("Failed to extract interface information"));
localtime_r(&cur_time, &time_info);
strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
- if (virAsprintf(&ret, "%s-%s%s", virDomainGetName(dom),
- timestr, NULLSTR_EMPTY(ext)) < 0) {
- vshError(ctl, "%s", _("Out of memory"));
- return NULL;
- }
+ ret = g_strdup_printf("%s-%s%s", virDomainGetName(dom), timestr,
+ NULLSTR_EMPTY(ext));
return ret;
}
cpumaplen)))
goto cleanup;
- if (virAsprintf(&vcpuStr, "%zu", i) < 0)
- goto cleanup;
+ vcpuStr = g_strdup_printf("%zu", i);
if (vshTableRowAppend(table, vcpuStr, pinInfo, NULL) < 0)
goto cleanup;
g_autofree char *pinInfo = NULL;
g_autofree char *iothreadIdStr = NULL;
- if (virAsprintf(&iothreadIdStr, "%u", info[i]->iothread_id) < 0)
- goto cleanup;
+ iothreadIdStr = g_strdup_printf("%u", info[i]->iothread_id);
ignore_value(pinInfo = virBitmapDataFormat(info[i]->cpumap, info[i]->cpumaplen));
/* Create our XPATH lookup for the current display's port */
VIR_FREE(xpath);
- if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@port") < 0)
- goto cleanup;
+ xpath = g_strdup_printf(xpath_fmt, scheme[iter], "@port");
/* Attempt to get the port number for the current graphics scheme */
tmp = virXPathInt(xpath, ctxt, &port);
/* Create our XPATH lookup for TLS Port (automatically skipped
* for unsupported schemes */
- if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@tlsPort") < 0)
- goto cleanup;
+ xpath = g_strdup_printf(xpath_fmt, scheme[iter], "@tlsPort");
/* Attempt to get the TLS port number */
tmp = virXPathInt(xpath, ctxt, &tls_port);
tls_port = 0;
/* Create our XPATH lookup for the current display's address */
- if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@listen") < 0)
- goto cleanup;
+ xpath = g_strdup_printf(xpath_fmt, scheme[iter], "@listen");
/* Attempt to get the listening addr if set for the current
* graphics scheme */
VIR_FREE(xpath);
/* Create our XPATH lookup for the current spice type. */
- if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@type") < 0)
- goto cleanup;
+ xpath = g_strdup_printf(xpath_fmt, scheme[iter], "listen/@type");
/* Attempt to get the type of spice connection */
VIR_FREE(type_conn);
if (STREQ_NULLABLE(type_conn, "socket")) {
if (!sockpath) {
- if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@socket") < 0)
- goto cleanup;
+ xpath = g_strdup_printf(xpath_fmt, scheme[iter], "listen/@socket");
sockpath = virXPathString(xpath, ctxt);
* subelement (which, by the way, doesn't exist on libvirt
* < 0.9.4, so we really do need to check both places)
*/
- if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@address") < 0)
- goto cleanup;
+ xpath = g_strdup_printf(xpath_fmt, scheme[iter], "listen/@address");
listen_addr = virXPathString(xpath, ctxt);
VIR_FREE(xpath);
* care of when getting the XML */
/* Create our XPATH lookup for the password */
- if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@passwd") < 0)
- goto cleanup;
+ xpath = g_strdup_printf(xpath_fmt, scheme[iter], "@passwd");
/* Attempt to get the password */
VIR_FREE(passwd);
else
doc = buffer;
- if (virAsprintf(&xmlStr, "<container>%s</container>", doc) < 0)
- goto error;
+ xmlStr = g_strdup_printf("<container>%s</container>", doc);
if (!(xml = virXMLParseStringCtxt(xmlStr, xmlFile, &ctxt)))
goto error;
goto cleanup;
}
- if (stp &&
- ((virAsprintf(&delay_str, "%d", delay) < 0) ||
- !xmlSetProp(br_node, BAD_CAST "delay", BAD_CAST delay_str))) {
- vshError(ctl, _("Failed to set bridge delay %d in xml document"), delay);
- goto cleanup;
+ if (stp) {
+ delay_str = g_strdup_printf("%d", delay);
+ if (!xmlSetProp(br_node, BAD_CAST "delay", BAD_CAST delay_str)) {
+ vshError(ctl, _("Failed to set bridge delay %d in xml document"), delay);
+ goto cleanup;
+ }
}
/* Change the type of the outer/master interface to "bridge" and the
else if (lease->type == VIR_IP_ADDR_TYPE_IPV6)
typestr = "ipv6";
- ignore_value(virAsprintf(&cidr_format, "%s/%d",
- lease->ipaddr, lease->prefix));
+ cidr_format = g_strdup_printf("%s/%d", lease->ipaddr, lease->prefix);
if (vshTableRowAppend(table,
expirytime,
const char *unit;
val = vshPrettyCapacity(info.capacity, &unit);
- if (virAsprintf(&poolInfoTexts[i].capacity,
- "%.2lf %s", val, unit) < 0)
- goto cleanup;
+ poolInfoTexts[i].capacity = g_strdup_printf("%.2lf %s", val,
+ unit);
val = vshPrettyCapacity(info.allocation, &unit);
- if (virAsprintf(&poolInfoTexts[i].allocation,
- "%.2lf %s", val, unit) < 0)
- goto cleanup;
+ poolInfoTexts[i].allocation = g_strdup_printf("%.2lf %s", val,
+ unit);
val = vshPrettyCapacity(info.available, &unit);
- if (virAsprintf(&poolInfoTexts[i].available,
- "%.2lf %s", val, unit) < 0)
- goto cleanup;
+ poolInfoTexts[i].available = g_strdup_printf("%.2lf %s", val,
+ unit);
} else {
/* Capacity related information isn't available */
poolInfoTexts[i].capacity = g_strdup(_("-"));
volInfoTexts[i].type = g_strdup(virshVolumeTypeToString(volumeInfo.type));
val = vshPrettyCapacity(volumeInfo.capacity, &unit);
- if (virAsprintf(&volInfoTexts[i].capacity,
- "%.2lf %s", val, unit) < 0)
- goto cleanup;
+ volInfoTexts[i].capacity = g_strdup_printf("%.2lf %s", val, unit);
val = vshPrettyCapacity(volumeInfo.allocation, &unit);
- if (virAsprintf(&volInfoTexts[i].allocation,
- "%.2lf %s", val, unit) < 0)
- goto cleanup;
+ volInfoTexts[i].allocation = g_strdup_printf("%.2lf %s", val,
+ unit);
}
}
}
for (i = 0; i < nsrvs; i++) {
g_autofree char *idStr = NULL;
- if (virAsprintf(&idStr, "%zu", i) < 0)
- goto cleanup;
+ idStr = g_strdup_printf("%zu", i);
if (vshTableRowAppend(table,
idStr,
×tr) < 0)
goto cleanup;
- if (virAsprintf(&idStr, "%llu", id) < 0)
- goto cleanup;
+ idStr = g_strdup_printf("%llu", id);
if (vshTableRowAppend(table, idStr,
vshAdmClientTransportToString(transport),
timestr, NULL) < 0)
char *
vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
{
- int ret = 0;
char *str = NULL;
switch (item->type) {
case VIR_TYPED_PARAM_INT:
- ret = virAsprintf(&str, "%d", item->value.i);
+ str = g_strdup_printf("%d", item->value.i);
break;
case VIR_TYPED_PARAM_UINT:
- ret = virAsprintf(&str, "%u", item->value.ui);
+ str = g_strdup_printf("%u", item->value.ui);
break;
case VIR_TYPED_PARAM_LLONG:
- ret = virAsprintf(&str, "%lld", item->value.l);
+ str = g_strdup_printf("%lld", item->value.l);
break;
case VIR_TYPED_PARAM_ULLONG:
- ret = virAsprintf(&str, "%llu", item->value.ul);
+ str = g_strdup_printf("%llu", item->value.ul);
break;
case VIR_TYPED_PARAM_DOUBLE:
- ret = virAsprintf(&str, "%f", item->value.d);
+ str = g_strdup_printf("%f", item->value.d);
break;
case VIR_TYPED_PARAM_BOOLEAN:
vshError(ctl, _("unimplemented parameter type %d"), item->type);
}
- if (ret < 0) {
+ if (!str) {
vshError(ctl, "%s", _("Out of memory"));
exit(EXIT_FAILURE);
}
tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = "/tmp";
- if (virAsprintf(&ret, "%s/virshXXXXXX.xml", tmpdir) < 0) {
- vshError(ctl, "%s", _("out of memory"));
- return NULL;
- }
+ ret = g_strdup_printf("%s/virshXXXXXX.xml", tmpdir);
fd = mkostemps(ret, 4, O_CLOEXEC);
if (fd == -1) {
vshError(ctl, _("mkostemps: failed to create temporary file: %s"),
rl_completer_quote_characters = quote_characters;
rl_char_is_quoted_p = vshReadlineCharIsQuoted;
- if (virAsprintf(&histsize_env, "%s_HISTSIZE", ctl->env_prefix) < 0)
- goto cleanup;
+ histsize_env = g_strdup_printf("%s_HISTSIZE", ctl->env_prefix);
/* Limit the total size of the history buffer */
if ((histsize_str = getenv(histsize_env))) {
goto cleanup;
}
- if (virAsprintf(&ctl->historydir, "%s/%s", userdir, ctl->name) < 0) {
- vshError(ctl, "%s", _("Out of memory"));
- goto cleanup;
- }
+ ctl->historydir = g_strdup_printf("%s/%s", userdir, ctl->name);
- if (virAsprintf(&ctl->historyfile, "%s/history", ctl->historydir) < 0) {
- vshError(ctl, "%s", _("Out of memory"));
- goto cleanup;
- }
+ ctl->historyfile = g_strdup_printf("%s/history", ctl->historydir);
read_history(ctl->historyfile);
ret = 0;
char *env = NULL;
if (ctl->debug == VSH_DEBUG_DEFAULT) {
- if (virAsprintf(&env, "%s_DEBUG", ctl->env_prefix) < 0)
- return -1;
+ env = g_strdup_printf("%s_DEBUG", ctl->env_prefix);
/* log level not set from commandline, check env variable */
debugEnv = getenv(env);
}
if (ctl->logfile == NULL) {
- if (virAsprintf(&env, "%s_LOG_FILE", ctl->env_prefix) < 0)
- return -1;
+ env = g_strdup_printf("%s_LOG_FILE", ctl->env_prefix);
/* log file not set from cmdline */
debugEnv = getenv(env);