return audit_encode_nv_string(key, value, 0);
#else
char *str;
- if (virAsprintf(&str, "%s=%s", key, value) < 0)
- return NULL;
+ str = g_strdup_printf("%s=%s", key, value);
return str;
#endif
}
if (!(userdir = virGetUserConfigDirectory()))
return -1;
- if (virAsprintf(path, "%s/auth.conf", userdir) < 0)
- return -1;
+ *path = g_strdup_printf("%s/auth.conf", userdir);
VIR_DEBUG("Checking for readability of '%s'", *path);
if (access(*path, R_OK) == 0)
memset(&cred, 0, sizeof(virConnectCredential));
if (defaultUsername != NULL) {
- if (virAsprintf(&prompt, _("Enter username for %s [%s]"), hostname,
- defaultUsername) < 0) {
- return NULL;
- }
+ prompt = g_strdup_printf(_("Enter username for %s [%s]"), hostname,
+ defaultUsername);
} else {
- if (virAsprintf(&prompt, _("Enter username for %s"), hostname) < 0)
- return NULL;
+ prompt = g_strdup_printf(_("Enter username for %s"), hostname);
}
for (ncred = 0; ncred < auth->ncredtype; ncred++) {
memset(&cred, 0, sizeof(virConnectCredential));
- if (virAsprintf(&prompt, _("Enter %s's password for %s"), username,
- hostname) < 0) {
- return NULL;
- }
+ prompt = g_strdup_printf(_("Enter %s's password for %s"), username, hostname);
for (ncred = 0; ncred < auth->ncredtype; ncred++) {
if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE &&
if (!hostname)
hostname = "localhost";
- if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0)
- return -1;
+ authgroup = g_strdup_printf("auth-%s-%s", service, hostname);
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
VIR_FREE(authgroup);
- if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0)
- return -1;
+ authgroup = g_strdup_printf("auth-%s-%s", service, "default");
}
if (!virKeyFileHasGroup(auth->keyfile, authgroup))
return -1;
}
- if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0)
- return -1;
+ credgroup = g_strdup_printf("credentials-%s", authcred);
if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
virReportError(VIR_ERR_CONF_SYNTAX,
if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0)
return rc;
- if (virAsprintf(&newstr, "_%s", *path) < 0)
- return -1;
+ newstr = g_strdup_printf("_%s", *path);
VIR_FREE(*path);
*path = newstr;
if (pid == -1) {
procfile = g_strdup("/proc/self/cgroup");
} else {
- if (virAsprintf(&procfile, "/proc/%lld/cgroup",
- (long long) pid) < 0)
- goto cleanup;
+ procfile = g_strdup_printf("/proc/%lld/cgroup", (long long)pid);
}
mapping = fopen(procfile, "r");
/* Automatically append space after the string since all callers
* use it anyway */
- if (virAsprintf(&ret, "%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)) < 0)
- return NULL;
+ ret = g_strdup_printf("%d:%d ", major(sb.st_rdev), minor(sb.st_rdev));
return ret;
}
{
g_autofree char *strval = NULL;
- if (virAsprintf(&strval, "%llu", value) < 0)
- return -1;
+ strval = g_strdup_printf("%llu", value);
return virCgroupSetValueStr(group, controller, key, strval);
}
{
g_autofree char *strval = NULL;
- if (virAsprintf(&strval, "%lld", value) < 0)
- return -1;
+ strval = g_strdup_printf("%lld", value);
return virCgroupSetValueStr(group, controller, key, strval);
}
if (path[0] == '/' || !parent) {
(*group)->path = g_strdup(path);
} else {
- if (virAsprintf(&(*group)->path, "%s%s%s",
- parent->path,
- STREQ(parent->path, "") ? "" : "/",
- path) < 0)
- goto error;
+ (*group)->path = g_strdup_printf("%s%s%s", parent->path,
+ STREQ(parent->path, "") ? "" : "/", path);
}
if (virCgroupDetect(*group, pid, controllers, path, parent) < 0)
{
g_autofree char *grpname = NULL;
- if (virAsprintf(&grpname, "%s.libvirt-%s",
- name, driver) < 0)
- return -1;
+ grpname = g_strdup_printf("%s.libvirt-%s", name, driver);
if (virCgroupPartitionEscape(&grpname) < 0)
return -1;
switch (nameval) {
case VIR_CGROUP_THREAD_VCPU:
- if (virAsprintf(&name, "vcpu%d", id) < 0)
- return -1;
+ name = g_strdup_printf("vcpu%d", id);
break;
case VIR_CGROUP_THREAD_EMULATOR:
name = g_strdup("emulator");
break;
case VIR_CGROUP_THREAD_IOTHREAD:
- if (virAsprintf(&name, "iothread%d", id) < 0)
- return -1;
+ name = g_strdup_printf("iothread%d", id);
break;
case VIR_CGROUP_THREAD_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR,
if (ent->d_type != DT_DIR) continue;
- if (virAsprintf(&path, "%s/%s", grppath, ent->d_name) == -1) {
- rc = -ENOMEM;
- break;
- }
+ path = g_strdup_printf("%s/%s", grppath, ent->d_name);
+
rc = virCgroupRemoveRecursively(path);
if (rc != 0)
break;
g_autofree char *scopename_new = NULL;
g_autofree char *partmachinename = NULL;
- if (virAsprintf(&partname, "%s.libvirt-%s",
- name, drivername) < 0)
- return false;
+ partname = g_strdup_printf("%s.libvirt-%s", name, drivername);
if (virCgroupPartitionEscape(&partname) < 0)
return false;
- if (virAsprintf(&partmachinename, "%s.libvirt-%s",
- machinename, drivername) < 0 ||
- virCgroupPartitionEscape(&partmachinename) < 0)
+ partmachinename = g_strdup_printf("%s.libvirt-%s",
+ machinename, drivername);
+
+ if (virCgroupPartitionEscape(&partmachinename) < 0)
return false;
if (!(scopename_old = virSystemdMakeScopeName(name, drivername, true)))
if (path[0] == '/') {
group->legacy[i].placement = g_strdup(path);
} else {
+ bool delim = STREQ(parent->legacy[i].placement, "/") || STREQ(path, "");
/*
* parent == "/" + path="" => "/"
* parent == "/libvirt.service" + path == "" => "/libvirt.service"
* parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
*/
- if (virAsprintf(&group->legacy[i].placement,
- "%s%s%s",
- parent->legacy[i].placement,
- (STREQ(parent->legacy[i].placement, "/") ||
- STREQ(path, "") ? "" : "/"),
- path) < 0)
- return -1;
+ group->legacy[i].placement = g_strdup_printf("%s%s%s",
+ parent->legacy[i].placement,
+ delim ? "" : "/",
+ path);
}
}
return 0;
*dirName = '\0';
- if (virAsprintf(&linkSrc, "%s/%s", tmp, typeStr) < 0)
- return -1;
+ linkSrc = g_strdup_printf("%s/%s", tmp, typeStr);
*dirName = '/';
if (lstat(linkSrc, &sb) < 0) {
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
group->legacy[i].placement = g_strdup(selfpath);
} else {
- if (virAsprintf(&group->legacy[i].placement,
- "%s%s%s", selfpath,
- (STREQ(selfpath, "/") ||
- STREQ(path, "") ? "" : "/"),
- path) < 0)
- return -1;
+ bool delim = STREQ(selfpath, "/") || STREQ(path, "");
+
+ group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath,
+ delim ? "" : "/",
+ path);
}
}
}
return -1;
}
- if (virAsprintf(path, "%s%s/%s",
- group->legacy[controller].mountPoint,
- group->legacy[controller].placement,
- NULLSTR_EMPTY(key)) < 0)
- return -1;
+ *path = g_strdup_printf("%s%s/%s", group->legacy[controller].mountPoint,
+ group->legacy[controller].placement, NULLSTR_EMPTY(key));
return 0;
}
return -1;
}
- if (virAsprintf(&opts,
- "mode=755,size=65536%s", mountopts) < 0)
- return -1;
+ opts = g_strdup_printf("mode=755,size=65536%s", mountopts);
if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
virReportSystemError(errno,
if (!virFileExists(group->legacy[i].mountPoint)) {
g_autofree char *src = NULL;
- if (virAsprintf(&src, "%s%s",
- oldroot,
- group->legacy[i].mountPoint) < 0)
- return -1;
+ src = g_strdup_printf("%s%s", oldroot, group->legacy[i].mountPoint);
VIR_DEBUG("Create mount point '%s'",
group->legacy[i].mountPoint);
if (!cgroup->legacy[i].mountPoint)
continue;
- if (virAsprintf(&base, "%s%s", cgroup->legacy[i].mountPoint,
- cgroup->legacy[i].placement) < 0)
- goto cleanup;
+ base = g_strdup_printf("%s%s", cgroup->legacy[i].mountPoint,
+ cgroup->legacy[i].placement);
if (virDirOpen(&dh, base) < 0)
goto cleanup;
while ((direrr = virDirRead(dh, &de, base)) > 0) {
g_autofree char *entry = NULL;
- if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)
- goto cleanup;
+ entry = g_strdup_printf("%s/%s", base, de->d_name);
if (chown(entry, uid, gid) < 0) {
virReportSystemError(errno,
return -1;
}
- if (virAsprintf(&value, "%u", weight) < 0)
- return -1;
+ value = g_strdup_printf("%u", weight);
return virCgroupSetValueRaw(path, value);
}
if (!(blkstr = virCgroupGetBlockDevString(devPath)))
return -1;
- if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
- return -1;
+ str = g_strdup_printf("%s%d", blkstr, weight);
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight_device", &path) < 0) {
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
- return -1;
+ str = g_strdup_printf("%s%u", blkstr, riops);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0)
- return -1;
+ str = g_strdup_printf("%s%u", blkstr, wiops);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0)
- return -1;
+ str = g_strdup_printf("%s%llu", blkstr, rbps);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0)
- return -1;
+ str = g_strdup_printf("%s%llu", blkstr, wbps);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
if (major < 0)
majorstr = g_strdup("*");
- if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
- return -1;
+ else
+ majorstr = g_strdup_printf("%i", major);
if (minor < 0)
minorstr = g_strdup("*");
- if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
- return -1;
+ else
+ minorstr = g_strdup_printf("%i", minor);
- if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
- virCgroupGetDevicePermsString(perms)) < 0)
- return -1;
+ devstr = g_strdup_printf("%c %s:%s %s", type, majorstr, minorstr,
+ virCgroupGetDevicePermsString(perms));
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
if (major < 0)
majorstr = g_strdup("*");
- if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
- return -1;
+ else
+ majorstr = g_strdup_printf("%i", major);
if (minor < 0)
minorstr = g_strdup("*");
- if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
- return -1;
+ else
+ minorstr = g_strdup_printf("%i", minor);
- if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
- virCgroupGetDevicePermsString(perms)) < 0)
- return -1;
+ devstr = g_strdup_printf("%c %s:%s %s", type, majorstr, minorstr,
+ virCgroupGetDevicePermsString(perms));
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
/* Systemd uses cgroup v2 for process tracking but no controller is
* available. We should consider this configuration as cgroup v2 is
* not available. */
- if (virAsprintf(&contFile, "%s/cgroup.controllers", entry.mnt_dir) < 0)
- goto cleanup;
+ contFile = g_strdup_printf("%s/cgroup.controllers", entry.mnt_dir);
if (virFileReadAll(contFile, 1024 * 1024, &contStr) < 0)
goto cleanup;
g_autofree char *scopename = NULL;
char *tmp;
- if (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename,
- drivername) < 0) {
- return false;
- }
+ partmachinename = g_strdup_printf("%s.libvirt-%s", machinename, drivername);
if (virCgroupPartitionEscape(&partmachinename) < 0)
return false;
if (path[0] == '/') {
group->unified.placement = g_strdup(path);
} else {
+ bool delim = STREQ(parent->unified.placement, "/") || STREQ(path, "");
/*
* parent == "/" + path="" => "/"
* parent == "/libvirt.service" + path == "" => "/libvirt.service"
* parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
*/
- if (virAsprintf(&group->unified.placement, "%s%s%s",
- parent->unified.placement,
- (STREQ(parent->unified.placement, "/") ||
- STREQ(path, "") ? "" : "/"),
- path) < 0)
- return -1;
+ group->unified.placement = g_strdup_printf("%s%s%s",
+ parent->unified.placement,
+ delim ? "" : "/",
+ path);
}
return 0;
* selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
* selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
*/
- if (virAsprintf(&group->unified.placement,
- "%s%s%s", selfpath,
- (STREQ(selfpath, "/") ||
- STREQ(path, "") ? "" : "/"),
- path) < 0)
- return -1;
+ group->unified.placement = g_strdup_printf("%s%s%s", selfpath,
+ (STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), path);
return 0;
}
char **tmp;
if (parent) {
- if (virAsprintf(&contFile, "%s%s/cgroup.subtree_control",
- parent->unified.mountPoint,
- NULLSTR_EMPTY(parent->unified.placement)) < 0)
- return -1;
+ contFile = g_strdup_printf("%s%s/cgroup.subtree_control",
+ parent->unified.mountPoint,
+ NULLSTR_EMPTY(parent->unified.placement));
} else {
- if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
- group->unified.mountPoint,
- NULLSTR_EMPTY(group->unified.placement)) < 0)
- return -1;
+ contFile = g_strdup_printf("%s%s/cgroup.controllers",
+ group->unified.mountPoint,
+ NULLSTR_EMPTY(group->unified.placement));
}
rc = virFileReadAll(contFile, 1024 * 1024, &contStr);
return -1;
}
- if (virAsprintf(path, "%s%s/%s",
- group->unified.mountPoint,
- group->unified.placement,
- NULLSTR_EMPTY(key)) < 0)
- return -1;
+ *path = g_strdup_printf("%s%s/%s", group->unified.mountPoint,
+ group->unified.placement, NULLSTR_EMPTY(key));
return 0;
}
g_autofree char *val = NULL;
g_autofree char *path = NULL;
- if (virAsprintf(&val, "+%s",
- virCgroupV2ControllerTypeToString(controller)) < 0) {
- return -1;
- }
+ val = g_strdup_printf("+%s", virCgroupV2ControllerTypeToString(controller));
if (virCgroupPathOfController(parent, controller,
"cgroup.subtree_control", &path) < 0) {
return -1;
}
- if (virAsprintf(&opts, "mode=755,size=65536%s", mountopts) < 0)
- return -1;
+ opts = g_strdup_printf("mode=755,size=65536%s", mountopts);
- if (virAsprintf(&src, "%s%s", oldroot, group->unified.mountPoint) < 0)
- return -1;
+ src = g_strdup_printf("%s%s", oldroot, group->unified.mountPoint);
if (mount(src, group->unified.mountPoint, "none", MS_BIND, NULL) < 0) {
virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'"),
{
g_autofree char *base = NULL;
- if (virAsprintf(&base, "%s%s", cgroup->unified.mountPoint,
- cgroup->unified.placement) < 0) {
- return -1;
- }
+ base = g_strdup_printf("%s%s", cgroup->unified.mountPoint,
+ cgroup->unified.placement);
if (virFileChownFiles(base, uid, gid) < 0)
return -1;
return -1;
}
- if (virAsprintf(&value, format, weight) < 0)
- return -1;
+ value = g_strdup_printf(format, weight);
return virCgroupSetValueRaw(path, value);
}
if (!(blkstr = virCgroupGetBlockDevString(devPath)))
return -1;
- if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
- return -1;
+ str = g_strdup_printf("%s%d", blkstr, weight);
if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight", &path) < 0) {
return -1;
if (riops == 0) {
- if (virAsprintf(&str, "%sriops=max", blkstr) < 0)
- return -1;
+ str = g_strdup_printf("%sriops=max", blkstr);
} else {
- if (virAsprintf(&str, "%sriops=%u", blkstr, riops) < 0)
- return -1;
+ str = g_strdup_printf("%sriops=%u", blkstr, riops);
}
return virCgroupSetValueStr(group,
return -1;
if (wiops == 0) {
- if (virAsprintf(&str, "%swiops=max", blkstr) < 0)
- return -1;
+ str = g_strdup_printf("%swiops=max", blkstr);
} else {
- if (virAsprintf(&str, "%swiops=%u", blkstr, wiops) < 0)
- return -1;
+ str = g_strdup_printf("%swiops=%u", blkstr, wiops);
}
return virCgroupSetValueStr(group,
return -1;
if (rbps == 0) {
- if (virAsprintf(&str, "%srbps=max", blkstr) < 0)
- return -1;
+ str = g_strdup_printf("%srbps=max", blkstr);
} else {
- if (virAsprintf(&str, "%srbps=%llu", blkstr, rbps) < 0)
- return -1;
+ str = g_strdup_printf("%srbps=%llu", blkstr, rbps);
}
return virCgroupSetValueStr(group,
return -1;
if (wbps == 0) {
- if (virAsprintf(&str, "%swbps=max", blkstr) < 0)
- return -1;
+ str = g_strdup_printf("%swbps=max", blkstr);
} else {
- if (virAsprintf(&str, "%swbps=%llu", blkstr, wbps) < 0)
- return -1;
+ str = g_strdup_printf("%swbps=%llu", blkstr, wbps);
}
return virCgroupSetValueStr(group,
}
*tmp = '\0';
- if (virAsprintf(&value, "%s %llu", str, cfs_period) < 0)
- return -1;
+ value = g_strdup_printf("%s %llu", str, cfs_period);
return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPU,
"cpu.max", value);
{
char *path;
if (geteuid() == 0) {
- if (virAsprintf(&path, "%s/libvirt/%s",
- SYSCONFDIR, name) < 0)
- return NULL;
+ path = g_strdup_printf("%s/libvirt/%s", SYSCONFDIR, name);
} else {
char *userdir = virGetUserConfigDirectory();
if (!userdir)
return NULL;
- if (virAsprintf(&path, "%s/%s",
- userdir, name) < 0) {
- VIR_FREE(userdir);
- return NULL;
- }
+ path = g_strdup_printf("%s/%s", userdir, name);
VIR_FREE(userdir);
}
goto cleanup;
for (i = 0; i < deps->count; i++) {
- if (virAsprintfQuiet(&devPaths[i], "/dev/block/%u:%u",
- major(deps->device[i]),
- minor(deps->device[i])) < 0)
- goto cleanup;
+ devPaths[i] = g_strdup_printf("/dev/block/%u:%u",
+ major(deps->device[i]),
+ minor(deps->device[i]));
}
recursiveDevPaths = NULL;
* for runtime addition.
*/
- if (virAsprintf(&tmp, "%s.new", path) < 0)
- return -ENOMEM;
+ tmp = g_strdup_printf("%s.new", path);
if (!(f = fopen(tmp, "w"))) {
istmp = false;
/* the first test determines if it is a dhcpv6 host */
if (ipv6) {
if (name && id) {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
- "id:%s,%s,[%s]", id, name, ipstr) < 0)
- goto error;
+ hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("id:%s,%s,[%s]",
+ id, name, ipstr);
} else if (name && !id) {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
- "%s,[%s]", name, ipstr) < 0)
- goto error;
+ hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,[%s]",
+ name, ipstr);
} else if (!name && id) {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
- "id:%s,[%s]", id, ipstr) < 0)
- goto error;
+ hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("id:%s,[%s]",
+ id, ipstr);
}
} else if (name && mac) {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,%s",
- mac, ipstr, name) < 0)
- goto error;
+ hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s,%s",
+ mac, ipstr, name);
} else if (name && !mac) {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s",
- name, ipstr) < 0)
- goto error;
+ hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s", name,
+ ipstr);
} else {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s",
- mac, ipstr) < 0)
- goto error;
+ hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s", mac,
+ ipstr);
}
VIR_FREE(ipstr);
* for runtime addition.
*/
- if (virAsprintf(&tmp, "%s.new", path) < 0)
- return -ENOMEM;
+ tmp = g_strdup_printf("%s.new", path);
if (!(f = fopen(tmp, "w"))) {
istmp = false;
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
- if (virAsprintf(&complete, "%s\n%s", version, help) < 0)
- goto cleanup;
+ complete = g_strdup_printf("%s\n%s", version, help);
ret = dnsmasqCapsSetFromBuffer(caps, complete);
if (VIR_ALLOC(ctx) < 0)
return NULL;
- if (virAsprintf(&ctx->chain, "libvirt_%s_FORWARD", driver) < 0) {
- VIR_FREE(ctx);
- return NULL;
- }
+ ctx->chain = g_strdup_printf("libvirt_%s_FORWARD", driver);
return ctx;
}
if (virVasprintfQuiet(&fmtmsg, fmt, args) < 0)
goto cleanup;
- if (virAsprintfQuiet(&newmsg, "%s: %s", fmtmsg, err->message) < 0)
- goto cleanup;
+ newmsg = g_strdup_printf("%s: %s", fmtmsg, err->message);
VIR_FREE(err->message);
err->message = g_steal_pointer(&newmsg);
int fd = -1;
int ret = -1;
- if (virAsprintf(&newfile, "%s.new", path) < 0)
- goto cleanup;
+ newfile = g_strdup_printf("%s.new", path);
if ((fd = open(newfile, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) {
virReportSystemError(errno, _("cannot create file '%s'"),
VIR_DEBUG("Found free loop device number %i", devnr);
- if (virAsprintf(&looppath, "/dev/loop%i", devnr) < 0)
- return -1;
+ looppath = g_strdup_printf("/dev/loop%i", devnr);
if ((*fd = open(looppath, O_RDWR)) < 0) {
virReportSystemError(errno,
!c_isdigit(de->d_name[4]))
continue;
- if (virAsprintf(&looppath, "/dev/%s", de->d_name) < 0)
- goto cleanup;
+ looppath = g_strdup_printf("/dev/%s", de->d_name);
VIR_DEBUG("Checking up on device %s", looppath);
if ((fd = open(looppath, O_RDWR)) < 0) {
{
g_autofree char *path = NULL;
- if (virAsprintf(&path, SYSFS_BLOCK_DIR "/%s/pid",
- dev_name) < 0)
- return -1;
+ path = g_strdup_printf(SYSFS_BLOCK_DIR "/%s/pid", dev_name);
if (!virFileExists(path)) {
if (errno == ENOENT)
if (rv < 0)
goto cleanup;
if (rv == 0) {
- ignore_value(virAsprintf(&ret, "/dev/%s", de->d_name));
+ ret = g_strdup_printf("/dev/%s", de->d_name);
goto cleanup;
}
}
g_autofree char *filepath = NULL;
struct stat sb;
- if (virAsprintf(&filepath, "%s/%s",
- dir, de->d_name) < 0)
- goto cleanup;
+ filepath = g_strdup_printf("%s/%s", dir, de->d_name);
if (lstat(filepath, &sb) < 0) {
virReportSystemError(errno, _("Cannot access '%s'"),
checkLink);
return -1;
}
- if (virAsprintf(&candidate, "%s/%s", directory, checkLink) < 0)
- return -1;
+ candidate = g_strdup_printf("%s/%s", directory, checkLink);
return virFileLinkPointsTo(candidate, checkDest);
}
*/
pathiter = path;
while ((pathseg = strsep(&pathiter, ":")) != NULL) {
- if (virAsprintf(&fullpath, "%s/%s", pathseg, file) < 0 ||
- virFileIsExecutable(fullpath))
+ fullpath = g_strdup_printf("%s/%s", pathseg, file);
+ if (virFileIsExecutable(fullpath))
break;
VIR_FREE(fullpath);
}
else
path = installdir;
- if (virAsprintf(&ret, "%s/%s%s%s", path, prefix, filename, suffix) < 0)
- return NULL;
+ ret = g_strdup_printf("%s/%s%s%s", path, prefix, filename, suffix);
VIR_DEBUG("Resolved '%s' to '%s'", filename, ret);
return ret;
while ((direrr = virDirRead(dir, &ent, name)) > 0) {
g_autofree char *path = NULL;
- if (virAsprintf(&path, "%s/%s", name, ent->d_name) < 0)
- goto cleanup;
+ path = g_strdup_printf("%s/%s", name, ent->d_name);
if (!virFileIsRegular(path))
continue;
char *path;
if (ext == NULL) {
- ignore_value(virAsprintf(&path, "%s/%s", dir, name));
+ path = g_strdup_printf("%s/%s", dir, name);
} else {
- ignore_value(virAsprintf(&path, "%s/%s%s", dir, name, ext));
+ path = g_strdup_printf("%s/%s%s", dir, name, ext);
}
return path;
if (buf == NULL)
return -1;
- if (virAsprintf(abspath, "%s/%s", buf, path) < 0)
- return -1;
+ *abspath = g_strdup_printf("%s/%s", buf, path);
}
return 0;
/* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
* core, node, socket, thread and topology information from /sys
*/
- if (virAsprintf(&sysfs_nodedir, "%s/node", SYSFS_SYSTEM_PATH) < 0)
- goto cleanup;
+ sysfs_nodedir = g_strdup_printf("%s/node", SYSFS_SYSTEM_PATH);
if (virDirOpenQuiet(&nodedir, sysfs_nodedir) < 0) {
/* the host isn't probably running a NUMA architecture */
(*nodes)++;
- if (virAsprintf(&sysfs_cpudir, "%s/node/%s", SYSFS_SYSTEM_PATH,
- nodedirent->d_name) < 0)
- goto cleanup;
+ sysfs_cpudir = g_strdup_printf("%s/node/%s", SYSFS_SYSTEM_PATH,
+ nodedirent->d_name);
if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch,
present_cpus_map,
fallback:
VIR_FREE(sysfs_cpudir);
- if (virAsprintf(&sysfs_cpudir, "%s/cpu", SYSFS_SYSTEM_PATH) < 0)
- goto cleanup;
+ sysfs_cpudir = g_strdup_printf("%s/cpu", SYSFS_SYSTEM_PATH);
if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch,
present_cpus_map,
if (!(rundir = virGetUserRuntimeDirectory()))
return NULL;
- if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < 0)
- return NULL;
+ hostdevMgr->stateDir = g_strdup_printf("%s/hostdevmgr", rundir);
old_umask = umask(077);
return -1;
}
- if (virAsprintf(&meminfo_path,
- SYSFS_SYSTEM_PATH "/node/node%d/meminfo",
- cellNum) < 0)
- return -1;
+ meminfo_path = g_strdup_printf(
+ SYSFS_SYSTEM_PATH "/node/node%d/meminfo", cellNum);
}
meminfo = fopen(meminfo_path, "r");
char *field = strchr(param->field, '_');
sa_assert(field);
field++;
- if (virAsprintf(&path, "%s/%s",
- SYSFS_MEMORY_SHARED_PATH, field) < 0)
- return -2;
+ path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
- if (virAsprintf(&strval, "%u", param->value.ui) == -1)
- return -2;
+ strval = g_strdup_printf("%u", param->value.ui);
if ((rc = virFileWriteStr(path, strval, 0)) < 0) {
virReportSystemError(-rc, _("failed to set %s"), param->field);
char *field = strchr(param->field, '_');
sa_assert(field);
field++;
- if (virAsprintf(&path, "%s/%s",
- SYSFS_MEMORY_SHARED_PATH, field) < 0)
- return false;
+ path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_INVALID,
char *tmp = NULL;
int rc = -1;
- if (virAsprintf(&path, "%s/%s",
- SYSFS_MEMORY_SHARED_PATH, field) < 0)
- return -1;
+ path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
if (!virFileExists(path))
return -2;
if (!netstr)
return NULL;
- ignore_value(virAsprintf(&ret, "%s/%d", netstr, prefix));
+ ret = g_strdup_printf("%s/%d", netstr, prefix);
return ret;
}
}
if (port->start < port->end && port->end < 65536) {
- if (virAsprintf(&portRangeStr, ":%u-%u",
- port->start, port->end) < 0)
- return -1;
+ portRangeStr = g_strdup_printf(":%u-%u", port->start, port->end);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid port range '%u-%u'."),
port->start, port->end);
+ return -1;
}
}
/* Use --jump SNAT if public addr is specified */
if (addrStartStr && addrStartStr[0]) {
- int r = 0;
-
if (addrEndStr && addrEndStr[0]) {
- r = virAsprintf(&natRangeStr, "%s-%s%s", addrStartStr, addrEndStr,
- portRangeStr ? portRangeStr : "");
+ natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr,
+ portRangeStr ? portRangeStr : "");
} else {
- r = virAsprintf(&natRangeStr, "%s%s", addrStartStr,
- portRangeStr ? portRangeStr : "");
+ natRangeStr = g_strdup_printf("%s%s", addrStartStr,
+ portRangeStr ? portRangeStr : "");
}
- if (r < 0)
- return -1;
-
virFirewallRuleAddArgList(fw, rule,
"--jump", "SNAT",
"--to-source", natRangeStr, NULL);
g_autofree char *temp_ifacename = NULL;
g_autoptr(virCommand) cmd = NULL;
- if (virAsprintf(&temp_ifacename,
- "libvirt-iface-%08llx",
- (unsigned long long)virRandomBits(32)) < 0)
- return -1;
+ temp_ifacename = g_strdup_printf("libvirt-iface-%08llx",
+ (unsigned long long)virRandomBits(32));
VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'",
temp_ifacename, initiatoriqn);
virJSONValueNewNumberInt(int data)
{
g_autofree char *str = NULL;
- if (virAsprintf(&str, "%i", data) < 0)
- return NULL;
+ str = g_strdup_printf("%i", data);
return virJSONValueNewNumber(str);
}
virJSONValueNewNumberUint(unsigned int data)
{
g_autofree char *str = NULL;
- if (virAsprintf(&str, "%u", data) < 0)
- return NULL;
+ str = g_strdup_printf("%u", data);
return virJSONValueNewNumber(str);
}
virJSONValueNewNumberLong(long long data)
{
g_autofree char *str = NULL;
- if (virAsprintf(&str, "%lld", data) < 0)
- return NULL;
+ str = g_strdup_printf("%lld", data);
return virJSONValueNewNumber(str);
}
virJSONValueNewNumberUlong(unsigned long long data)
{
g_autofree char *str = NULL;
- if (virAsprintf(&str, "%llu", data) < 0)
- return NULL;
+ str = g_strdup_printf("%llu", data);
return virJSONValueNewNumber(str);
}
g_autofree char *drvblklst = NULL;
g_autofree char *outbuf = NULL;
- if (virAsprintfQuiet(&drvblklst, "blacklist %s\n", module) < 0)
- return false;
+ drvblklst = g_strdup_printf("blacklist %s\n", module);
/* modprobe will convert all '-' into '_', so we need to as well */
for (i = 0; i < drvblklst[i]; i++)
{
char *ret;
if (lockspace->dir)
- ignore_value(virAsprintf(&ret, "%s/%s", lockspace->dir, resname));
+ ret = g_strdup_printf("%s/%s", lockspace->dir, resname);
else
ret = g_strdup(resname);
return ret;
}
-static int
+static void
virLogSetDefaultOutputToStderr(void)
{
- return virAsprintf(&virLogDefaultOutput, "%d:stderr",
- virLogDefaultPriority);
+ virLogDefaultOutput = g_strdup_printf("%d:stderr",
+ virLogDefaultPriority);
}
-static int
+static void
virLogSetDefaultOutputToJournald(void)
{
virLogPriority priority = virLogDefaultPriority;
if (priority == VIR_LOG_DEBUG)
priority = VIR_LOG_INFO;
- return virAsprintf(&virLogDefaultOutput, "%d:journald", priority);
+ virLogDefaultOutput = g_strdup_printf("%d:journald", priority);
}
mode_t old_umask;
if (privileged) {
- if (virAsprintf(&virLogDefaultOutput,
- "%d:file:%s/log/libvirt/%s.log", virLogDefaultPriority,
- LOCALSTATEDIR, binary) < 0)
- goto cleanup;
+ virLogDefaultOutput = g_strdup_printf("%d:file:%s/log/libvirt/%s.log",
+ virLogDefaultPriority, LOCALSTATEDIR, binary);
} else {
if (!(logdir = virGetUserCacheDirectory()))
goto cleanup;
}
umask(old_umask);
- if (virAsprintf(&virLogDefaultOutput, "%d:file:%s/%s.log",
- virLogDefaultPriority, logdir, binary) < 0)
- goto cleanup;
+ virLogDefaultOutput = g_strdup_printf("%d:file:%s/%s.log",
+ virLogDefaultPriority, logdir, binary);
}
ret = 0;
* Decides on what the default output (journald, file, stderr) should be
* according to @binary, @godaemon, @privileged. This function should be run
* exactly once at daemon startup, so no locks are used.
- *
- * Returns 0 on success, -1 in case of a failure.
*/
-int
+void
virLogSetDefaultOutput(const char *binary, bool godaemon, bool privileged)
{
bool have_journald = access("/run/systemd/journal/socket", W_OK) >= 0;
if (godaemon) {
if (have_journald)
- return virLogSetDefaultOutputToJournald();
+ virLogSetDefaultOutputToJournald();
+ else
+ virLogSetDefaultOutputToFile(binary, privileged);
} else {
if (!isatty(STDIN_FILENO) && have_journald)
- return virLogSetDefaultOutputToJournald();
-
- return virLogSetDefaultOutputToStderr();
+ virLogSetDefaultOutputToJournald();
+ else
+ virLogSetDefaultOutputToStderr();
}
-
- return virLogSetDefaultOutputToFile(binary, privileged);
}
}
-static int
+static void
virLogFormatString(char **msg,
int linenr,
const char *funcname,
virLogPriority priority,
const char *str)
{
- int ret;
-
/*
* Be careful when changing the following log message formatting, we rely
* on it when stripping libvirt debug messages from qemu log files. So when
* to just grep for it to find the right place.
*/
if ((funcname != NULL)) {
- ret = virAsprintfQuiet(msg, "%llu: %s : %s:%d : %s\n",
+ *msg = g_strdup_printf("%llu: %s : %s:%d : %s\n",
virThreadSelfID(), virLogPriorityString(priority),
funcname, linenr, str);
} else {
- ret = virAsprintfQuiet(msg, "%llu: %s : %s\n",
+ *msg = g_strdup_printf("%llu: %s : %s\n",
virThreadSelfID(), virLogPriorityString(priority),
str);
}
- return ret;
}
-static int
+static void
virLogVersionString(const char **rawmsg,
char **msg)
{
*rawmsg = VIR_LOG_VERSION_STRING;
- return virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
+ virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
}
/* Similar to virGetHostname() but avoids use of error
* reporting APIs or logging APIs, to prevent recursion
*/
-static int
+static void
virLogHostnameString(char **rawmsg,
char **msg)
{
char *hoststr;
- if (virAsprintfQuiet(&hoststr, "hostname: %s", virLogHostname) < 0)
- return -1;
+ hoststr = g_strdup_printf("hostname: %s", virLogHostname);
- if (virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr) < 0) {
- VIR_FREE(hoststr);
- return -1;
- }
+ virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr);
*rawmsg = hoststr;
- return 0;
}
char *str = NULL;
char *msg = NULL;
char timestamp[VIR_TIME_STRING_BUFLEN];
- int ret;
size_t i;
int saved_errno = errno;
if (virVasprintfQuiet(&str, fmt, vargs) < 0)
goto cleanup;
- ret = virLogFormatString(&msg, linenr, funcname, priority, str);
- if (ret < 0)
- goto cleanup;
+ virLogFormatString(&msg, linenr, funcname, priority, str);
if (virTimeStringNowRaw(timestamp) < 0)
timestamp[0] = '\0';
const char *rawinitmsg;
char *hoststr = NULL;
char *initmsg = NULL;
- if (virLogVersionString(&rawinitmsg, &initmsg) >= 0)
- virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
- __FILE__, __LINE__, __func__,
- timestamp, NULL, rawinitmsg, initmsg,
- virLogOutputs[i]->data);
+ virLogVersionString(&rawinitmsg, &initmsg);
+ virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
+ __FILE__, __LINE__, __func__,
+ timestamp, NULL, rawinitmsg, initmsg,
+ virLogOutputs[i]->data);
VIR_FREE(initmsg);
- if (virLogHostnameString(&hoststr, &initmsg) >= 0)
- virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
- __FILE__, __LINE__, __func__,
- timestamp, NULL, hoststr, initmsg,
- virLogOutputs[i]->data);
+
+ virLogHostnameString(&hoststr, &initmsg);
+ virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
+ __FILE__, __LINE__, __func__,
+ timestamp, NULL, hoststr, initmsg,
+ virLogOutputs[i]->data);
VIR_FREE(hoststr);
VIR_FREE(initmsg);
virLogOutputs[i]->logInitMessage = false;
const char *rawinitmsg;
char *hoststr = NULL;
char *initmsg = NULL;
- if (virLogVersionString(&rawinitmsg, &initmsg) >= 0)
- virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
- __FILE__, __LINE__, __func__,
- timestamp, NULL, rawinitmsg, initmsg,
- (void *) STDERR_FILENO);
+ virLogVersionString(&rawinitmsg, &initmsg);
+ virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
+ __FILE__, __LINE__, __func__,
+ timestamp, NULL, rawinitmsg, initmsg,
+ (void *) STDERR_FILENO);
VIR_FREE(initmsg);
- if (virLogHostnameString(&hoststr, &initmsg) >= 0)
- virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
- __FILE__, __LINE__, __func__,
- timestamp, NULL, hoststr, initmsg,
- (void *) STDERR_FILENO);
+
+ virLogHostnameString(&hoststr, &initmsg);
+ virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
+ __FILE__, __LINE__, __func__,
+ timestamp, NULL, hoststr, initmsg,
+ (void *) STDERR_FILENO);
VIR_FREE(hoststr);
VIR_FREE(initmsg);
logInitMessageStderr = false;
if (fd < 0)
return;
- if (virAsprintfQuiet(&msg, "%s: %s", timestamp, str) < 0)
- return;
-
+ msg = g_strdup_printf("%s: %s", timestamp, str);
ignore_value(safewrite(fd, msg, strlen(msg)));
VIR_FREE(msg);
}
int virLogSetOutputs(const char *outputs);
int virLogSetFilters(const char *filters);
char *virLogGetDefaultOutput(void);
-int virLogSetDefaultOutput(const char *fname, bool godaemon, bool privileged);
+void virLogSetDefaultOutput(const char *fname, bool godaemon, bool privileged);
/*
* Internal logging API
{
char *filename;
- ignore_value(virAsprintf(&filename, "%s/%s.macs", dnsmasqStateDir, bridge));
+ filename = g_strdup_printf("%s/%s.macs", dnsmasqStateDir, bridge);
return filename;
}
g_autofree char *file = NULL;
char *tmp = NULL;
- if (virAsprintf(&file, "%s/mdev_type/device_api", dev->path) < 0)
- return -1;
+ file = g_strdup_printf("%s/mdev_type/device_api", dev->path);
/* TODO - make this a generic method to access sysfs files for various
* kinds of devices
if (!dev_path)
return NULL;
- if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0)
- return NULL;
+ iommu_path = g_strdup_printf("%s/iommu_group", dev_path);
if (!virFileExists(iommu_path)) {
virReportSystemError(errno, _("failed to access '%s'"), iommu_path);
return NULL;
}
- if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path)) < 0)
- return NULL;
+ vfio_path = g_strdup_printf("/dev/vfio/%s", last_component(result_path));
return vfio_path;
}
{
char *ret = NULL;
- ignore_value(virAsprintf(&ret, MDEV_SYSFS_DEVICES "%s", uuidstr));
+ ret = g_strdup_printf(MDEV_SYSFS_DEVICES "%s", uuidstr);
return ret;
}
char *phy_path = NULL;
int len;
- if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1)
- return -1;
+ pid = g_strdup_printf("%lld", (long long) pidInNs);
/* The 802.11 wireless devices only move together with their PHY. */
if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") < 0)
virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname,
const char *file)
{
- if (virAsprintf(pf_sysfs_device_link, SYSFS_NET_DIR "%s/%s", ifname, file) < 0)
- return -1;
+ *pf_sysfs_device_link = g_strdup_printf(SYSFS_NET_DIR "%s/%s", ifname, file);
return 0;
}
virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname,
const char *file)
{
- if (virAsprintf(pf_sysfs_device_link, SYSFS_NET_DIR "%s/device/%s", ifname,
- file) < 0)
- return -1;
+ *pf_sysfs_device_link = g_strdup_printf(SYSFS_NET_DIR "%s/device/%s", ifname,
+ file);
return 0;
}
char *subsys = NULL;
bool ret = false;
- if (virAsprintf(&subsys_link, "%s/subsystem", devpath) < 0)
- return false;
+ subsys_link = g_strdup_printf("%s/subsystem", devpath);
if (!virFileExists(subsys_link))
goto cleanup;
if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0)
goto cleanup;
- if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0)
- goto cleanup;
+ virtfnName = g_strdup_printf("virtfn%d", vf);
/* this provides the path to the VF's directory in sysfs,
* e.g. "/sys/class/net/enp2s0f0/virtfn3"
*/
if (pfDevName && saveVlan) {
- if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) < 0)
- goto cleanup;
+ filePath = g_strdup_printf("%s/%s_vf%d", stateDir, pfDevName, vf);
/* get admin MAC and vlan tag */
if (virNetDevGetVfConfig(pfDevName, vf, &oldMAC, &oldVlanTag) < 0)
}
} else {
- if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0)
- goto cleanup;
+ filePath = g_strdup_printf("%s/%s", stateDir, linkdev);
}
if (linkdev) {
*/
if (pfDevName) {
- if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) < 0)
- goto cleanup;
+ filePath = g_strdup_printf("%s/%s_vf%d", stateDir, pfDevName, vf);
if (linkdev && !virFileExists(filePath)) {
/* the device may have been stored in a file named for the
}
}
- if (!pfDevName) {
- if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0)
- goto cleanup;
- }
+ if (!pfDevName)
+ filePath = g_strdup_printf("%s/%s", stateDir, linkdev);
if (!virFileExists(filePath)) {
/* having no file to read is not necessarily an error, so we
if (virDirOpen(&dirp, SYSFS_INFINIBAND_DIR) < 0)
return -1;
- if (virAsprintf(ð_devpath, SYSFS_NET_DIR "%s/device/resource", ifname) < 0)
- goto cleanup;
+ eth_devpath = g_strdup_printf(SYSFS_NET_DIR "%s/device/resource", ifname);
/* If /sys/class/net/<ifname>/device/resource doesn't exist it is not a PCI
* device and therefore it will not have RDMA. */
goto cleanup;
while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) {
- if (virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resource",
- dp->d_name) < 0)
- continue;
+ ib_devpath = g_strdup_printf(SYSFS_INFINIBAND_DIR "%s/device/resource",
+ dp->d_name);
if (virFileReadAll(ib_devpath, RESOURCE_FILE_LEN, &ib_res_buf) > 0 &&
STREQ(eth_res_buf, ib_res_buf)) {
ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_RDMA));
}
/* u32 filters must have 800:: prefix. Don't ask. */
- if (virAsprintf(&filter_id, "800::%u", id) < 0)
- goto cleanup;
+ filter_id = g_strdup_printf("800::%u", id);
if (remove_old) {
int cmd_ret = 0;
if (create_new) {
virMacAddrGetRaw(ifmac_ptr, ifmac);
- if (virAsprintf(&mac[0], "0x%02x%02x%02x%02x", ifmac[2],
- ifmac[3], ifmac[4], ifmac[5]) < 0 ||
- virAsprintf(&mac[1], "0x%02x%02x", ifmac[0], ifmac[1]) < 0)
- goto cleanup;
+ mac[0] = g_strdup_printf("0x%02x%02x%02x%02x", ifmac[2],
+ ifmac[3], ifmac[4], ifmac[5]);
+ mac[1] = g_strdup_printf("0x%02x%02x", ifmac[0], ifmac[1]);
virCommandFree(cmd);
cmd = virCommandNew(TC);
virNetDevBandwidthClear(ifname);
if (tx && tx->average) {
- if (virAsprintf(&average, "%llukbps", tx->average) < 0)
- goto cleanup;
- if (tx->peak &&
- (virAsprintf(&peak, "%llukbps", tx->peak) < 0))
- goto cleanup;
- if (tx->burst &&
- (virAsprintf(&burst, "%llukb", tx->burst) < 0))
- goto cleanup;
+ average = g_strdup_printf("%llukbps", tx->average);
+ if (tx->peak)
+ peak = g_strdup_printf("%llukbps", tx->peak);
+ if (tx->burst)
+ burst = g_strdup_printf("%llukb", tx->burst);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname, "root",
}
if (rx) {
- if (virAsprintf(&average, "%llukbps", rx->average) < 0)
- goto cleanup;
- if (virAsprintf(&burst, "%llukb", rx->burst ? rx->burst : rx->average) < 0)
- goto cleanup;
+ average = g_strdup_printf("%llukbps", rx->average);
+ burst = g_strdup_printf("%llukb", rx->burst ? rx->burst : rx->average);
virCommandFree(cmd);
cmd = virCommandNew(TC);
return -1;
}
- if (virAsprintf(&class_id, "1:%x", id) < 0 ||
- virAsprintf(&qdisc_id, "%x:", id) < 0 ||
- virAsprintf(&floor, "%llukbps", bandwidth->in->floor) < 0 ||
- virAsprintf(&ceil, "%llukbps", net_bandwidth->in->peak ?
- net_bandwidth->in->peak :
- net_bandwidth->in->average) < 0)
- goto cleanup;
+ class_id = g_strdup_printf("1:%x", id);
+ qdisc_id = g_strdup_printf("%x:", id);
+ floor = g_strdup_printf("%llukbps", bandwidth->in->floor);
+ ceil = g_strdup_printf("%llukbps", net_bandwidth->in->peak ?
+ net_bandwidth->in->peak :
+ net_bandwidth->in->average);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "class", "add", "dev", brname, "parent", "1:1",
return -1;
}
- if (virAsprintf(&class_id, "1:%x", id) < 0 ||
- virAsprintf(&qdisc_id, "%x:", id) < 0)
- goto cleanup;
+ class_id = g_strdup_printf("1:%x", id);
+ qdisc_id = g_strdup_printf("%x:", id);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "del", "dev", brname,
char *rate = NULL;
char *ceil = NULL;
- if (virAsprintf(&class_id, "1:%x", id) < 0 ||
- virAsprintf(&rate, "%llukbps", new_rate) < 0 ||
- virAsprintf(&ceil, "%llukbps", bandwidth->in->peak ?
- bandwidth->in->peak :
- bandwidth->in->average) < 0)
- goto cleanup;
+ class_id = g_strdup_printf("1:%x", id);
+ rate = g_strdup_printf("%llukbps", new_rate);
+ ceil = g_strdup_printf("%llukbps", bandwidth->in->peak ?
+ bandwidth->in->peak :
+ bandwidth->in->average);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "class", "change", "dev", ifname,
int ret = -1;
char *class_id = NULL;
- if (virAsprintf(&class_id, "1:%x", id) < 0)
- goto cleanup;
+ class_id = g_strdup_printf("1:%x", id);
if (virNetDevBandwidthManipulateFilter(ifname, ifmac_ptr, id,
class_id, true, true) < 0)
{
g_autofree char *path = NULL;
- if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname) < 0)
- return -1;
+ path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname);
if (virFileExists(path)) {
char valuestr[INT_BUFSIZE_BOUND(value)];
g_autofree char *path = NULL;
VIR_AUTOCLOSE fd = -1;
- if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname) < 0)
- return -1;
+ path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname);
if (virFileExists(path)) {
g_autofree char *valuestr = NULL;
snprintf(valuestr, sizeof(valuestr), "%lu", value);
- if (virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s",
- brname, ifname, paramname) < 0)
- return -1;
+ path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname,
+ paramname);
if (!virFileExists(path))
errno = EINVAL;
g_autofree char *path = NULL;
g_autofree char *valuestr = NULL;
- if (virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s",
- brname, ifname, paramname) < 0)
- return -1;
+ path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname,
+ paramname);
if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0)
return -1;
char *suffix;
int accept_ra = -1;
- if (virAsprintf(&path, "/proc/sys/net/ipv6/conf/%s/accept_ra",
- ifname ? ifname : "all") < 0)
- return -1;
+ path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/accept_ra",
+ ifname ? ifname : "all");
if ((virFileReadAll(path, 512, &buf) < 0) ||
(virStrToLong_i(buf, &suffix, 10, &accept_ra) < 0))
if (virNetDevGetIndex(ifname, &ifindex) < 0)
return false;
- if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
- return false;
+ tapname = g_strdup_printf("/dev/tap%d", ifindex);
return virFileExists(tapname);
}
if (virNetDevGetIndex(ifname, &ifindex) < 0)
return -1;
- if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
- goto cleanup;
+ tapname = g_strdup_printf("/dev/tap%d", ifindex);
for (i = 0; i < tapfdSize; i++) {
int fd = -1;
virUUIDFormat(ovsport->interfaceID, ifuuidstr);
virUUIDFormat(vmuuid, vmuuidstr);
- if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=\"%s\"",
- macaddrstr) < 0)
- return -1;
- if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"",
- ifuuidstr) < 0)
- return -1;
- if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=\"%s\"",
- vmuuidstr) < 0)
- return -1;
+ attachedmac_ex_id = g_strdup_printf("external-ids:attached-mac=\"%s\"",
+ macaddrstr);
+ ifaceid_ex_id = g_strdup_printf("external-ids:iface-id=\"%s\"", ifuuidstr);
+ vmid_ex_id = g_strdup_printf("external-ids:vm-id=\"%s\"", vmuuidstr);
if (ovsport->profileID[0] != '\0') {
- if (virAsprintf(&profile_ex_id, "external-ids:port-profile=\"%s\"",
- ovsport->profileID) < 0)
- return -1;
+ profile_ex_id = g_strdup_printf("external-ids:port-profile=\"%s\"",
+ ovsport->profileID);
}
cmd = virCommandNew(OVSVSCTL);
for (i = 0; i <= IF_MAXUNIT; i++) {
g_autofree char *newname = NULL;
- if (virAsprintf(&newname, *ifname, i) < 0)
- goto cleanup;
+ newname = g_strdup_printf(*ifname, i);
if (virNetDevExists(newname) == 0) {
newifname = g_steal_pointer(&newname);
if (tapfd) {
g_autofree char *dev_path = NULL;
- if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0)
- goto cleanup;
+ dev_path = g_strdup_printf("/dev/%s", ifr.ifr_name);
if ((*tapfd = open(dev_path, O_RDWR)) < 0) {
virReportSystemError(errno,
int ret;
g_autofree char *path = NULL;
- if (virAsprintf(&path, SYSFS_NET_DIR "vnet%d/", devNum) < 0)
- return -1;
+ path = g_strdup_printf(SYSFS_NET_DIR "vnet%d/", devNum);
ret = virFileExists(path) ? 1 : 0;
VIR_DEBUG("Checked dev vnet%d usage: %d", devNum, ret);
return ret;
if ((veth1num = virNetDevVethGetFreeNum(vethNum)) < 0)
goto cleanup;
- if (virAsprintf(&veth1auto, "vnet%d", veth1num) < 0)
- goto cleanup;
+ veth1auto = g_strdup_printf("vnet%d", veth1num);
vethNum = veth1num + 1;
}
if (!*veth2) {
if ((veth2num = virNetDevVethGetFreeNum(vethNum)) < 0)
goto cleanup;
- if (virAsprintf(&veth2auto, "vnet%d", veth2num) < 0)
- goto cleanup;
+ veth2auto = g_strdup_printf("vnet%d", veth2num);
vethNum = veth2num + 1;
}
unsigned int page_size,
const char *suffix)
{
- int ret;
-
if (node == -1) {
/* We are aiming at overall system info */
- ret = virAsprintf(path,
- HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
- page_size, NULLSTR_EMPTY(suffix));
+ *path = g_strdup_printf(HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
+ page_size, NULLSTR_EMPTY(suffix));
} else {
/* We are aiming on specific NUMA node */
- ret = virAsprintf(path,
- HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
- HUGEPAGES_PREFIX "%ukB/%s",
- node, page_size, NULLSTR_EMPTY(suffix));
+ *path = g_strdup_printf(HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
+ HUGEPAGES_PREFIX "%ukB/%s",
+ node, page_size, NULLSTR_EMPTY(suffix));
}
- if (ret >= 0 && !virFileExists(*path)) {
- ret = -1;
+ if (!virFileExists(*path)) {
if (node != -1) {
if (!virNumaNodeIsAvailable(node)) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("page size %u is not available"),
page_size);
}
+ return -1;
}
- return ret;
+ return 0;
}
static int
*path = g_strdup(HUGEPAGES_SYSTEM_PREFIX);
return 0;
} else {
- return virAsprintf(path,
- HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
- node);
+ *path = g_strdup_printf(HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
+ node);
+ return 0;
}
}
* all the pages we wanted. So do the second read to check.
*/
VIR_FREE(nr_buf);
- if (virAsprintf(&nr_buf, "%llu", page_count) < 0)
- return -1;
+ nr_buf = g_strdup_printf("%llu", page_count);
if (virFileWriteStr(nr_path, nr_buf, 0) < 0) {
virReportSystemError(errno,
{
char *buffer;
- ignore_value(virAsprintf(&buffer, PCI_SYSFS "drivers/%s", driver));
+ buffer = g_strdup_printf(PCI_SYSFS "drivers/%s", driver);
return buffer;
}
{
char *buffer;
- ignore_value(virAsprintf(&buffer, PCI_SYSFS "devices/%s/%s", device, file));
+ buffer = g_strdup_printf(PCI_SYSFS "devices/%s/%s", device, file);
return buffer;
}
* device is a VF, we just assume FLR works
*/
- if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name) < 0)
- return -1;
+ path = g_strdup_printf(PCI_SYSFS "devices/%s/physfn", dev->name);
found = virFileExists(path);
if (found) {
{
char *str;
- ignore_value(virAsprintf(&str,
- VIR_PCI_DEVICE_ADDRESS_FMT,
- addr->domain,
- addr->bus,
- addr->slot,
- addr->function));
+ str = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT,
+ addr->domain,
+ addr->bus,
+ addr->slot,
+ addr->function);
return str;
}
dev->address.slot = slot;
dev->address.function = function;
- if (virAsprintf(&dev->name,
- VIR_PCI_DEVICE_ADDRESS_FMT,
- domain, bus, slot, function) < 0)
- return NULL;
+ dev->name = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, domain, bus, slot,
+ function);
- if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config",
- dev->name) < 0)
- return NULL;
+ dev->path = g_strdup_printf(PCI_SYSFS "devices/%s/config", dev->name);
if (!virFileExists(dev->path)) {
virReportSystemError(errno,
struct dirent *ent;
int direrr;
- if (virAsprintf(&pcidir, "/sys/bus/pci/devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
- dev->address.domain, dev->address.bus,
- dev->address.slot, dev->address.function) < 0)
- goto cleanup;
+ pcidir = g_strdup_printf("/sys/bus/pci/devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
+ dev->address.domain, dev->address.bus, dev->address.slot,
+ dev->address.function);
if (virDirOpen(&dir, pcidir) < 0)
goto cleanup;
STREQ(ent->d_name, "vendor") ||
STREQ(ent->d_name, "device") ||
STREQ(ent->d_name, "reset")) {
- if (virAsprintf(&file, "%s/%s", pcidir, ent->d_name) < 0)
- goto cleanup;
+ file = g_strdup_printf("%s/%s", pcidir, ent->d_name);
if ((actor)(dev, file, opaque) < 0)
goto cleanup;
}
struct dirent *ent;
int direrr;
- if (virAsprintf(&groupPath,
- PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT "/iommu_group/devices",
- orig->domain, orig->bus, orig->slot, orig->function) < 0)
- goto cleanup;
+ groupPath = g_strdup_printf(PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT "/iommu_group/devices",
+ orig->domain, orig->bus, orig->slot, orig->function);
if (virDirOpenQuiet(&groupDir, groupPath) < 0) {
/* just process the original device, nothing more */
const char *groupNumStr;
unsigned int groupNum;
- if (virAsprintf(&devName,
- VIR_PCI_DEVICE_ADDRESS_FMT,
- addr->domain, addr->bus, addr->slot, addr->function) < 0)
- return -1;
+ devName = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain, addr->bus,
+ addr->slot, addr->function);
if (!(devPath = virPCIFile(devName, "iommu_group")))
return -1;
dev->name, devPath);
return NULL;
}
- if (virAsprintf(&groupDev, "/dev/vfio/%s",
- last_component(groupPath)) < 0)
- return NULL;
+ groupDev = g_strdup_printf("/dev/vfio/%s", last_component(groupPath));
return groupDev;
}
*num_virtual_functions = 0;
*max_virtual_functions = 0;
- if (virAsprintf(&totalvfs_file, "%s/sriov_totalvfs", sysfs_path) < 0)
- goto error;
+ totalvfs_file = g_strdup_printf("%s/sriov_totalvfs", sysfs_path);
if (virFileExists(totalvfs_file)) {
char *end = NULL; /* so that terminating \n doesn't create error */
do {
g_autofree char *device_link = NULL;
/* look for virtfn%d links until one isn't found */
- if (virAsprintf(&device_link, "%s/virtfn%zu", sysfs_path, *num_virtual_functions) < 0)
- goto error;
+ device_link = g_strdup_printf("%s/virtfn%zu", sysfs_path,
+ *num_virtual_functions);
if (!virFileExists(device_link))
break;
{
g_autofree char *vf_sysfs_physfn_link = NULL;
- if (virAsprintf(&vf_sysfs_physfn_link, "%s/physfn",
- vf_sysfs_device_link) < 0)
- return -1;
+ vf_sysfs_physfn_link = g_strdup_printf("%s/physfn", vf_sysfs_device_link);
return virFileExists(vf_sysfs_physfn_link);
}
int
virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link)
{
- if (virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
- virPCIDeviceName) < 0)
- return -1;
+ *pci_sysfs_device_link = g_strdup_printf(PCI_SYSFS "devices/%s",
+ virPCIDeviceName);
return 0;
}
virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr addr,
char **pci_sysfs_device_link)
{
- if (virAsprintf(pci_sysfs_device_link,
- PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
- addr->domain, addr->bus,
- addr->slot, addr->function) < 0)
- return -1;
+ *pci_sysfs_device_link = g_strdup_printf(PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain,
+ addr->bus, addr->slot, addr->function);
return 0;
}
size_t ntypes = 0;
size_t i;
- if (virAsprintf(&types_path, "%s/mdev_supported_types", sysfspath) < 0)
- return -1;
+ types_path = g_strdup_printf("%s/mdev_supported_types", sysfspath);
if ((dirret = virDirOpenIfExists(&dir, types_path)) < 0)
goto cleanup;
while ((dirret = virDirRead(dir, &entry, types_path)) > 0) {
g_autofree char *tmppath = NULL;
/* append the type id to the path and read the attributes from there */
- if (virAsprintf(&tmppath, "%s/%s", types_path, entry->d_name) < 0)
- goto cleanup;
+ tmppath = g_strdup_printf("%s/%s", types_path, entry->d_name);
if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0)
goto cleanup;
goto cleanup;
}
- if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) < 0)
- return -ENOMEM;
+ procPath = g_strdup_printf("/proc/%lld/exe", (long long)retPid);
if ((ret = virFileIsLink(procPath)) < 0)
return ret;
"%s", _("No runstatedir specified"));
return -1;
}
- if (virAsprintf(pidfile, "%s/%s.pid", runstatedir, progname) < 0)
- return -1;
+ *pidfile = g_strdup_printf("%s/%s.pid", runstatedir, progname);
} else {
if (!(rundir = virGetUserRuntimeDirectory()))
return -1;
return -1;
}
- if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0)
- return -1;
+ *pidfile = g_strdup_printf("%s/%s.pid", rundir, progname);
}
return 0;
{
char *buf;
if (WIFEXITED(status)) {
- ignore_value(virAsprintfQuiet(&buf, _("exit status %d"),
- WEXITSTATUS(status)));
+ buf = g_strdup_printf(_("exit status %d"),
+ WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
- ignore_value(virAsprintfQuiet(&buf, _("fatal signal %d"),
- WTERMSIG(status)));
+ buf = g_strdup_printf(_("fatal signal %d"),
+ WTERMSIG(status));
} else {
- ignore_value(virAsprintfQuiet(&buf, _("invalid value %d"), status));
+ buf = g_strdup_printf(_("invalid value %d"), status);
}
return buf;
}
*npids = 0;
*pids = NULL;
- if (virAsprintf(&taskPath, "/proc/%llu/task", (long long) pid) < 0)
- goto cleanup;
+ taskPath = g_strdup_printf("/proc/%llu/task", (long long)pid);
if (virDirOpen(&dir, taskPath) < 0)
goto cleanup;
int fd;
g_autofree char *nsfile = NULL;
- if (virAsprintf(&nsfile, "/proc/%llu/ns/%s",
- (long long) pid,
- ns[i]) < 0)
- goto cleanup;
+ nsfile = g_strdup_printf("/proc/%llu/ns/%s", (long long)pid, ns[i]);
if ((fd = open(nsfile, O_RDONLY)) >= 0) {
if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) {
g_autofree char *buf = NULL;
VIR_AUTOSTRINGLIST tokens = NULL;
- if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0)
- return -1;
+ filename = g_strdup_printf("/proc/%llu/stat", (long long)pid);
if ((len = virFileReadAll(filename, 1024, &buf)) < 0)
return -1;
int ret = -1;
g_autofree char *path = NULL;
- if (virAsprintf(&path, "/proc/%lld/ns/mnt", (long long) data->pid) < 0)
- goto cleanup;
+ path = g_strdup_printf("/proc/%lld/ns/mnt", (long long)data->pid);
if ((fd = open(path, O_RDONLY)) < 0) {
virReportSystemError(errno, "%s",
member = virJSONValueArrayGet((virJSONValuePtr) array, i);
g_autofree char *prefix = NULL;
- if (virAsprintf(&prefix, "%s.%zu", key, i) < 0)
- return 0;
+ prefix = g_strdup_printf("%s.%zu", key, i);
if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf,
virQEMUBuildCommandLineJSONArrayNumbered,
if (data->prefix) {
g_autofree char *tmpkey = NULL;
- if (virAsprintf(&tmpkey, "%s.%s", data->prefix, key) < 0)
- return -1;
+ tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
data->arrayFunc, false);
return -1;
}
- if (virAsprintf(wwn, "5" "%s%09llx", oui,
- (unsigned long long)virRandomBits(36)) < 0)
- return -1;
+ *wwn = g_strdup_printf("5" "%s%09llx", oui,
+ (unsigned long long)virRandomBits(36));
return 0;
}
return NULL;
}
- if (virAsprintf(&path, "%s/%s-%s", parentpath, prefix, id) < 0)
- return NULL;
+ path = g_strdup_printf("%s/%s-%s", parentpath, prefix, id);
return path;
}
if (!alloc_str)
goto cleanup;
- if (virAsprintf(&schemata_path, "%s/schemata", alloc->path) < 0)
- goto cleanup;
+ schemata_path = g_strdup_printf("%s/schemata", alloc->path);
VIR_DEBUG("Writing resctrl schemata '%s' into '%s'", alloc_str, schemata_path);
if (virFileWriteStr(schemata_path, alloc_str, 0) < 0) {
return -1;
}
- if (virAsprintf(&tasks, "%s/tasks", path) < 0)
- return -1;
+ tasks = g_strdup_printf("%s/tasks", path);
- if (virAsprintf(&pidstr, "%lld", (long long int) pid) < 0)
- goto cleanup;
+ pidstr = g_strdup_printf("%lld", (long long int)pid);
if (virFileWriteStr(tasks, pidstr, 0) < 0) {
virReportSystemError(errno,
return 0;
}
- if (virAsprintf(&parentpath, "%s/mon_groups", monitor->alloc->path) < 0)
- return -1;
+ parentpath = g_strdup_printf("%s/mon_groups", monitor->alloc->path);
monitor->path = virResctrlDeterminePath(parentpath, machinename,
monitor->id);
return -1;
}
- if (virAsprintf(&datapath, "%s/mon_data", monitor->path) < 0)
- return -1;
+ datapath = g_strdup_printf("%s/mon_data", monitor->path);
if (virDirOpen(&dirp, datapath) < 0)
goto cleanup;
* "mon_L3_01" are two target directories for a two nodes system
* with resource utilization data file for each node respectively.
*/
- if (virAsprintf(&filepath, "%s/%s", datapath, ent->d_name) < 0)
- goto cleanup;
+ filepath = g_strdup_printf("%s/%s", datapath, ent->d_name);
if (!virFileIsDir(filepath))
continue;
for (i = 0; i < file->maxbackup; i++) {
char *oldpath;
- if (virAsprintf(&oldpath, "%s.%zu", file->basepath, i) < 0)
- return -1;
+ oldpath = g_strdup_printf("%s.%zu", file->basepath, i);
if (unlink(oldpath) < 0 &&
errno != ENOENT) {
for (i = 0; i < maxbackup; i++) {
char *tmppath;
- if (virAsprintf(&tmppath, "%s.%zu", path, i) < 0)
- goto error;
+ tmppath = g_strdup_printf("%s.%zu", path, i);
file->entries[file->nentries - (i + 2)] = virRotatingFileReaderEntryNew(tmppath);
VIR_FREE(tmppath);
goto cleanup;
}
} else {
- if (virAsprintf(&nextpath, "%s.%zu", file->basepath, file->maxbackup - 1) < 0)
- return -1;
+ nextpath = g_strdup_printf("%s.%zu", file->basepath, file->maxbackup - 1);
for (i = file->maxbackup; i > 0; i--) {
if (i == 1) {
thispath = g_strdup(file->basepath);
} else {
- if (virAsprintf(&thispath, "%s.%zu", file->basepath, i - 2) < 0)
- goto cleanup;
+ thispath = g_strdup_printf("%s.%zu", file->basepath, i - 2);
}
VIR_DEBUG("Rollover %s -> %s", thispath, nextpath);
if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
return NULL;
- if (virAsprintf(&path,
- "%s/%d:%u:%u:%llu/scsi_generic",
- prefix, adapter_id, bus, target, unit) < 0)
- return NULL;
+ path = g_strdup_printf("%s/%d:%u:%u:%llu/scsi_generic", prefix, adapter_id,
+ bus, target, unit);
if (virDirOpen(&dir, path) < 0)
goto cleanup;
if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
return NULL;
- if (virAsprintf(&path,
- "%s/%d:%u:%u:%llu/block",
- prefix, adapter_id, bus, target, unit) < 0)
- return NULL;
+ path = g_strdup_printf("%s/%d:%u:%u:%llu/block", prefix, adapter_id, bus,
+ target, unit);
if (virDirOpen(&dir, path) < 0)
goto cleanup;
if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0)
return NULL;
- if (virAsprintf(&dev->name, "%d:%u:%u:%llu", dev->adapter,
- dev->bus, dev->target, dev->unit) < 0 ||
- virAsprintf(&dev->sg_path, "%s/%s",
- sysfs_prefix ? sysfs_prefix : "/dev", sg) < 0)
- return NULL;
+ dev->name = g_strdup_printf("%d:%u:%u:%llu", dev->adapter,
+ dev->bus, dev->target, dev->unit);
+ dev->sg_path = g_strdup_printf("%s/%s",
+ sysfs_prefix ? sysfs_prefix : "/dev", sg);
if (!virFileExists(dev->sg_path)) {
virReportSystemError(errno,
return NULL;
}
- if (virAsprintf(&vendor_path,
- "%s/%s/vendor", prefix, dev->name) < 0 ||
- virAsprintf(&model_path,
- "%s/%s/model", prefix, dev->name) < 0)
- return NULL;
+ vendor_path = g_strdup_printf("%s/%s/vendor", prefix, dev->name);
+ model_path = g_strdup_printf("%s/%s/model", prefix, dev->name);
if (virFileReadAll(vendor_path, 1024, &vendor) < 0)
return NULL;
virTrimSpaces(vendor, NULL);
virTrimSpaces(model, NULL);
- if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0)
- return NULL;
+ dev->id = g_strdup_printf("%s:%s", vendor, model);
return g_steal_pointer(&dev);
}
char *buf = NULL;
int unique_id;
- if (virAsprintf(&sysfs_path, "%s/host%d/unique_id",
- sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH,
- host) < 0)
- return -1;
+ sysfs_path = g_strdup_printf("%s/host%d/unique_id",
+ sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host);
if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
goto cleanup;
if (!virFileIsLink(entry->d_name))
continue;
- if (virAsprintf(&host_link, "%s/%s", prefix, entry->d_name) < 0)
- goto cleanup;
+ host_link = g_strdup_printf("%s/%s", prefix, entry->d_name);
if (virFileResolveLink(host_link, &host_path) < 0)
goto cleanup;
VIR_FREE(host_link);
VIR_FREE(host_path);
- if (virAsprintf(&unique_path, "%s/%s/unique_id", prefix,
- entry->d_name) < 0)
- goto cleanup;
+ unique_path = g_strdup_printf("%s/%s/unique_id", prefix, entry->d_name);
if (!virFileExists(unique_path)) {
VIR_FREE(unique_path);
char *name = NULL;
char *parentaddr = NULL;
- if (virAsprintf(&parentaddr, "%04x:%02x:%02x.%01x",
- domain, bus, slot, function) < 0)
- goto cleanup;
+ parentaddr = g_strdup_printf("%04x:%02x:%02x.%01x", domain, bus, slot,
+ function);
if (!(name = virSCSIHostFindByPCI(NULL, parentaddr, unique_id))) {
virReportError(VIR_ERR_XML_ERROR,
_("Failed to find scsi_host using PCI '%s' "
dev->name = g_strdup(name);
- if (virAsprintf(&dev->path, "%s/%s",
- SYSFS_VHOST_SCSI_DEVICES, name) < 0)
- return NULL;
+ dev->path = g_strdup_printf("%s/%s", SYSFS_VHOST_SCSI_DEVICES, name);
VIR_DEBUG("%s: initialized", dev->name);
* nicely for UNIX sockets */
if (addr->data.sa.sa_family == AF_UNIX) {
if (withService) {
- if (virAsprintf(&addrstr, VIR_LOOPBACK_IPV4_ADDR"%s0",
- separator ? separator : ":") < 0)
- return NULL;
+ addrstr = g_strdup_printf(VIR_LOOPBACK_IPV4_ADDR "%s0",
+ separator ? separator : ":");
} else {
addrstr = g_strdup(VIR_LOOPBACK_IPV4_ADDR);
}
* a.b.c.d;port or e:f:g:h:i:j:k:l;port, so use square brackets for
* IPv6 only if no separator is passed to the function
*/
- if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET6) {
- if (virAsprintf(&ipv6_host, "[%s]", host) < 0)
- return NULL;
- }
+ if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET6)
+ ipv6_host = g_strdup_printf("[%s]", host);
- if (virAsprintf(&addrstr, "%s%s%s",
- ipv6_host ? ipv6_host : host,
- separator ? separator : ":", port) == -1) {
- return NULL;
- }
+ addrstr = g_strdup_printf("%s%s%s",
+ ipv6_host ? ipv6_host : host,
+ separator ? separator : ":", port);
} else {
addrstr = g_strdup(host);
}
*tmp = '\0';
if (*serial != '\0' && *port != '\0')
- ignore_value(virAsprintf(key, "%s_PORT%s", serial, port));
+ *key = g_strdup_printf("%s_PORT%s", serial, port);
}
return 0;
}
if (STRNEQ(dirname, "/")) {
- if (virAsprintf(&def->path, "%s/%s", dirname, rel) < 0)
- return NULL;
+ def->path = g_strdup_printf("%s/%s", dirname, rel);
} else {
- if (virAsprintf(&def->path, "/%s", rel) < 0)
- return NULL;
+ def->path = g_strdup_printf("/%s", rel);
}
if (virStorageSourceGetActualType(parent) == VIR_STORAGE_TYPE_NETWORK) {
*port = '\0';
}
- if (virAsprintf(&src->path, "%s/%s", target, lun) < 0)
- return -1;
+ src->path = g_strdup_printf("%s/%s", target, lun);
/* Libvirt doesn't handle inline authentication. Make the caller aware. */
if (virJSONValueObjectGetString(json, "user") ||
VIR_FREE(path);
- if (virAsprintf(&path, "%s%s", tmp, next->relPath) < 0)
- return -1;
+ path = g_strdup_printf("%s%s", tmp, next->relPath);
VIR_FREE(tmp);
virDoubleToStr(char **strp, double number)
{
virLocale oldlocale;
- int rc;
if (virLocaleSetRaw(&oldlocale) < 0)
return -1;
- rc = virAsprintf(strp, "%lf", number);
+ *strp = g_strdup_printf("%lf", number);
virLocaleRevert(&oldlocale);
virLocaleFixupRadix(strp);
- if (rc < 0)
- return -1;
return 0;
}
G_GNUC_WARN_UNUSED_RESULT;
int virDoubleToStr(char **strp, double number)
- ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
+ ATTRIBUTE_NONNULL(1);
void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
ret = -1;
- if (virAsprintf(&creatorname, "libvirt-%s", drivername) < 0)
- goto cleanup;
+ creatorname = g_strdup_printf("libvirt-%s", drivername);
if (partition) {
if (!(slicename = virSystemdMakeSliceName(partition)))
const char *dev;
const char *prefix[] = {"misc/", "tpm/"};
size_t i;
+ if (!devpath) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Missing TPM device path"));
+ return NULL;
+ }
+
+ if (!(dev = strrchr(devpath, '/'))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("TPM device path %s is invalid"), devpath);
+ return NULL;
+ }
- if (devpath) {
- dev = strrchr(devpath, '/');
- if (dev) {
- dev++;
- for (i = 0; i < G_N_ELEMENTS(prefix); i++) {
- if (virAsprintf(&path, "/sys/class/%s%s/device/cancel",
- prefix[i], dev) < 0)
- goto cleanup;
+ dev++;
+ for (i = 0; i < G_N_ELEMENTS(prefix); i++) {
+ path = g_strdup_printf("/sys/class/%s%s/device/cancel", prefix[i],
+ dev);
- if (virFileExists(path))
- break;
+ if (virFileExists(path))
+ break;
- VIR_FREE(path);
- }
- if (!path)
- path = g_strdup("/dev/null");
- } else {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("TPM device path %s is invalid"), devpath);
- }
- } else {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Missing TPM device path"));
+ VIR_FREE(path);
}
+ if (!path)
+ path = g_strdup("/dev/null");
- cleanup:
return path;
}
switch (param->type) {
case VIR_TYPED_PARAM_INT:
- ignore_value(virAsprintf(&value, "%d", param->value.i));
+ value = g_strdup_printf("%d", param->value.i);
break;
case VIR_TYPED_PARAM_UINT:
- ignore_value(virAsprintf(&value, "%u", param->value.ui));
+ value = g_strdup_printf("%u", param->value.ui);
break;
case VIR_TYPED_PARAM_LLONG:
- ignore_value(virAsprintf(&value, "%lld", param->value.l));
+ value = g_strdup_printf("%lld", param->value.l);
break;
case VIR_TYPED_PARAM_ULLONG:
- ignore_value(virAsprintf(&value, "%llu", param->value.ul));
+ value = g_strdup_printf("%llu", param->value.ul);
break;
case VIR_TYPED_PARAM_DOUBLE:
- ignore_value(virAsprintf(&value, "%g", param->value.d));
+ value = g_strdup_printf("%g", param->value.d);
break;
case VIR_TYPED_PARAM_BOOLEAN:
- ignore_value(virAsprintf(&value, "%d", param->value.b));
+ value = g_strdup_printf("%d", param->value.b);
break;
case VIR_TYPED_PARAM_STRING:
value = g_strdup(param->value.s);
if (xmluri.server != NULL &&
strchr(xmluri.server, ':') != NULL) {
- if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0)
- return NULL;
+ tmpserver = g_strdup_printf("[%s]", xmluri.server);
xmluri.server = tmpserver;
}
static int virUSBSysReadFile(const char *f_name, const char *d_name,
int base, unsigned int *value)
{
- int tmp;
g_autofree char *buf = NULL;
g_autofree char *filename = NULL;
char *ignore = NULL;
- tmp = virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name);
- if (tmp < 0)
- return -1;
+ filename = g_strdup_printf(USB_SYSFS "/devices/%s/%s", d_name, f_name);
if (virFileReadAll(filename, 1024, &buf) < 0)
return -1;
const char *vroot)
{
virUSBDevicePtr dev;
- int rc;
if (VIR_ALLOC(dev) < 0)
return NULL;
}
if (vroot) {
- rc = virAsprintf(&dev->path, "%s/%03d/%03d",
- vroot, dev->bus, dev->dev);
+ dev->path = g_strdup_printf("%s/%03d/%03d",
+ vroot, dev->bus, dev->dev);
} else {
- rc = virAsprintf(&dev->path, USB_DEVFS "%03d/%03d",
- dev->bus, dev->dev);
- }
-
- if (rc < 0) {
- virUSBDeviceFree(dev);
- return NULL;
+ dev->path = g_strdup_printf(USB_DEVFS "%03d/%03d",
+ dev->bus, dev->dev);
}
/* XXX fixme. this should be product/vendor */
char *home = NULL;
if (path && path[0]) {
- ignore_value(virAsprintf(&ret, "%s/libvirt", path));
+ ret = g_strdup_printf("%s/libvirt", path);
} else {
home = virGetUserDirectory();
if (home)
- ignore_value(virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir));
+ ret = g_strdup_printf("%s/%s/libvirt", home, xdgdefdir);
}
VIR_FREE(home);
} else {
char *ret;
- ignore_value(virAsprintf(&ret, "%s/libvirt", path));
+ ret = g_strdup_printf("%s/libvirt", path);
return ret;
}
}
return NULL;
}
- ignore_value(virAsprintf(&sysfs_path, "%s/%d:%d/queue/unpriv_sgio",
- sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH,
- maj, min));
+ sysfs_path = g_strdup_printf("%s/%d:%d/queue/unpriv_sgio",
+ sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH,
+ maj, min);
return sysfs_path;
}
goto cleanup;
}
- if (virAsprintf(&val, "%d", unpriv_sgio) < 0)
- goto cleanup;
+ val = g_strdup_printf("%d", unpriv_sgio);
if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
goto cleanup;
}
- if (virAsprintf(&ret, "%s/%s", driPath, ent->d_name) < 0)
- goto cleanup;
+ ret = g_strdup_printf("%s/%s", driPath, ent->d_name);
cleanup:
VIR_DIR_CLOSE(driDir);
char *sysfs_path = NULL;
bool ret = false;
- if (virAsprintf(&sysfs_path, "%s/host%d",
- sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
- host) < 0)
- return false;
+ sysfs_path = g_strdup_printf("%s/host%d",
+ sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host);
if (virFileExists(sysfs_path))
ret = true;
char *fc_host_path = NULL;
bool ret = false;
- if (virAsprintf(&fc_host_path,
- "%s/host%d/%s",
- sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
- host,
- "vport_create") < 0)
- return false;
-
- if (virAsprintf(&scsi_host_path,
- "%s/host%d/%s",
- sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH,
- host,
- "vport_create") < 0)
- goto cleanup;
+ fc_host_path = g_strdup_printf("%s/host%d/%s",
+ sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host,
+ "vport_create");
+
+ scsi_host_path = g_strdup_printf("%s/host%d/%s",
+ sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host,
+ "vport_create");
if (virFileExists(fc_host_path) || virFileExists(scsi_host_path))
ret = true;
- cleanup:
VIR_FREE(fc_host_path);
VIR_FREE(scsi_host_path);
return ret;
char *buf = NULL;
char *result = NULL;
- if (virAsprintf(&sysfs_path, "%s/host%d/%s",
- sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
- host, entry) < 0)
- goto cleanup;
+ sysfs_path = g_strdup_printf("%s/host%d/%s",
+ sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host, entry);
if (!virFileExists(sysfs_path))
goto cleanup;
goto cleanup;
}
- if (virAsprintf(&operation_path, "%s/host%d/%s",
- SYSFS_FC_HOST_PATH, parent_host, operation_file) < 0)
- goto cleanup;
+ operation_path = g_strdup_printf("%s/host%d/%s", SYSFS_FC_HOST_PATH,
+ parent_host, operation_file);
if (!virFileExists(operation_path)) {
VIR_FREE(operation_path);
- if (virAsprintf(&operation_path, "%s/host%d/%s",
- SYSFS_SCSI_HOST_PATH, parent_host, operation_file) < 0)
- goto cleanup;
+ operation_path = g_strdup_printf("%s/host%d/%s", SYSFS_SCSI_HOST_PATH,
+ parent_host, operation_file);
if (!virFileExists(operation_path)) {
virReportError(VIR_ERR_OPERATION_INVALID,
* in calling either the Add or Remove device functions. This translates
* into either adding or removing a node device object and a node device
* lifecycle event for applications to consume. */
- if (virAsprintf(&vport_name, "%s:%s", wwpn, wwnn) < 0)
- goto cleanup;
+ vport_name = g_strdup_printf("%s:%s", wwpn, wwnn);
if (virFileWriteStr(operation_path, vport_name, 0) == 0)
ret = 0;
char *p;
int ret = -1;
- if (virAsprintf(&path, "%s/%s/%s", prefix, d_name, f_name) < 0)
- return -1;
+ path = g_strdup_printf("%s/%s/%s", prefix, d_name, f_name);
if (!virFileExists(path)) {
ret = 0;
/* Existing vHBA's will have the same fabric_name, but won't
* have the vport_create file - so we check for both */
- if (virAsprintf(&vport_create_path, "%s/%s/vport_create", prefix,
- entry->d_name) < 0)
- goto cleanup;
+ vport_create_path = g_strdup_printf("%s/%s/vport_create", prefix,
+ entry->d_name);
if (!virFileExists(vport_create_path))
continue;