case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (virAsprintf(buf, "%s:%s", type, srcdef->data.file.path) < 0)
- return -1;
+ *buf = g_strdup_printf("%s:%s", type, srcdef->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_DEV:
if (bindService == NULL)
bindService = "0";
- if (virAsprintf(buf, "udp:%s:%s@%s:%s",
- connectHost,
- srcdef->data.udp.connectService,
- bindHost,
- bindService) < 0)
- return -1;
+ *buf = g_strdup_printf("udp:%s:%s@%s:%s", connectHost,
+ srcdef->data.udp.connectService, bindHost, bindService);
break;
}
else
prefix = "tcp";
- if (virAsprintf(buf, "%s:%s:%s%s",
- prefix,
- srcdef->data.tcp.host,
- srcdef->data.tcp.service,
- srcdef->data.tcp.listen ? ",server,nowait" : "") < 0)
- return -1;
+ *buf = g_strdup_printf("%s:%s:%s%s", prefix, srcdef->data.tcp.host,
+ srcdef->data.tcp.service,
+ srcdef->data.tcp.listen ? ",server,nowait" : "");
break;
}
case VIR_DOMAIN_CHR_TYPE_UNIX:
- if (virAsprintf(buf, "unix:%s%s",
- srcdef->data.nix.path,
- srcdef->data.nix.listen ? ",server,nowait" : "") < 0)
- return -1;
+ *buf = g_strdup_printf("unix:%s%s", srcdef->data.nix.path,
+ srcdef->data.nix.listen ? ",server,nowait" : "");
break;
default:
if (channel->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN &&
channel->source->type == VIR_DOMAIN_CHR_TYPE_UNIX &&
!channel->source->data.nix.path) {
- if (virAsprintf(&channel->source->data.nix.path,
- "%s/%s-%s", channelDir, domainName,
- channel->target.name ? channel->target.name
- : "unknown.sock") < 0)
- return -1;
+ const char *target = channel->target.name;
+ if (!target)
+ target = "unknown.sock";
+ channel->source->data.nix.path = g_strdup_printf("%s/%s-%s", channelDir,
+ domainName,
+ target);
channel->source->data.nix.listen = true;
}
char *ret;
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
- ignore_value(virAsprintf(&ret, "%s/%s.save", cfg->saveDir, vm->def->name));
+ ret = g_strdup_printf("%s/%s.save", cfg->saveDir, vm->def->name);
return ret;
}
}
}
- if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) > 0) {
- if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
- VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name);
- VIR_FREE(file);
- }
+ file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name);
+
+ if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
+ VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name);
+ VIR_FREE(file);
/* The "release" hook cleans up additional resources */
if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) {
char timestr[100];
struct tm time_info;
char *dumpfile = NULL;
- int ret = -1;
localtime_r(&curtime, &time_info);
strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
- if (virAsprintf(&dumpfile, "%s/%s-%s",
- cfg->autoDumpDir,
- vm->def->name,
- timestr) < 0)
- goto cleanup;
+ dumpfile = g_strdup_printf("%s/%s-%s", cfg->autoDumpDir, vm->def->name,
+ timestr);
/* Unlock virDomainObj while dumping core */
virObjectUnlock(vm);
libxl_domain_core_dump(cfg->ctx, vm->def->id, dumpfile, NULL);
virObjectLock(vm);
- ret = 0;
-
- cleanup:
VIR_FREE(dumpfile);
-
- return ret;
+ return 0;
}
int
for (i = 0; i < vm->def->nserials; i++) {
chr = vm->def->serials[i];
- ignore_value(virAsprintf(&chr->info.alias, "serial%zd", i));
+ chr->info.alias = g_strdup_printf("serial%zd", i);
if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
if (chr->source->data.file.path)
continue;
if (net->ifname)
continue;
- ignore_value(virAsprintf(&net->ifname,
- LIBXL_GENERATED_PREFIX_XEN "%d.%d%s",
- def->id, x_nic->devid, suffix));
+ net->ifname = g_strdup_printf(LIBXL_GENERATED_PREFIX_XEN "%d.%d%s",
+ def->id, x_nic->devid, suffix);
}
}
if (!(cfg = libxlDriverConfigNew()))
goto error;
- if (virAsprintf(&driverConf, "%s/libxl.conf", cfg->configBaseDir) < 0)
- goto error;
+ driverConf = g_strdup_printf("%s/libxl.conf", cfg->configBaseDir);
if (libxlDriverConfigLoadFile(cfg, driverConf) < 0)
goto error;
}
path = val = NULL;
- if (virAsprintf(&path, "/local/domain/%d/device/vbd/%d/backend",
- domid, devno) < 0)
- goto cleanup;
+ path = g_strdup_printf("/local/domain/%d/device/vbd/%d/backend", domid, devno);
if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
goto cleanup;
VIR_FREE(path);
- if (virAsprintf(&path, "%s/physical-sector-size", val) < 0)
- goto cleanup;
+ path = g_strdup_printf("%s/physical-sector-size", val);
VIR_FREE(val);
if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
stats->backend = g_strdup("vbd");
- if (virAsprintf(&path, "/sys/bus/xen-backend/devices/vbd-%d-%d/statistics",
- vm->def->id, devno) < 0)
- return ret;
+ path = g_strdup_printf("/sys/bus/xen-backend/devices/vbd-%d-%d/statistics",
+ vm->def->id, devno);
if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_FAILED,
}
# define LIBXL_SET_VBDSTAT(FIELD, VAR, MUL) \
- if ((virAsprintf(&name, "%s/"FIELD, path) < 0) || \
- (virFileReadAll(name, 256, &val) < 0) || \
+ name = g_strdup_printf("%s/"FIELD, path); \
+ if ((virFileReadAll(name, 256, &val) < 0) || \
(sscanf(val, "%llu", &status) != 1)) { \
virReportError(VIR_ERR_OPERATION_FAILED, \
_("cannot read %s"), name); \
if ((logger.files = virHashCreate(3, libxlLoggerFileFree)) == NULL)
return NULL;
- if (virAsprintf(&path, "%s/libxl-driver.log", logDir) < 0)
- goto error;
+ path = g_strdup_printf("%s/libxl-driver.log", logDir);
if ((logger.defaultLogFile = fopen(path, "a")) == NULL)
goto error;
char *domidstr = NULL;
char ebuf[1024];
- if (virAsprintf(&path, "%s/%s.log", logger->logDir, name) < 0 ||
- virAsprintf(&domidstr, "%d", id) < 0)
- goto cleanup;
+ path = g_strdup_printf("%s/%s.log", logger->logDir, name);
+ domidstr = g_strdup_printf("%d", id);
if (!(logFile = fopen(path, "a"))) {
VIR_WARN("Failed to open log file %s: %s",
libxlLoggerCloseFile(libxlLoggerPtr logger, int id)
{
char *domidstr = NULL;
- if (virAsprintf(&domidstr, "%d", id) < 0)
- return;
+ domidstr = g_strdup_printf("%d", id);
ignore_value(virHashRemoveEntry(logger->files, domidstr));
goto endjob;
priv->migrationPort = port;
- if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
- goto endjob;
+ *uri_out = g_strdup_printf("tcp://%s:%d", hostname, port);
} else {
if (!(STRPREFIX(uri_in, "tcp://"))) {
/* not full URI, add prefix tcp:// */
char *tmp;
- if (virAsprintf(&tmp, "tcp://%s", uri_in) < 0)
- goto endjob;
+ tmp = g_strdup_printf("tcp://%s", uri_in);
uri = virURIParse(tmp);
VIR_FREE(tmp);
} else {
port = uri->port;
}
- if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
- goto endjob;
+ *uri_out = g_strdup_printf("tcp://%s:%d", hostname, port);
}
snprintf(portstr, sizeof(portstr), "%d", port);
virConfValuePtr val, tmp;
char *buf;
- if (virAsprintf(&buf, "%04x:%02x:%02x.%x",
- def->hostdevs[i]->source.subsys.u.pci.addr.domain,
- def->hostdevs[i]->source.subsys.u.pci.addr.bus,
- def->hostdevs[i]->source.subsys.u.pci.addr.slot,
- def->hostdevs[i]->source.subsys.u.pci.addr.function) < 0)
- goto error;
+ buf = g_strdup_printf("%04x:%02x:%02x.%x",
+ def->hostdevs[i]->source.subsys.u.pci.addr.domain,
+ def->hostdevs[i]->source.subsys.u.pci.addr.bus,
+ def->hostdevs[i]->source.subsys.u.pci.addr.slot,
+ def->hostdevs[i]->source.subsys.u.pci.addr.function);
if (VIR_ALLOC(val) < 0) {
VIR_FREE(buf);
VIR_WARN("ignoring root= and extra= in favour of cmdline=");
} else {
if (root && extra) {
- if (virAsprintf(&cmdline, "root=%s %s", root, extra) < 0)
- return -1;
+ cmdline = g_strdup_printf("root=%s %s", root, extra);
} else if (root) {
- if (virAsprintf(&cmdline, "root=%s", root) < 0)
- return -1;
+ cmdline = g_strdup_printf("root=%s", root);
} else if (extra) {
cmdline = g_strdup(extra);
}
policy = "0";
break;
}
- if (virAsprintf(&cpuid_pairs[j++], "%s=%s",
- feature_name,
- policy) < 0)
- goto cleanup;
+ cpuid_pairs[j++] = g_strdup_printf("%s=%s", feature_name, policy);
}
cpuid_pairs[j] = NULL;
virConfValuePtr val, tmp;
char *buf;
- if (virAsprintf(&buf, "hostbus=%x,hostaddr=%x",
- def->hostdevs[i]->source.subsys.u.usb.bus,
- def->hostdevs[i]->source.subsys.u.usb.device) < 0)
- goto error;
+ buf = g_strdup_printf("hostbus=%x,hostaddr=%x",
+ def->hostdevs[i]->source.subsys.u.usb.bus,
+ def->hostdevs[i]->source.subsys.u.usb.device);
if (VIR_ALLOC(val) < 0) {
VIR_FREE(buf);
return -1;
if (root && extra) {
- if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
- return -1;
+ def->os.cmdline = g_strdup_printf("root=%s %s", root, extra);
} else if (root) {
- if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
- return -1;
+ def->os.cmdline = g_strdup_printf("root=%s", root);
} else if (extra) {
def->os.cmdline = g_strdup(extra);
}