Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/util/viraudit.c | 2 +- src/util/virauth.c | 10 ++--- src/util/virauthconfig.c | 6 +-- src/util/vircgroup.c | 22 +++++------ src/util/vircgroupv1.c | 64 ++++++++++++++++---------------- src/util/vircgroupv2.c | 64 ++++++++++++++++---------------- src/util/virconf.c | 4 +- src/util/virdevmapper.c | 6 +-- src/util/virdnsmasq.c | 30 +++++++-------- src/util/virebtables.c | 2 +- src/util/virerror.c | 2 +- src/util/virfile.c | 26 ++++++------- src/util/virhostcpu.c | 8 ++-- src/util/virhostdev.c | 2 +- src/util/virhostmem.c | 12 +++--- src/util/viriptables.c | 12 +++--- src/util/viriscsi.c | 4 +- src/util/virjson.c | 8 ++-- src/util/virkmod.c | 2 +- src/util/virlockspace.c | 2 +- src/util/virlog.c | 30 +++++++-------- src/util/virmacmap.c | 2 +- src/util/virmdev.c | 8 ++-- src/util/virnetdev.c | 26 ++++++------- src/util/virnetdevbandwidth.c | 46 +++++++++++------------ src/util/virnetdevbridge.c | 12 +++--- src/util/virnetdevip.c | 4 +- src/util/virnetdevmacvlan.c | 4 +- src/util/virnetdevopenvswitch.c | 12 +++--- src/util/virnetdevtap.c | 4 +- src/util/virnetdevveth.c | 6 +-- src/util/virnuma.c | 19 ++++------ src/util/virpci.c | 65 ++++++++++++++++----------------- src/util/virpidfile.c | 6 +-- src/util/virprocess.c | 18 ++++----- src/util/virqemu.c | 4 +- src/util/virrandom.c | 4 +- src/util/virresctrl.c | 14 +++---- src/util/virrotatingfile.c | 8 ++-- src/util/virscsi.c | 22 +++++------ src/util/virscsihost.c | 12 +++--- src/util/virscsivhost.c | 2 +- src/util/virsocketaddr.c | 12 +++--- src/util/virstoragefile.c | 10 ++--- src/util/virstring.c | 2 +- src/util/virsystemd.c | 2 +- src/util/virtpm.c | 4 +- src/util/virtypedparam.c | 12 +++--- src/util/viruri.c | 2 +- src/util/virusb.c | 10 ++--- src/util/virutil.c | 16 ++++---- src/util/virvhba.c | 36 +++++++++--------- 52 files changed, 359 insertions(+), 363 deletions(-) diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 9d423e8f53..8a0ef6f72c 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -158,7 +158,7 @@ char *virAuditEncode(const char *key, const char *value) return audit_encode_nv_string(key, value, 0); #else char *str; - virAsprintf(&str, "%s=%s", key, value); + str = g_strdup_printf("%s=%s", key, value); return str; #endif } diff --git a/src/util/virauth.c b/src/util/virauth.c index 9ff639ffa8..55208c01ef 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -69,7 +69,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri, if (!(userdir = virGetUserConfigDirectory())) return -1; - virAsprintf(path, "%s/auth.conf", userdir); + *path = g_strdup_printf("%s/auth.conf", userdir); VIR_DEBUG("Checking for readability of '%s'", *path); if (access(*path, R_OK) == 0) @@ -157,10 +157,10 @@ virAuthGetUsernamePath(const char *path, memset(&cred, 0, sizeof(virConnectCredential)); if (defaultUsername != NULL) { - virAsprintf(&prompt, _("Enter username for %s [%s]"), hostname, - defaultUsername); + prompt = g_strdup_printf(_("Enter username for %s [%s]"), hostname, + defaultUsername); } else { - virAsprintf(&prompt, _("Enter username for %s"), hostname); + prompt = g_strdup_printf(_("Enter username for %s"), hostname); } for (ncred = 0; ncred < auth->ncredtype; ncred++) { @@ -237,7 +237,7 @@ virAuthGetPasswordPath(const char *path, memset(&cred, 0, sizeof(virConnectCredential)); - virAsprintf(&prompt, _("Enter %s's password for %s"), username, hostname); + 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 && diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index b7263ebccb..fd846ddd4b 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -113,11 +113,11 @@ int virAuthConfigLookup(virAuthConfigPtr auth, if (!hostname) hostname = "localhost"; - virAsprintf(&authgroup, "auth-%s-%s", service, hostname); + authgroup = g_strdup_printf("auth-%s-%s", service, hostname); if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { VIR_FREE(authgroup); - virAsprintf(&authgroup, "auth-%s-%s", service, "default"); + authgroup = g_strdup_printf("auth-%s-%s", service, "default"); } if (!virKeyFileHasGroup(auth->keyfile, authgroup)) @@ -130,7 +130,7 @@ int virAuthConfigLookup(virAuthConfigPtr auth, return -1; } - virAsprintf(&credgroup, "credentials-%s", authcred); + credgroup = g_strdup_printf("credentials-%s", authcred); if (!virKeyFileHasGroup(auth->keyfile, credgroup)) { virReportError(VIR_ERR_CONF_SYNTAX, diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 8545cd3049..d5288ecfc5 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -206,7 +206,7 @@ virCgroupPartitionEscape(char **path) if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0) return rc; - virAsprintf(&newstr, "_%s", *path); + newstr = g_strdup_printf("_%s", *path); VIR_FREE(*path); *path = newstr; @@ -290,7 +290,7 @@ virCgroupDetectPlacement(virCgroupPtr group, if (pid == -1) { procfile = g_strdup("/proc/self/cgroup"); } else { - virAsprintf(&procfile, "/proc/%lld/cgroup", (long long)pid); + procfile = g_strdup_printf("/proc/%lld/cgroup", (long long)pid); } mapping = fopen(procfile, "r"); @@ -443,7 +443,7 @@ virCgroupGetBlockDevString(const char *path) /* Automatically append space after the string since all callers * use it anyway */ - virAsprintf(&ret, "%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)); + ret = g_strdup_printf("%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)); return ret; } @@ -559,7 +559,7 @@ virCgroupSetValueU64(virCgroupPtr group, { g_autofree char *strval = NULL; - virAsprintf(&strval, "%llu", value); + strval = g_strdup_printf("%llu", value); return virCgroupSetValueStr(group, controller, key, strval); } @@ -573,7 +573,7 @@ virCgroupSetValueI64(virCgroupPtr group, { g_autofree char *strval = NULL; - virAsprintf(&strval, "%lld", value); + strval = g_strdup_printf("%lld", value); return virCgroupSetValueStr(group, controller, key, strval); } @@ -676,8 +676,8 @@ virCgroupNew(pid_t pid, if (path[0] == '/' || !parent) { (*group)->path = g_strdup(path); } else { - virAsprintf(&(*group)->path, "%s%s%s", parent->path, - STREQ(parent->path, "") ? "" : "/", path); + (*group)->path = g_strdup_printf("%s%s%s", parent->path, + STREQ(parent->path, "") ? "" : "/", path); } if (virCgroupDetect(*group, pid, controllers, path, parent) < 0) @@ -909,7 +909,7 @@ virCgroupNewDomainPartition(virCgroupPtr partition, { g_autofree char *grpname = NULL; - virAsprintf(&grpname, "%s.libvirt-%s", name, driver); + grpname = g_strdup_printf("%s.libvirt-%s", name, driver); if (virCgroupPartitionEscape(&grpname) < 0) return -1; @@ -960,13 +960,13 @@ virCgroupNewThread(virCgroupPtr domain, switch (nameval) { case VIR_CGROUP_THREAD_VCPU: - virAsprintf(&name, "vcpu%d", id); + name = g_strdup_printf("vcpu%d", id); break; case VIR_CGROUP_THREAD_EMULATOR: name = g_strdup("emulator"); break; case VIR_CGROUP_THREAD_IOTHREAD: - virAsprintf(&name, "iothread%d", id); + name = g_strdup_printf("iothread%d", id); break; case VIR_CGROUP_THREAD_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2343,7 +2343,7 @@ virCgroupRemoveRecursively(char *grppath) if (ent->d_type != DT_DIR) continue; - virAsprintf(&path, "%s/%s", grppath, ent->d_name); + path = g_strdup_printf("%s/%s", grppath, ent->d_name); rc = virCgroupRemoveRecursively(path); if (rc != 0) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index d04fa521fc..334e6697df 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -97,13 +97,13 @@ virCgroupV1ValidateMachineGroup(virCgroupPtr group, g_autofree char *scopename_new = NULL; g_autofree char *partmachinename = NULL; - virAsprintf(&partname, "%s.libvirt-%s", name, drivername); + partname = g_strdup_printf("%s.libvirt-%s", name, drivername); if (virCgroupPartitionEscape(&partname) < 0) return false; - virAsprintf(&partmachinename, "%s.libvirt-%s", - machinename, drivername); + partmachinename = g_strdup_printf("%s.libvirt-%s", + machinename, drivername); if (virCgroupPartitionEscape(&partmachinename) < 0) return false; @@ -203,10 +203,10 @@ virCgroupV1CopyPlacement(virCgroupPtr group, * parent == "/libvirt.service" + path == "" => "/libvirt.service" * parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo" */ - virAsprintf(&group->legacy[i].placement, "%s%s%s", - parent->legacy[i].placement, - (STREQ(parent->legacy[i].placement, "/") || STREQ(path, "") ? "" : "/"), - path); + group->legacy[i].placement = g_strdup_printf("%s%s%s", + parent->legacy[i].placement, + (STREQ(parent->legacy[i].placement, "/") || STREQ(path, "") ? "" : "/"), + path); } } @@ -237,7 +237,7 @@ virCgroupV1ResolveMountLink(const char *mntDir, return 0; *dirName = '\0'; - virAsprintf(&linkSrc, "%s/%s", tmp, typeStr); + linkSrc = g_strdup_printf("%s/%s", tmp, typeStr); *dirName = '/'; if (lstat(linkSrc, &sb) < 0) { @@ -349,9 +349,9 @@ virCgroupV1DetectPlacement(virCgroupPtr group, if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) { group->legacy[i].placement = g_strdup(selfpath); } else { - virAsprintf(&group->legacy[i].placement, "%s%s%s", selfpath, - (STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), - path); + group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath, + (STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), + path); } } } @@ -516,8 +516,8 @@ virCgroupV1PathOfController(virCgroupPtr group, return -1; } - virAsprintf(path, "%s%s/%s", group->legacy[controller].mountPoint, - group->legacy[controller].placement, NULLSTR_EMPTY(key)); + *path = g_strdup_printf("%s%s/%s", group->legacy[controller].mountPoint, + group->legacy[controller].placement, NULLSTR_EMPTY(key)); return 0; } @@ -806,7 +806,7 @@ virCgroupV1BindMount(virCgroupPtr group, return -1; } - virAsprintf(&opts, "mode=755,size=65536%s", mountopts); + 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, @@ -821,7 +821,7 @@ virCgroupV1BindMount(virCgroupPtr group, if (!virFileExists(group->legacy[i].mountPoint)) { g_autofree char *src = NULL; - virAsprintf(&src, "%s%s", oldroot, group->legacy[i].mountPoint); + src = g_strdup_printf("%s%s", oldroot, group->legacy[i].mountPoint); VIR_DEBUG("Create mount point '%s'", group->legacy[i].mountPoint); @@ -881,8 +881,8 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, if (!cgroup->legacy[i].mountPoint) continue; - virAsprintf(&base, "%s%s", cgroup->legacy[i].mountPoint, - cgroup->legacy[i].placement); + base = g_strdup_printf("%s%s", cgroup->legacy[i].mountPoint, + cgroup->legacy[i].placement); if (virDirOpen(&dh, base) < 0) goto cleanup; @@ -890,7 +890,7 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, while ((direrr = virDirRead(dh, &de, base)) > 0) { g_autofree char *entry = NULL; - virAsprintf(&entry, "%s/%s", base, de->d_name); + entry = g_strdup_printf("%s/%s", base, de->d_name); if (chown(entry, uid, gid) < 0) { virReportSystemError(errno, @@ -947,7 +947,7 @@ virCgroupV1SetBlkioWeight(virCgroupPtr group, return -1; } - virAsprintf(&value, "%u", weight); + value = g_strdup_printf("%u", weight); return virCgroupSetValueRaw(path, value); } @@ -1189,7 +1189,7 @@ virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group, if (!(blkstr = virCgroupGetBlockDevString(devPath))) return -1; - virAsprintf(&str, "%s%d", blkstr, weight); + str = g_strdup_printf("%s%d", blkstr, weight); if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.weight_device", &path) < 0) { @@ -1256,7 +1256,7 @@ virCgroupV1SetBlkioDeviceReadIops(virCgroupPtr group, if (!(blkstr = virCgroupGetBlockDevString(path))) return -1; - virAsprintf(&str, "%s%u", blkstr, riops); + str = g_strdup_printf("%s%u", blkstr, riops); return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, @@ -1307,7 +1307,7 @@ virCgroupV1SetBlkioDeviceWriteIops(virCgroupPtr group, if (!(blkstr = virCgroupGetBlockDevString(path))) return -1; - virAsprintf(&str, "%s%u", blkstr, wiops); + str = g_strdup_printf("%s%u", blkstr, wiops); return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, @@ -1358,7 +1358,7 @@ virCgroupV1SetBlkioDeviceReadBps(virCgroupPtr group, if (!(blkstr = virCgroupGetBlockDevString(path))) return -1; - virAsprintf(&str, "%s%llu", blkstr, rbps); + str = g_strdup_printf("%s%llu", blkstr, rbps); return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, @@ -1409,7 +1409,7 @@ virCgroupV1SetBlkioDeviceWriteBps(virCgroupPtr group, if (!(blkstr = virCgroupGetBlockDevString(path))) return -1; - virAsprintf(&str, "%s%llu", blkstr, wbps); + str = g_strdup_printf("%s%llu", blkstr, wbps); return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, @@ -1761,15 +1761,15 @@ virCgroupV1AllowDevice(virCgroupPtr group, if (major < 0) majorstr = g_strdup("*"); else - virAsprintf(&majorstr, "%i", major); + majorstr = g_strdup_printf("%i", major); if (minor < 0) minorstr = g_strdup("*"); else - virAsprintf(&minorstr, "%i", minor); + minorstr = g_strdup_printf("%i", minor); - virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, - virCgroupGetDevicePermsString(perms)); + devstr = g_strdup_printf("%c %s:%s %s", type, majorstr, minorstr, + virCgroupGetDevicePermsString(perms)); if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_DEVICES, @@ -1795,15 +1795,15 @@ virCgroupV1DenyDevice(virCgroupPtr group, if (major < 0) majorstr = g_strdup("*"); else - virAsprintf(&majorstr, "%i", major); + majorstr = g_strdup_printf("%i", major); if (minor < 0) minorstr = g_strdup("*"); else - virAsprintf(&minorstr, "%i", minor); + minorstr = g_strdup_printf("%i", minor); - virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, - virCgroupGetDevicePermsString(perms)); + devstr = g_strdup_printf("%c %s:%s %s", type, majorstr, minorstr, + virCgroupGetDevicePermsString(perms)); if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_DEVICES, diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index f0ce4a48bc..d3374b6094 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -75,7 +75,7 @@ virCgroupV2Available(void) /* Systemd uses cgroup v2 for process tracking but no controller is * available. We should consider this configuration as cgroup v2 is * not available. */ - virAsprintf(&contFile, "%s/cgroup.controllers", entry.mnt_dir); + contFile = g_strdup_printf("%s/cgroup.controllers", entry.mnt_dir); if (virFileReadAll(contFile, 1024 * 1024, &contStr) < 0) goto cleanup; @@ -103,7 +103,7 @@ virCgroupV2ValidateMachineGroup(virCgroupPtr group, g_autofree char *scopename = NULL; char *tmp; - virAsprintf(&partmachinename, "%s.libvirt-%s", machinename, drivername); + partmachinename = g_strdup_printf("%s.libvirt-%s", machinename, drivername); if (virCgroupPartitionEscape(&partmachinename) < 0) return false; @@ -162,10 +162,10 @@ virCgroupV2CopyPlacement(virCgroupPtr group, * parent == "/libvirt.service" + path == "" => "/libvirt.service" * parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo" */ - virAsprintf(&group->unified.placement, "%s%s%s", - parent->unified.placement, - (STREQ(parent->unified.placement, "/") || STREQ(path, "") ? "" : "/"), - path); + group->unified.placement = g_strdup_printf("%s%s%s", + parent->unified.placement, + (STREQ(parent->unified.placement, "/") || STREQ(path, "") ? "" : "/"), + path); } return 0; @@ -209,8 +209,8 @@ virCgroupV2DetectPlacement(virCgroupPtr group, * selfpath == "/libvirt.service" + path == "" -> "/libvirt.service" * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo" */ - virAsprintf(&group->unified.placement, "%s%s%s", selfpath, - (STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), path); + group->unified.placement = g_strdup_printf("%s%s%s", selfpath, + (STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), path); return 0; } @@ -252,13 +252,13 @@ virCgroupV2ParseControllersFile(virCgroupPtr group, char **tmp; if (parent) { - virAsprintf(&contFile, "%s%s/cgroup.subtree_control", - parent->unified.mountPoint, - NULLSTR_EMPTY(parent->unified.placement)); + contFile = g_strdup_printf("%s%s/cgroup.subtree_control", + parent->unified.mountPoint, + NULLSTR_EMPTY(parent->unified.placement)); } else { - virAsprintf(&contFile, "%s%s/cgroup.controllers", - group->unified.mountPoint, - NULLSTR_EMPTY(group->unified.placement)); + contFile = g_strdup_printf("%s%s/cgroup.controllers", + group->unified.mountPoint, + NULLSTR_EMPTY(group->unified.placement)); } rc = virFileReadAll(contFile, 1024 * 1024, &contStr); @@ -345,8 +345,8 @@ virCgroupV2PathOfController(virCgroupPtr group, return -1; } - virAsprintf(path, "%s%s/%s", group->unified.mountPoint, - group->unified.placement, NULLSTR_EMPTY(key)); + *path = g_strdup_printf("%s%s/%s", group->unified.mountPoint, + group->unified.placement, NULLSTR_EMPTY(key)); return 0; } @@ -368,7 +368,7 @@ virCgroupV2EnableController(virCgroupPtr group, g_autofree char *val = NULL; g_autofree char *path = NULL; - virAsprintf(&val, "+%s", virCgroupV2ControllerTypeToString(controller)); + val = g_strdup_printf("+%s", virCgroupV2ControllerTypeToString(controller)); if (virCgroupPathOfController(parent, controller, "cgroup.subtree_control", &path) < 0) { @@ -550,9 +550,9 @@ virCgroupV2BindMount(virCgroupPtr group, return -1; } - virAsprintf(&opts, "mode=755,size=65536%s", mountopts); + opts = g_strdup_printf("mode=755,size=65536%s", mountopts); - virAsprintf(&src, "%s%s", oldroot, group->unified.mountPoint); + 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'"), @@ -572,8 +572,8 @@ virCgroupV2SetOwner(virCgroupPtr cgroup, { g_autofree char *base = NULL; - virAsprintf(&base, "%s%s", cgroup->unified.mountPoint, - cgroup->unified.placement); + base = g_strdup_printf("%s%s", cgroup->unified.mountPoint, + cgroup->unified.placement); if (virFileChownFiles(base, uid, gid) < 0) return -1; @@ -617,7 +617,7 @@ virCgroupV2SetBlkioWeight(virCgroupPtr group, return -1; } - virAsprintf(&value, format, weight); + value = g_strdup_printf(format, weight); return virCgroupSetValueRaw(path, value); } @@ -810,7 +810,7 @@ virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group, if (!(blkstr = virCgroupGetBlockDevString(devPath))) return -1; - virAsprintf(&str, "%s%d", blkstr, weight); + str = g_strdup_printf("%s%d", blkstr, weight); if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, "io.weight", &path) < 0) { @@ -879,9 +879,9 @@ virCgroupV2SetBlkioDeviceReadIops(virCgroupPtr group, return -1; if (riops == 0) { - virAsprintf(&str, "%sriops=max", blkstr); + str = g_strdup_printf("%sriops=max", blkstr); } else { - virAsprintf(&str, "%sriops=%u", blkstr, riops); + str = g_strdup_printf("%sriops=%u", blkstr, riops); } return virCgroupSetValueStr(group, @@ -948,9 +948,9 @@ virCgroupV2SetBlkioDeviceWriteIops(virCgroupPtr group, return -1; if (wiops == 0) { - virAsprintf(&str, "%swiops=max", blkstr); + str = g_strdup_printf("%swiops=max", blkstr); } else { - virAsprintf(&str, "%swiops=%u", blkstr, wiops); + str = g_strdup_printf("%swiops=%u", blkstr, wiops); } return virCgroupSetValueStr(group, @@ -1017,9 +1017,9 @@ virCgroupV2SetBlkioDeviceReadBps(virCgroupPtr group, return -1; if (rbps == 0) { - virAsprintf(&str, "%srbps=max", blkstr); + str = g_strdup_printf("%srbps=max", blkstr); } else { - virAsprintf(&str, "%srbps=%llu", blkstr, rbps); + str = g_strdup_printf("%srbps=%llu", blkstr, rbps); } return virCgroupSetValueStr(group, @@ -1086,9 +1086,9 @@ virCgroupV2SetBlkioDeviceWriteBps(virCgroupPtr group, return -1; if (wbps == 0) { - virAsprintf(&str, "%swbps=max", blkstr); + str = g_strdup_printf("%swbps=max", blkstr); } else { - virAsprintf(&str, "%swbps=%llu", blkstr, wbps); + str = g_strdup_printf("%swbps=%llu", blkstr, wbps); } return virCgroupSetValueStr(group, @@ -1488,7 +1488,7 @@ virCgroupV2SetCpuCfsPeriod(virCgroupPtr group, } *tmp = '\0'; - virAsprintf(&value, "%s %llu", str, cfs_period); + value = g_strdup_printf("%s %llu", str, cfs_period); return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPU, "cpu.max", value); diff --git a/src/util/virconf.c b/src/util/virconf.c index d4071d1945..6238b28dd9 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -1520,13 +1520,13 @@ virConfLoadConfigPath(const char *name) { char *path; if (geteuid() == 0) { - virAsprintf(&path, "%s/libvirt/%s", SYSCONFDIR, name); + path = g_strdup_printf("%s/libvirt/%s", SYSCONFDIR, name); } else { char *userdir = virGetUserConfigDirectory(); if (!userdir) return NULL; - virAsprintf(&path, "%s/%s", userdir, name); + path = g_strdup_printf("%s/%s", userdir, name); VIR_FREE(userdir); } diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 4f29f74c77..cc6a099faa 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -127,9 +127,9 @@ virDevMapperGetTargetsImpl(const char *path, goto cleanup; for (i = 0; i < deps->count; i++) { - virAsprintf(&devPaths[i], "/dev/block/%u:%u", - major(deps->device[i]), - minor(deps->device[i])); + devPaths[i] = g_strdup_printf("/dev/block/%u:%u", + major(deps->device[i]), + minor(deps->device[i])); } recursiveDevPaths = NULL; diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index a93c851f7d..12c51875b2 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -180,7 +180,7 @@ addnhostsWrite(const char *path, * for runtime addition. */ - virAsprintf(&tmp, "%s.new", path); + tmp = g_strdup_printf("%s.new", path); if (!(f = fopen(tmp, "w"))) { istmp = false; @@ -311,24 +311,24 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, /* the first test determines if it is a dhcpv6 host */ if (ipv6) { if (name && id) { - virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, - "id:%s,%s,[%s]", id, name, ipstr); + hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf( + "id:%s,%s,[%s]", id, name, ipstr); } else if (name && !id) { - virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,[%s]", - name, ipstr); + hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,[%s]", + name, ipstr); } else if (!name && id) { - virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, - "id:%s,[%s]", id, ipstr); + hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf( + "id:%s,[%s]", id, ipstr); } } else if (name && mac) { - virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,%s", - mac, ipstr, name); + hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s,%s", + mac, ipstr, name); } else if (name && !mac) { - virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", name, - ipstr); + hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s", name, + ipstr); } else { - virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", mac, - ipstr); + hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s", mac, + ipstr); } VIR_FREE(ipstr); @@ -386,7 +386,7 @@ hostsfileWrite(const char *path, * for runtime addition. */ - virAsprintf(&tmp, "%s.new", path); + tmp = g_strdup_printf("%s.new", path); if (!(f = fopen(tmp, "w"))) { istmp = false; @@ -750,7 +750,7 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force) if (virCommandRun(cmd, NULL) < 0) goto cleanup; - virAsprintf(&complete, "%s\n%s", version, help); + complete = g_strdup_printf("%s\n%s", version, help); ret = dnsmasqCapsSetFromBuffer(caps, complete); diff --git a/src/util/virebtables.c b/src/util/virebtables.c index 9f4ba9013e..14a922834a 100644 --- a/src/util/virebtables.c +++ b/src/util/virebtables.c @@ -58,7 +58,7 @@ ebtablesContextNew(const char *driver) if (VIR_ALLOC(ctx) < 0) return NULL; - virAsprintf(&ctx->chain, "libvirt_%s_FORWARD", driver); + ctx->chain = g_strdup_printf("libvirt_%s_FORWARD", driver); return ctx; } diff --git a/src/util/virerror.c b/src/util/virerror.c index ee0ec1cffc..76a75e27a8 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1488,7 +1488,7 @@ virLastErrorPrefixMessage(const char *fmt, ...) if (virVasprintfQuiet(&fmtmsg, fmt, args) < 0) goto cleanup; - virAsprintf(&newmsg, "%s: %s", fmtmsg, err->message); + newmsg = g_strdup_printf("%s: %s", fmtmsg, err->message); VIR_FREE(err->message); err->message = g_steal_pointer(&newmsg); diff --git a/src/util/virfile.c b/src/util/virfile.c index 0636fb8f08..042847137d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -508,7 +508,7 @@ virFileRewrite(const char *path, int fd = -1; int ret = -1; - virAsprintf(&newfile, "%s.new", path); + 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'"), @@ -665,7 +665,7 @@ static int virFileLoopDeviceOpenLoopCtl(char **dev_name, int *fd) VIR_DEBUG("Found free loop device number %i", devnr); - virAsprintf(&looppath, "/dev/loop%i", devnr); + looppath = g_strdup_printf("/dev/loop%i", devnr); if ((*fd = open(looppath, O_RDWR)) < 0) { virReportSystemError(errno, @@ -701,7 +701,7 @@ static int virFileLoopDeviceOpenSearch(char **dev_name) !c_isdigit(de->d_name[4])) continue; - virAsprintf(&looppath, "/dev/%s", de->d_name); + looppath = g_strdup_printf("/dev/%s", de->d_name); VIR_DEBUG("Checking up on device %s", looppath); if ((fd = open(looppath, O_RDWR)) < 0) { @@ -831,7 +831,7 @@ virFileNBDDeviceIsBusy(const char *dev_name) { g_autofree char *path = NULL; - virAsprintf(&path, SYSFS_BLOCK_DIR "/%s/pid", dev_name); + path = g_strdup_printf(SYSFS_BLOCK_DIR "/%s/pid", dev_name); if (!virFileExists(path)) { if (errno == ENOENT) @@ -863,7 +863,7 @@ virFileNBDDeviceFindUnused(void) if (rv < 0) goto cleanup; if (rv == 0) { - virAsprintf(&ret, "/dev/%s", de->d_name); + ret = g_strdup_printf("/dev/%s", de->d_name); goto cleanup; } } @@ -1008,7 +1008,7 @@ int virFileDeleteTree(const char *dir) g_autofree char *filepath = NULL; struct stat sb; - virAsprintf(&filepath, "%s/%s", dir, de->d_name); + filepath = g_strdup_printf("%s/%s", dir, de->d_name); if (lstat(filepath, &sb) < 0) { virReportSystemError(errno, _("Cannot access '%s'"), @@ -1549,7 +1549,7 @@ virFileRelLinkPointsTo(const char *directory, checkLink); return -1; } - virAsprintf(&candidate, "%s/%s", directory, checkLink); + candidate = g_strdup_printf("%s/%s", directory, checkLink); return virFileLinkPointsTo(candidate, checkDest); } @@ -1685,7 +1685,7 @@ virFindFileInPath(const char *file) */ pathiter = path; while ((pathseg = strsep(&pathiter, ":")) != NULL) { - virAsprintf(&fullpath, "%s/%s", pathseg, file); + fullpath = g_strdup_printf("%s/%s", pathseg, file); if (virFileIsExecutable(fullpath)) break; VIR_FREE(fullpath); @@ -1749,7 +1749,7 @@ virFileFindResourceFull(const char *filename, else path = installdir; - virAsprintf(&ret, "%s/%s%s%s", path, prefix, filename, suffix); + ret = g_strdup_printf("%s/%s%s%s", path, prefix, filename, suffix); VIR_DEBUG("Resolved '%s' to '%s'", filename, ret); return ret; @@ -2976,7 +2976,7 @@ int virFileChownFiles(const char *name, while ((direrr = virDirRead(dir, &ent, name)) > 0) { g_autofree char *path = NULL; - virAsprintf(&path, "%s/%s", name, ent->d_name); + path = g_strdup_printf("%s/%s", name, ent->d_name); if (!virFileIsRegular(path)) continue; @@ -3093,9 +3093,9 @@ virFileBuildPath(const char *dir, const char *name, const char *ext) char *path; if (ext == NULL) { - virAsprintf(&path, "%s/%s", dir, name); + path = g_strdup_printf("%s/%s", dir, name); } else { - virAsprintf(&path, "%s/%s%s", dir, name, ext); + path = g_strdup_printf("%s/%s%s", dir, name, ext); } return path; @@ -3283,7 +3283,7 @@ virFileAbsPath(const char *path, char **abspath) if (buf == NULL) return -1; - virAsprintf(abspath, "%s/%s", buf, path); + *abspath = g_strdup_printf("%s/%s", buf, path); } return 0; diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 26b2fdc17f..90543dcb00 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -627,7 +627,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, /* OK, we've parsed clock speed out of /proc/cpuinfo. Get the * core, node, socket, thread and topology information from /sys */ - virAsprintf(&sysfs_nodedir, "%s/node", SYSFS_SYSTEM_PATH); + 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 */ @@ -670,8 +670,8 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, (*nodes)++; - virAsprintf(&sysfs_cpudir, "%s/node/%s", SYSFS_SYSTEM_PATH, - nodedirent->d_name); + sysfs_cpudir = g_strdup_printf("%s/node/%s", SYSFS_SYSTEM_PATH, + nodedirent->d_name); if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch, present_cpus_map, @@ -704,7 +704,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, fallback: VIR_FREE(sysfs_cpudir); - virAsprintf(&sysfs_cpudir, "%s/cpu", SYSFS_SYSTEM_PATH); + sysfs_cpudir = g_strdup_printf("%s/cpu", SYSFS_SYSTEM_PATH); if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch, present_cpus_map, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index ab40c5faaa..ee05bc248c 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -184,7 +184,7 @@ virHostdevManagerNew(void) if (!(rundir = virGetUserRuntimeDirectory())) return NULL; - virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir); + hostdevMgr->stateDir = g_strdup_printf("%s/hostdevmgr", rundir); old_umask = umask(077); diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index 0d57d47529..61bca450e6 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -280,8 +280,8 @@ virHostMemGetStats(int cellNum G_GNUC_UNUSED, return -1; } - virAsprintf(&meminfo_path, - SYSFS_SYSTEM_PATH "/node/node%d/meminfo", cellNum); + meminfo_path = g_strdup_printf( + SYSFS_SYSTEM_PATH "/node/node%d/meminfo", cellNum); } meminfo = fopen(meminfo_path, "r"); @@ -316,9 +316,9 @@ virHostMemSetParameterValue(virTypedParameterPtr param) char *field = strchr(param->field, '_'); sa_assert(field); field++; - virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field); + path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field); - virAsprintf(&strval, "%u", param->value.ui); + strval = g_strdup_printf("%u", param->value.ui); if ((rc = virFileWriteStr(path, strval, 0)) < 0) { virReportSystemError(-rc, _("failed to set %s"), param->field); @@ -341,7 +341,7 @@ virHostMemParametersAreAllSupported(virTypedParameterPtr params, char *field = strchr(param->field, '_'); sa_assert(field); field++; - virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field); + path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field); if (!virFileExists(path)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -405,7 +405,7 @@ virHostMemGetParameterValue(const char *field, char *tmp = NULL; int rc = -1; - virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field); + path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field); if (!virFileExists(path)) return -2; diff --git a/src/util/viriptables.c b/src/util/viriptables.c index c8c4d98f30..b7cce40d37 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -401,7 +401,7 @@ static char *iptablesFormatNetwork(virSocketAddr *netaddr, if (!netstr) return NULL; - virAsprintf(&ret, "%s/%d", netstr, prefix); + ret = g_strdup_printf("%s/%d", netstr, prefix); return ret; } @@ -905,7 +905,7 @@ iptablesForwardMasquerade(virFirewallPtr fw, } if (port->start < port->end && port->end < 65536) { - virAsprintf(&portRangeStr, ":%u-%u", port->start, port->end); + portRangeStr = g_strdup_printf(":%u-%u", port->start, port->end); } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid port range '%u-%u'."), @@ -917,11 +917,11 @@ iptablesForwardMasquerade(virFirewallPtr fw, /* Use --jump SNAT if public addr is specified */ if (addrStartStr && addrStartStr[0]) { if (addrEndStr && addrEndStr[0]) { - virAsprintf(&natRangeStr, "%s-%s%s", addrStartStr, addrEndStr, - portRangeStr ? portRangeStr : ""); + natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr, + portRangeStr ? portRangeStr : ""); } else { - virAsprintf(&natRangeStr, "%s%s", addrStartStr, - portRangeStr ? portRangeStr : ""); + natRangeStr = g_strdup_printf("%s%s", addrStartStr, + portRangeStr ? portRangeStr : ""); } virFirewallRuleAddArgList(fw, rule, diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 55a30470d6..9f4c8f4e03 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -213,8 +213,8 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn, g_autofree char *temp_ifacename = NULL; g_autoptr(virCommand) cmd = NULL; - virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", - (unsigned long long)virRandomBits(32)); + 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); diff --git a/src/util/virjson.c b/src/util/virjson.c index ec8d706edd..7ab8f4b52a 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -497,7 +497,7 @@ virJSONValuePtr virJSONValueNewNumberInt(int data) { g_autofree char *str = NULL; - virAsprintf(&str, "%i", data); + str = g_strdup_printf("%i", data); return virJSONValueNewNumber(str); } @@ -506,7 +506,7 @@ virJSONValuePtr virJSONValueNewNumberUint(unsigned int data) { g_autofree char *str = NULL; - virAsprintf(&str, "%u", data); + str = g_strdup_printf("%u", data); return virJSONValueNewNumber(str); } @@ -515,7 +515,7 @@ virJSONValuePtr virJSONValueNewNumberLong(long long data) { g_autofree char *str = NULL; - virAsprintf(&str, "%lld", data); + str = g_strdup_printf("%lld", data); return virJSONValueNewNumber(str); } @@ -524,7 +524,7 @@ virJSONValuePtr virJSONValueNewNumberUlong(unsigned long long data) { g_autofree char *str = NULL; - virAsprintf(&str, "%llu", data); + str = g_strdup_printf("%llu", data); return virJSONValueNewNumber(str); } diff --git a/src/util/virkmod.c b/src/util/virkmod.c index 12e6e5676c..12cb5920e8 100644 --- a/src/util/virkmod.c +++ b/src/util/virkmod.c @@ -149,7 +149,7 @@ virKModIsBlacklisted(const char *module) g_autofree char *drvblklst = NULL; g_autofree char *outbuf = NULL; - virAsprintf(&drvblklst, "blacklist %s\n", module); + 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++) diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 30868035a9..b7e1b6cfda 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -67,7 +67,7 @@ static char *virLockSpaceGetResourcePath(virLockSpacePtr lockspace, { char *ret; if (lockspace->dir) - virAsprintf(&ret, "%s/%s", lockspace->dir, resname); + ret = g_strdup_printf("%s/%s", lockspace->dir, resname); else ret = g_strdup(resname); return ret; diff --git a/src/util/virlog.c b/src/util/virlog.c index 880539e5c0..e7d62e3948 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -152,8 +152,8 @@ virLogUnlock(void) static void virLogSetDefaultOutputToStderr(void) { - virAsprintf(&virLogDefaultOutput, "%d:stderr", - virLogDefaultPriority); + virLogDefaultOutput = g_strdup_printf("%d:stderr", + virLogDefaultPriority); } @@ -167,7 +167,7 @@ virLogSetDefaultOutputToJournald(void) if (priority == VIR_LOG_DEBUG) priority = VIR_LOG_INFO; - virAsprintf(&virLogDefaultOutput, "%d:journald", priority); + virLogDefaultOutput = g_strdup_printf("%d:journald", priority); } @@ -179,8 +179,8 @@ virLogSetDefaultOutputToFile(const char *binary, bool privileged) mode_t old_umask; if (privileged) { - virAsprintf(&virLogDefaultOutput, "%d:file:%s/log/libvirt/%s.log", - virLogDefaultPriority, LOCALSTATEDIR, binary); + virLogDefaultOutput = g_strdup_printf("%d:file:%s/log/libvirt/%s.log", + virLogDefaultPriority, LOCALSTATEDIR, binary); } else { if (!(logdir = virGetUserCacheDirectory())) goto cleanup; @@ -192,8 +192,8 @@ virLogSetDefaultOutputToFile(const char *binary, bool privileged) } umask(old_umask); - virAsprintf(&virLogDefaultOutput, "%d:file:%s/%s.log", - virLogDefaultPriority, logdir, binary); + virLogDefaultOutput = g_strdup_printf("%d:file:%s/%s.log", + virLogDefaultPriority, logdir, binary); } ret = 0; @@ -453,13 +453,13 @@ virLogFormatString(char **msg, * to just grep for it to find the right place. */ if ((funcname != NULL)) { - virAsprintf(msg, "%llu: %s : %s:%d : %s\n", - virThreadSelfID(), virLogPriorityString(priority), - funcname, linenr, str); + *msg = g_strdup_printf("%llu: %s : %s:%d : %s\n", + virThreadSelfID(), virLogPriorityString(priority), + funcname, linenr, str); } else { - virAsprintf(msg, "%llu: %s : %s\n", - virThreadSelfID(), virLogPriorityString(priority), - str); + *msg = g_strdup_printf("%llu: %s : %s\n", + virThreadSelfID(), virLogPriorityString(priority), + str); } } @@ -481,7 +481,7 @@ virLogHostnameString(char **rawmsg, { char *hoststr; - virAsprintf(&hoststr, "hostname: %s", virLogHostname); + hoststr = g_strdup_printf("hostname: %s", virLogHostname); virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr); *rawmsg = hoststr; @@ -689,7 +689,7 @@ virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED, if (fd < 0) return; - virAsprintf(&msg, "%s: %s", timestamp, str); + msg = g_strdup_printf("%s: %s", timestamp, str); ignore_value(safewrite(fd, msg, strlen(msg))); VIR_FREE(msg); } diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index c515e3e7b0..b38ae8ac43 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -290,7 +290,7 @@ virMacMapFileName(const char *dnsmasqStateDir, { char *filename; - virAsprintf(&filename, "%s/%s.macs", dnsmasqStateDir, bridge); + filename = g_strdup_printf("%s/%s.macs", dnsmasqStateDir, bridge); return filename; } diff --git a/src/util/virmdev.c b/src/util/virmdev.c index c5fd4ad42f..545069cfaa 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -80,7 +80,7 @@ virMediatedDeviceGetSysfsDeviceAPI(virMediatedDevicePtr dev, g_autofree char *file = NULL; char *tmp = NULL; - virAsprintf(&file, "%s/mdev_type/device_api", dev->path); + 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 @@ -217,7 +217,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) if (!dev_path) return NULL; - virAsprintf(&iommu_path, "%s/iommu_group", dev_path); + iommu_path = g_strdup_printf("%s/iommu_group", dev_path); if (!virFileExists(iommu_path)) { virReportSystemError(errno, _("failed to access '%s'"), iommu_path); @@ -229,7 +229,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) return NULL; } - virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path)); + vfio_path = g_strdup_printf("/dev/vfio/%s", last_component(result_path)); return vfio_path; } @@ -425,7 +425,7 @@ virMediatedDeviceGetSysfsPath(const char *uuidstr) { char *ret = NULL; - virAsprintf(&ret, MDEV_SYSFS_DEVICES "%s", uuidstr); + ret = g_strdup_printf(MDEV_SYSFS_DEVICES "%s", uuidstr); return ret; } diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 20f7ef5428..9b2741bc28 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -511,7 +511,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs) char *phy_path = NULL; int len; - virAsprintf(&pid, "%lld", (long long) pidInNs); + 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) @@ -1068,7 +1068,7 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname, const char *file) { - virAsprintf(pf_sysfs_device_link, SYSFS_NET_DIR "%s/%s", ifname, file); + *pf_sysfs_device_link = g_strdup_printf(SYSFS_NET_DIR "%s/%s", ifname, file); return 0; } @@ -1076,8 +1076,8 @@ static int virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname, const char *file) { - virAsprintf(pf_sysfs_device_link, SYSFS_NET_DIR "%s/device/%s", ifname, - file); + *pf_sysfs_device_link = g_strdup_printf(SYSFS_NET_DIR "%s/device/%s", ifname, + file); return 0; } @@ -1099,7 +1099,7 @@ virNetDevIsPCIDevice(const char *devpath) char *subsys = NULL; bool ret = false; - virAsprintf(&subsys_link, "%s/subsystem", devpath); + subsys_link = g_strdup_printf("%s/subsystem", devpath); if (!virFileExists(subsys_link)) goto cleanup; @@ -1400,7 +1400,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **vfname) if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) goto cleanup; - virAsprintf(&virtfnName, "virtfn%d", vf); + 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" @@ -1888,7 +1888,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, */ if (pfDevName && saveVlan) { - virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf); + filePath = g_strdup_printf("%s/%s_vf%d", stateDir, pfDevName, vf); /* get admin MAC and vlan tag */ if (virNetDevGetVfConfig(pfDevName, vf, &oldMAC, &oldVlanTag) < 0) @@ -1904,7 +1904,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, } } else { - virAsprintf(&filePath, "%s/%s", stateDir, linkdev); + filePath = g_strdup_printf("%s/%s", stateDir, linkdev); } if (linkdev) { @@ -2009,7 +2009,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, */ if (pfDevName) { - virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf); + 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 @@ -2023,7 +2023,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, } if (!pfDevName) - virAsprintf(&filePath, "%s/%s", stateDir, linkdev); + filePath = g_strdup_printf("%s/%s", stateDir, linkdev); if (!virFileExists(filePath)) { /* having no file to read is not necessarily an error, so we @@ -2903,7 +2903,7 @@ virNetDevRDMAFeature(const char *ifname, if (virDirOpen(&dirp, SYSFS_INFINIBAND_DIR) < 0) return -1; - virAsprintf(ð_devpath, SYSFS_NET_DIR "%s/device/resource", ifname); + 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. */ @@ -2916,8 +2916,8 @@ virNetDevRDMAFeature(const char *ifname, goto cleanup; while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) { - virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resource", - dp->d_name); + 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)); diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index b7e0c0c7c1..1f1872464a 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -114,7 +114,7 @@ virNetDevBandwidthManipulateFilter(const char *ifname, } /* u32 filters must have 800:: prefix. Don't ask. */ - virAsprintf(&filter_id, "800::%u", id); + filter_id = g_strdup_printf("800::%u", id); if (remove_old) { int cmd_ret = 0; @@ -131,9 +131,9 @@ virNetDevBandwidthManipulateFilter(const char *ifname, if (create_new) { virMacAddrGetRaw(ifmac_ptr, ifmac); - virAsprintf(&mac[0], "0x%02x%02x%02x%02x", ifmac[2], - ifmac[3], ifmac[4], ifmac[5]); - virAsprintf(&mac[1], "0x%02x%02x", ifmac[0], ifmac[1]); + 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); @@ -230,11 +230,11 @@ virNetDevBandwidthSet(const char *ifname, virNetDevBandwidthClear(ifname); if (tx && tx->average) { - virAsprintf(&average, "%llukbps", tx->average); + average = g_strdup_printf("%llukbps", tx->average); if (tx->peak) - virAsprintf(&peak, "%llukbps", tx->peak); + peak = g_strdup_printf("%llukbps", tx->peak); if (tx->burst) - virAsprintf(&burst, "%llukb", tx->burst); + burst = g_strdup_printf("%llukb", tx->burst); cmd = virCommandNew(TC); virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname, "root", @@ -357,8 +357,8 @@ virNetDevBandwidthSet(const char *ifname, } if (rx) { - virAsprintf(&average, "%llukbps", rx->average); - virAsprintf(&burst, "%llukb", rx->burst ? rx->burst : rx->average); + average = g_strdup_printf("%llukbps", rx->average); + burst = g_strdup_printf("%llukb", rx->burst ? rx->burst : rx->average); virCommandFree(cmd); cmd = virCommandNew(TC); @@ -568,12 +568,12 @@ virNetDevBandwidthPlug(const char *brname, return -1; } - virAsprintf(&class_id, "1:%x", id); - virAsprintf(&qdisc_id, "%x:", id); - virAsprintf(&floor, "%llukbps", bandwidth->in->floor); - virAsprintf(&ceil, "%llukbps", net_bandwidth->in->peak ? - net_bandwidth->in->peak : - net_bandwidth->in->average); + 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", @@ -632,8 +632,8 @@ virNetDevBandwidthUnplug(const char *brname, return -1; } - virAsprintf(&class_id, "1:%x", id); - virAsprintf(&qdisc_id, "%x:", id); + class_id = g_strdup_printf("1:%x", id); + qdisc_id = g_strdup_printf("%x:", id); cmd = virCommandNew(TC); virCommandAddArgList(cmd, "qdisc", "del", "dev", brname, @@ -691,11 +691,11 @@ virNetDevBandwidthUpdateRate(const char *ifname, char *rate = NULL; char *ceil = NULL; - virAsprintf(&class_id, "1:%x", id); - virAsprintf(&rate, "%llukbps", new_rate); - virAsprintf(&ceil, "%llukbps", bandwidth->in->peak ? - bandwidth->in->peak : - bandwidth->in->average); + 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, @@ -741,7 +741,7 @@ virNetDevBandwidthUpdateFilter(const char *ifname, int ret = -1; char *class_id = NULL; - virAsprintf(&class_id, "1:%x", id); + class_id = g_strdup_printf("1:%x", id); if (virNetDevBandwidthManipulateFilter(ifname, ifmac_ptr, id, class_id, true, true) < 0) diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 0a0834be69..2cef3c0a2b 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -122,7 +122,7 @@ static int virNetDevBridgeSet(const char *brname, { g_autofree char *path = NULL; - virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname); + path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname); if (virFileExists(path)) { char valuestr[INT_BUFSIZE_BOUND(value)]; @@ -164,7 +164,7 @@ static int virNetDevBridgeGet(const char *brname, g_autofree char *path = NULL; VIR_AUTOCLOSE fd = -1; - virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname); + path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname); if (virFileExists(path)) { g_autofree char *valuestr = NULL; @@ -221,8 +221,8 @@ virNetDevBridgePortSet(const char *brname, snprintf(valuestr, sizeof(valuestr), "%lu", value); - virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, - paramname); + path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, + paramname); if (!virFileExists(path)) errno = EINVAL; @@ -248,8 +248,8 @@ virNetDevBridgePortGet(const char *brname, g_autofree char *path = NULL; g_autofree char *valuestr = NULL; - virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, - paramname); + 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; diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index 057e75e5e1..5696bc367e 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -487,8 +487,8 @@ virNetDevIPGetAcceptRA(const char *ifname) char *suffix; int accept_ra = -1; - virAsprintf(&path, "/proc/sys/net/ipv6/conf/%s/accept_ra", - ifname ? ifname : "all"); + 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)) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index 11fcb96400..cb901d7136 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -294,7 +294,7 @@ virNetDevMacVLanIsMacvtap(const char *ifname) if (virNetDevGetIndex(ifname, &ifindex) < 0) return false; - virAsprintf(&tapname, "/dev/tap%d", ifindex); + tapname = g_strdup_printf("/dev/tap%d", ifindex); return virFileExists(tapname); } @@ -392,7 +392,7 @@ virNetDevMacVLanTapOpen(const char *ifname, if (virNetDevGetIndex(ifname, &ifindex) < 0) return -1; - virAsprintf(&tapname, "/dev/tap%d", ifindex); + tapname = g_strdup_printf("/dev/tap%d", ifindex); for (i = 0; i < tapfdSize; i++) { int fd = -1; diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 9862e550b7..a864b34799 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -151,13 +151,13 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virUUIDFormat(ovsport->interfaceID, ifuuidstr); virUUIDFormat(vmuuid, vmuuidstr); - virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=\"%s\"", - macaddrstr); - virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"", ifuuidstr); - virAsprintf(&vmid_ex_id, "external-ids:vm-id=\"%s\"", vmuuidstr); + 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') { - virAsprintf(&profile_ex_id, "external-ids:port-profile=\"%s\"", - ovsport->profileID); + profile_ex_id = g_strdup_printf("external-ids:port-profile=\"%s\"", + ovsport->profileID); } cmd = virCommandNew(OVSVSCTL); diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 23f2882bc3..aea4c91a6a 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -395,7 +395,7 @@ int virNetDevTapCreate(char **ifname, for (i = 0; i <= IF_MAXUNIT; i++) { g_autofree char *newname = NULL; - virAsprintf(&newname, *ifname, i); + newname = g_strdup_printf(*ifname, i); if (virNetDevExists(newname) == 0) { newifname = g_steal_pointer(&newname); @@ -415,7 +415,7 @@ int virNetDevTapCreate(char **ifname, if (tapfd) { g_autofree char *dev_path = NULL; - virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name); + dev_path = g_strdup_printf("/dev/%s", ifr.ifr_name); if ((*tapfd = open(dev_path, O_RDWR)) < 0) { virReportSystemError(errno, diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 5e5074dd68..387017f2a8 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -44,7 +44,7 @@ static int virNetDevVethExists(int devNum) int ret; g_autofree char *path = NULL; - virAsprintf(&path, SYSFS_NET_DIR "vnet%d/", devNum); + 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; @@ -127,7 +127,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) if ((veth1num = virNetDevVethGetFreeNum(vethNum)) < 0) goto cleanup; - virAsprintf(&veth1auto, "vnet%d", veth1num); + veth1auto = g_strdup_printf("vnet%d", veth1num); vethNum = veth1num + 1; } if (!*veth2) { @@ -135,7 +135,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) if ((veth2num = virNetDevVethGetFreeNum(vethNum)) < 0) goto cleanup; - virAsprintf(&veth2auto, "vnet%d", veth2num); + veth2auto = g_strdup_printf("vnet%d", veth2num); vethNum = veth2num + 1; } diff --git a/src/util/virnuma.c b/src/util/virnuma.c index e6213df6da..61b9687291 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -540,15 +540,13 @@ virNumaGetHugePageInfoPath(char **path, { if (node == -1) { /* We are aiming at overall system info */ - 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 */ - 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 (!virFileExists(*path)) { @@ -580,9 +578,8 @@ virNumaGetHugePageInfoDir(char **path, int node) *path = g_strdup(HUGEPAGES_SYSTEM_PREFIX); return 0; } else { - virAsprintf(path, - HUGEPAGES_NUMA_PREFIX "node%d/hugepages/", - node); + *path = g_strdup_printf(HUGEPAGES_NUMA_PREFIX "node%d/hugepages/", + node); return 0; } } @@ -929,7 +926,7 @@ virNumaSetPagePoolSize(int node, * all the pages we wanted. So do the second read to check. */ VIR_FREE(nr_buf); - virAsprintf(&nr_buf, "%llu", page_count); + nr_buf = g_strdup_printf("%llu", page_count); if (virFileWriteStr(nr_path, nr_buf, 0) < 0) { virReportSystemError(errno, diff --git a/src/util/virpci.c b/src/util/virpci.c index 3ae13469bd..63580f3021 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -213,7 +213,7 @@ virPCIDriverDir(const char *driver) { char *buffer; - virAsprintf(&buffer, PCI_SYSFS "drivers/%s", driver); + buffer = g_strdup_printf(PCI_SYSFS "drivers/%s", driver); return buffer; } @@ -223,7 +223,7 @@ virPCIFile(const char *device, const char *file) { char *buffer; - virAsprintf(&buffer, PCI_SYSFS "devices/%s/%s", device, file); + buffer = g_strdup_printf(PCI_SYSFS "devices/%s/%s", device, file); return buffer; } @@ -604,7 +604,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd) * device is a VF, we just assume FLR works */ - virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name); + path = g_strdup_printf(PCI_SYSFS "devices/%s/physfn", dev->name); found = virFileExists(path); if (found) { @@ -1353,12 +1353,12 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr) { char *str; - 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; } @@ -1380,10 +1380,10 @@ virPCIDeviceNew(unsigned int domain, dev->address.slot = slot; dev->address.function = function; - virAsprintf(&dev->name, VIR_PCI_DEVICE_ADDRESS_FMT, domain, bus, slot, - function); + dev->name = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, domain, bus, slot, + function); - virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config", dev->name); + dev->path = g_strdup_printf(PCI_SYSFS "devices/%s/config", dev->name); if (!virFileExists(dev->path)) { virReportSystemError(errno, @@ -1728,9 +1728,9 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, struct dirent *ent; int direrr; - virAsprintf(&pcidir, "/sys/bus/pci/devices/" VIR_PCI_DEVICE_ADDRESS_FMT, - dev->address.domain, dev->address.bus, dev->address.slot, - dev->address.function); + 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; @@ -1747,7 +1747,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, STREQ(ent->d_name, "vendor") || STREQ(ent->d_name, "device") || STREQ(ent->d_name, "reset")) { - virAsprintf(&file, "%s/%s", pcidir, ent->d_name); + file = g_strdup_printf("%s/%s", pcidir, ent->d_name); if ((actor)(dev, file, opaque) < 0) goto cleanup; } @@ -1779,9 +1779,9 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, struct dirent *ent; int direrr; - virAsprintf(&groupPath, - PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT "/iommu_group/devices", - orig->domain, orig->bus, orig->slot, orig->function); + 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 */ @@ -1928,8 +1928,8 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr) const char *groupNumStr; unsigned int groupNum; - virAsprintf(&devName, VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain, addr->bus, - addr->slot, addr->function); + 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; @@ -1979,7 +1979,7 @@ virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev) dev->name, devPath); return NULL; } - virAsprintf(&groupDev, "/dev/vfio/%s", last_component(groupPath)); + groupDev = g_strdup_printf("/dev/vfio/%s", last_component(groupPath)); return groupDev; } @@ -2278,7 +2278,7 @@ virPCIGetVirtualFunctions(const char *sysfs_path, *num_virtual_functions = 0; *max_virtual_functions = 0; - virAsprintf(&totalvfs_file, "%s/sriov_totalvfs", sysfs_path); + 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 */ @@ -2295,8 +2295,8 @@ virPCIGetVirtualFunctions(const char *sysfs_path, do { g_autofree char *device_link = NULL; /* look for virtfn%d links until one isn't found */ - virAsprintf(&device_link, "%s/virtfn%zu", sysfs_path, - *num_virtual_functions); + device_link = g_strdup_printf("%s/virtfn%zu", sysfs_path, + *num_virtual_functions); if (!virFileExists(device_link)) break; @@ -2337,7 +2337,7 @@ virPCIIsVirtualFunction(const char *vf_sysfs_device_link) { g_autofree char *vf_sysfs_physfn_link = NULL; - virAsprintf(&vf_sysfs_physfn_link, "%s/physfn", vf_sysfs_device_link); + vf_sysfs_physfn_link = g_strdup_printf("%s/physfn", vf_sysfs_device_link); return virFileExists(vf_sysfs_physfn_link); } @@ -2395,8 +2395,8 @@ virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link, int virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link) { - virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s", - virPCIDeviceName); + *pci_sysfs_device_link = g_strdup_printf(PCI_SYSFS "devices/%s", + virPCIDeviceName); return 0; } @@ -2404,9 +2404,8 @@ int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr addr, char **pci_sysfs_device_link) { - virAsprintf(pci_sysfs_device_link, - PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain, - addr->bus, addr->slot, addr->function); + *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; } @@ -2591,7 +2590,7 @@ virPCIGetMdevTypes(const char *sysfspath, size_t ntypes = 0; size_t i; - virAsprintf(&types_path, "%s/mdev_supported_types", sysfspath); + types_path = g_strdup_printf("%s/mdev_supported_types", sysfspath); if ((dirret = virDirOpenIfExists(&dir, types_path)) < 0) goto cleanup; @@ -2604,7 +2603,7 @@ virPCIGetMdevTypes(const char *sysfspath, 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 */ - virAsprintf(&tmppath, "%s/%s", types_path, entry->d_name); + tmppath = g_strdup_printf("%s/%s", types_path, entry->d_name); if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0) goto cleanup; diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 2faa6215e4..59f540c7e6 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -233,7 +233,7 @@ int virPidFileReadPathIfAlive(const char *path, goto cleanup; } - virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid); + procPath = g_strdup_printf("/proc/%lld/exe", (long long)retPid); if ((ret = virFileIsLink(procPath)) < 0) return ret; @@ -494,7 +494,7 @@ virPidFileConstructPath(bool privileged, "%s", _("No runstatedir specified")); return -1; } - virAsprintf(pidfile, "%s/%s.pid", runstatedir, progname); + *pidfile = g_strdup_printf("%s/%s.pid", runstatedir, progname); } else { if (!(rundir = virGetUserRuntimeDirectory())) return -1; @@ -506,7 +506,7 @@ virPidFileConstructPath(bool privileged, return -1; } - virAsprintf(pidfile, "%s/%s.pid", rundir, progname); + *pidfile = g_strdup_printf("%s/%s.pid", rundir, progname); } return 0; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 107a0fb9c9..11928cb4b3 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -129,13 +129,13 @@ virProcessTranslateStatus(int status) { char *buf; if (WIFEXITED(status)) { - virAsprintf(&buf, _("exit status %d"), - WEXITSTATUS(status)); + buf = g_strdup_printf(_("exit status %d"), + WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { - virAsprintf(&buf, _("fatal signal %d"), - WTERMSIG(status)); + buf = g_strdup_printf(_("fatal signal %d"), + WTERMSIG(status)); } else { - virAsprintf(&buf, _("invalid value %d"), status); + buf = g_strdup_printf(_("invalid value %d"), status); } return buf; } @@ -586,7 +586,7 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids) *npids = 0; *pids = NULL; - virAsprintf(&taskPath, "/proc/%llu/task", (long long)pid); + taskPath = g_strdup_printf("/proc/%llu/task", (long long)pid); if (virDirOpen(&dir, taskPath) < 0) goto cleanup; @@ -631,7 +631,7 @@ int virProcessGetNamespaces(pid_t pid, int fd; g_autofree char *nsfile = NULL; - virAsprintf(&nsfile, "/proc/%llu/ns/%s", (long long)pid, ns[i]); + 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) { @@ -950,7 +950,7 @@ int virProcessGetStartTime(pid_t pid, g_autofree char *buf = NULL; VIR_AUTOSTRINGLIST tokens = NULL; - virAsprintf(&filename, "/proc/%llu/stat", (long long)pid); + filename = g_strdup_printf("/proc/%llu/stat", (long long)pid); if ((len = virFileReadAll(filename, 1024, &buf)) < 0) return -1; @@ -1049,7 +1049,7 @@ static int virProcessNamespaceHelper(pid_t pid G_GNUC_UNUSED, int ret = -1; g_autofree char *path = NULL; - virAsprintf(&path, "/proc/%lld/ns/mnt", (long long)data->pid); + path = g_strdup_printf("/proc/%lld/ns/mnt", (long long)data->pid); if ((fd = open(path, O_RDONLY)) < 0) { virReportSystemError(errno, "%s", diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 1eee238771..0220d9eda3 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -89,7 +89,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key, member = virJSONValueArrayGet((virJSONValuePtr) array, i); g_autofree char *prefix = NULL; - virAsprintf(&prefix, "%s.%zu", key, i); + prefix = g_strdup_printf("%s.%zu", key, i); if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, virQEMUBuildCommandLineJSONArrayNumbered, @@ -112,7 +112,7 @@ virQEMUBuildCommandLineJSONIterate(const char *key, if (data->prefix) { g_autofree char *tmpkey = NULL; - virAsprintf(&tmpkey, "%s.%s", data->prefix, key); + tmpkey = g_strdup_printf("%s.%s", data->prefix, key); return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf, data->arrayFunc, false); diff --git a/src/util/virrandom.c b/src/util/virrandom.c index 12ea9bbbdc..39ac36a76e 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -194,7 +194,7 @@ virRandomGenerateWWN(char **wwn, return -1; } - virAsprintf(wwn, "5" "%s%09llx", oui, - (unsigned long long)virRandomBits(36)); + *wwn = g_strdup_printf("5" "%s%09llx", oui, + (unsigned long long)virRandomBits(36)); return 0; } diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 55c15d04a4..903af52786 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2319,7 +2319,7 @@ virResctrlDeterminePath(const char *parentpath, return NULL; } - virAsprintf(&path, "%s/%s-%s", parentpath, prefix, id); + path = g_strdup_printf("%s/%s-%s", parentpath, prefix, id); return path; } @@ -2415,7 +2415,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl, if (!alloc_str) goto cleanup; - virAsprintf(&schemata_path, "%s/schemata", alloc->path); + 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) { @@ -2449,9 +2449,9 @@ virResctrlAddPID(const char *path, return -1; } - virAsprintf(&tasks, "%s/tasks", path); + tasks = g_strdup_printf("%s/tasks", path); - virAsprintf(&pidstr, "%lld", (long long int)pid); + pidstr = g_strdup_printf("%lld", (long long int)pid); if (virFileWriteStr(tasks, pidstr, 0) < 0) { virReportSystemError(errno, @@ -2562,7 +2562,7 @@ virResctrlMonitorDeterminePath(virResctrlMonitorPtr monitor, return 0; } - virAsprintf(&parentpath, "%s/mon_groups", monitor->alloc->path); + parentpath = g_strdup_printf("%s/mon_groups", monitor->alloc->path); monitor->path = virResctrlDeterminePath(parentpath, machinename, monitor->id); @@ -2694,7 +2694,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor, return -1; } - virAsprintf(&datapath, "%s/mon_data", monitor->path); + datapath = g_strdup_printf("%s/mon_data", monitor->path); if (virDirOpen(&dirp, datapath) < 0) goto cleanup; @@ -2711,7 +2711,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor, * "mon_L3_01" are two target directories for a two nodes system * with resource utilization data file for each node respectively. */ - virAsprintf(&filepath, "%s/%s", datapath, ent->d_name); + filepath = g_strdup_printf("%s/%s", datapath, ent->d_name); if (!virFileIsDir(filepath)) continue; diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c index 826a3db2c2..b77e30dba7 100644 --- a/src/util/virrotatingfile.c +++ b/src/util/virrotatingfile.c @@ -195,7 +195,7 @@ virRotatingFileWriterDelete(virRotatingFileWriterPtr file) for (i = 0; i < file->maxbackup; i++) { char *oldpath; - virAsprintf(&oldpath, "%s.%zu", file->basepath, i); + oldpath = g_strdup_printf("%s.%zu", file->basepath, i); if (unlink(oldpath) < 0 && errno != ENOENT) { @@ -307,7 +307,7 @@ virRotatingFileReaderNew(const char *path, for (i = 0; i < maxbackup; i++) { char *tmppath; - virAsprintf(&tmppath, "%s.%zu", path, i); + tmppath = g_strdup_printf("%s.%zu", path, i); file->entries[file->nentries - (i + 2)] = virRotatingFileReaderEntryNew(tmppath); VIR_FREE(tmppath); @@ -380,13 +380,13 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr file) goto cleanup; } } else { - virAsprintf(&nextpath, "%s.%zu", file->basepath, file->maxbackup - 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 { - virAsprintf(&thispath, "%s.%zu", file->basepath, i - 2); + thispath = g_strdup_printf("%s.%zu", file->basepath, i - 2); } VIR_DEBUG("Rollover %s -> %s", thispath, nextpath); diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 0f28c617b0..55707a8d34 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -117,8 +117,8 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix, if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0) return NULL; - virAsprintf(&path, "%s/%d:%u:%u:%llu/scsi_generic", prefix, adapter_id, - bus, target, unit); + path = g_strdup_printf("%s/%d:%u:%u:%llu/scsi_generic", prefix, adapter_id, + bus, target, unit); if (virDirOpen(&dir, path) < 0) goto cleanup; @@ -154,8 +154,8 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix, if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0) return NULL; - virAsprintf(&path, "%s/%d:%u:%u:%llu/block", prefix, adapter_id, bus, - target, unit); + path = g_strdup_printf("%s/%d:%u:%u:%llu/block", prefix, adapter_id, bus, + target, unit); if (virDirOpen(&dir, path) < 0) goto cleanup; @@ -203,10 +203,10 @@ virSCSIDeviceNew(const char *sysfs_prefix, if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0) return NULL; - virAsprintf(&dev->name, "%d:%u:%u:%llu", dev->adapter, - dev->bus, dev->target, dev->unit); - virAsprintf(&dev->sg_path, "%s/%s", - sysfs_prefix ? sysfs_prefix : "/dev", sg); + 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, @@ -215,8 +215,8 @@ virSCSIDeviceNew(const char *sysfs_prefix, return NULL; } - virAsprintf(&vendor_path, "%s/%s/vendor", prefix, dev->name); - virAsprintf(&model_path, "%s/%s/model", prefix, dev->name); + 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; @@ -227,7 +227,7 @@ virSCSIDeviceNew(const char *sysfs_prefix, virTrimSpaces(vendor, NULL); virTrimSpaces(model, NULL); - virAsprintf(&dev->id, "%s:%s", vendor, model); + dev->id = g_strdup_printf("%s:%s", vendor, model); ret = g_steal_pointer(&dev); return ret; diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c index 53da460fdf..7d8e5299b8 100644 --- a/src/util/virscsihost.c +++ b/src/util/virscsihost.c @@ -52,8 +52,8 @@ virSCSIHostGetUniqueId(const char *sysfs_prefix, char *buf = NULL; int unique_id; - virAsprintf(&sysfs_path, "%s/host%d/unique_id", - sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host); + 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; @@ -116,7 +116,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, if (!virFileIsLink(entry->d_name)) continue; - virAsprintf(&host_link, "%s/%s", prefix, entry->d_name); + host_link = g_strdup_printf("%s/%s", prefix, entry->d_name); if (virFileResolveLink(host_link, &host_path) < 0) goto cleanup; @@ -129,7 +129,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, VIR_FREE(host_link); VIR_FREE(host_path); - virAsprintf(&unique_path, "%s/%s/unique_id", prefix, entry->d_name); + unique_path = g_strdup_printf("%s/%s/unique_id", prefix, entry->d_name); if (!virFileExists(unique_path)) { VIR_FREE(unique_path); @@ -235,8 +235,8 @@ virSCSIHostGetNameByParentaddr(unsigned int domain, char *name = NULL; char *parentaddr = NULL; - virAsprintf(&parentaddr, "%04x:%02x:%02x.%01x", domain, bus, slot, - function); + 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' " diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c index 4687c30f97..d096dca518 100644 --- a/src/util/virscsivhost.c +++ b/src/util/virscsivhost.c @@ -256,7 +256,7 @@ virSCSIVHostDeviceNew(const char *name) dev->name = g_strdup(name); - virAsprintf(&dev->path, "%s/%s", SYSFS_VHOST_SCSI_DEVICES, name); + dev->path = g_strdup_printf("%s/%s", SYSFS_VHOST_SCSI_DEVICES, name); VIR_DEBUG("%s: initialized", dev->name); diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index ba1cde05cd..d7b0f12d96 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -477,8 +477,8 @@ virSocketAddrFormatFull(const virSocketAddr *addr, * nicely for UNIX sockets */ if (addr->data.sa.sa_family == AF_UNIX) { if (withService) { - virAsprintf(&addrstr, VIR_LOOPBACK_IPV4_ADDR "%s0", - separator ? separator : ":"); + addrstr = g_strdup_printf(VIR_LOOPBACK_IPV4_ADDR "%s0", + separator ? separator : ":"); } else { addrstr = g_strdup(VIR_LOOPBACK_IPV4_ADDR); } @@ -503,11 +503,11 @@ virSocketAddrFormatFull(const virSocketAddr *addr, * IPv6 only if no separator is passed to the function */ if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET6) - virAsprintf(&ipv6_host, "[%s]", host); + ipv6_host = g_strdup_printf("[%s]", host); - virAsprintf(&addrstr, "%s%s%s", - ipv6_host ? ipv6_host : host, - separator ? separator : ":", port); + addrstr = g_strdup_printf("%s%s%s", + ipv6_host ? ipv6_host : host, + separator ? separator : ":", port); } else { addrstr = g_strdup(host); } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index f3b388a7bc..64d583b0f7 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1541,7 +1541,7 @@ virStorageFileGetNPIVKey(const char *path, *tmp = '\0'; if (*serial != '\0' && *port != '\0') - virAsprintf(key, "%s_PORT%s", serial, port); + *key = g_strdup_printf("%s_PORT%s", serial, port); } return 0; @@ -2620,9 +2620,9 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent, } if (STRNEQ(dirname, "/")) { - virAsprintf(&def->path, "%s/%s", dirname, rel); + def->path = g_strdup_printf("%s/%s", dirname, rel); } else { - virAsprintf(&def->path, "/%s", rel); + def->path = g_strdup_printf("/%s", rel); } if (virStorageSourceGetActualType(parent) == VIR_STORAGE_TYPE_NETWORK) { @@ -3281,7 +3281,7 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, *port = '\0'; } - virAsprintf(&src->path, "%s/%s", target, lun); + src->path = g_strdup_printf("%s/%s", target, lun); /* Libvirt doesn't handle inline authentication. Make the caller aware. */ if (virJSONValueObjectGetString(json, "user") || @@ -4193,7 +4193,7 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top, VIR_FREE(path); - virAsprintf(&path, "%s%s", tmp, next->relPath); + path = g_strdup_printf("%s%s", tmp, next->relPath); VIR_FREE(tmp); diff --git a/src/util/virstring.c b/src/util/virstring.c index 91b237f358..ac132ff924 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -713,7 +713,7 @@ virDoubleToStr(char **strp, double number) if (virLocaleSetRaw(&oldlocale) < 0) return -1; - virAsprintf(strp, "%lf", number); + *strp = g_strdup_printf("%lf", number); virLocaleRevert(&oldlocale); virLocaleFixupRadix(strp); diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index bb6ee24f4e..a692bfa86d 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -301,7 +301,7 @@ int virSystemdCreateMachine(const char *name, ret = -1; - virAsprintf(&creatorname, "libvirt-%s", drivername); + creatorname = g_strdup_printf("libvirt-%s", drivername); if (partition) { if (!(slicename = virSystemdMakeSliceName(partition))) diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 149a82310d..97013f6a7d 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -73,8 +73,8 @@ virTPMCreateCancelPath(const char *devpath) dev++; for (i = 0; i < G_N_ELEMENTS(prefix); i++) { - virAsprintf(&path, "/sys/class/%s%s/device/cancel", prefix[i], - dev); + path = g_strdup_printf("/sys/class/%s%s/device/cancel", prefix[i], + dev); if (virFileExists(path)) break; diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index d8c296c138..4ad2ed455f 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -176,22 +176,22 @@ virTypedParameterToString(virTypedParameterPtr param) switch (param->type) { case VIR_TYPED_PARAM_INT: - virAsprintf(&value, "%d", param->value.i); + value = g_strdup_printf("%d", param->value.i); break; case VIR_TYPED_PARAM_UINT: - virAsprintf(&value, "%u", param->value.ui); + value = g_strdup_printf("%u", param->value.ui); break; case VIR_TYPED_PARAM_LLONG: - virAsprintf(&value, "%lld", param->value.l); + value = g_strdup_printf("%lld", param->value.l); break; case VIR_TYPED_PARAM_ULLONG: - virAsprintf(&value, "%llu", param->value.ul); + value = g_strdup_printf("%llu", param->value.ul); break; case VIR_TYPED_PARAM_DOUBLE: - virAsprintf(&value, "%g", param->value.d); + value = g_strdup_printf("%g", param->value.d); break; case VIR_TYPED_PARAM_BOOLEAN: - 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); diff --git a/src/util/viruri.c b/src/util/viruri.c index 241e4ea102..4717feb05e 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -234,7 +234,7 @@ virURIFormat(virURIPtr uri) if (xmluri.server != NULL && strchr(xmluri.server, ':') != NULL) { - virAsprintf(&tmpserver, "[%s]", xmluri.server); + tmpserver = g_strdup_printf("[%s]", xmluri.server); xmluri.server = tmpserver; } diff --git a/src/util/virusb.c b/src/util/virusb.c index 3e97480b1a..7ce582085f 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -89,7 +89,7 @@ static int virUSBSysReadFile(const char *f_name, const char *d_name, g_autofree char *filename = NULL; char *ignore = NULL; - virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name); + filename = g_strdup_printf(USB_SYSFS "/devices/%s/%s", d_name, f_name); if (virFileReadAll(filename, 1024, &buf) < 0) return -1; @@ -329,11 +329,11 @@ virUSBDeviceNew(unsigned int bus, } if (vroot) { - 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 { - virAsprintf(&dev->path, USB_DEVFS "%03d/%03d", - dev->bus, dev->dev); + dev->path = g_strdup_printf(USB_DEVFS "%03d/%03d", + dev->bus, dev->dev); } /* XXX fixme. this should be product/vendor */ diff --git a/src/util/virutil.c b/src/util/virutil.c index 705fb6bd74..51f8796b40 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -744,11 +744,11 @@ static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir) char *home = NULL; if (path && path[0]) { - virAsprintf(&ret, "%s/libvirt", path); + ret = g_strdup_printf("%s/libvirt", path); } else { home = virGetUserDirectory(); if (home) - virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir); + ret = g_strdup_printf("%s/%s/libvirt", home, xdgdefdir); } VIR_FREE(home); @@ -774,7 +774,7 @@ char *virGetUserRuntimeDirectory(void) } else { char *ret; - virAsprintf(&ret, "%s/libvirt", path); + ret = g_strdup_printf("%s/libvirt", path); return ret; } } @@ -1587,9 +1587,9 @@ virGetUnprivSGIOSysfsPath(const char *path, return NULL; } - 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; } @@ -1612,7 +1612,7 @@ virSetDeviceUnprivSGIO(const char *path, goto cleanup; } - virAsprintf(&val, "%d", unpriv_sgio); + val = g_strdup_printf("%d", unpriv_sgio); if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) { virReportSystemError(-rc, _("failed to set %s"), sysfs_path); @@ -1877,7 +1877,7 @@ virHostGetDRMRenderNode(void) goto cleanup; } - virAsprintf(&ret, "%s/%s", driPath, ent->d_name); + ret = g_strdup_printf("%s/%s", driPath, ent->d_name); cleanup: VIR_DIR_CLOSE(driDir); diff --git a/src/util/virvhba.c b/src/util/virvhba.c index c78d5e2cd9..df0691a658 100644 --- a/src/util/virvhba.c +++ b/src/util/virvhba.c @@ -52,8 +52,8 @@ virVHBAPathExists(const char *sysfs_prefix, char *sysfs_path = NULL; bool ret = false; - virAsprintf(&sysfs_path, "%s/host%d", - sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host); + sysfs_path = g_strdup_printf("%s/host%d", + sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host); if (virFileExists(sysfs_path)) ret = true; @@ -83,13 +83,13 @@ virVHBAIsVportCapable(const char *sysfs_prefix, char *fc_host_path = NULL; bool ret = false; - virAsprintf(&fc_host_path, "%s/host%d/%s", - sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host, - "vport_create"); + fc_host_path = g_strdup_printf("%s/host%d/%s", + sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host, + "vport_create"); - virAsprintf(&scsi_host_path, "%s/host%d/%s", - sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_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; @@ -120,8 +120,8 @@ virVHBAGetConfig(const char *sysfs_prefix, char *buf = NULL; char *result = NULL; - virAsprintf(&sysfs_path, "%s/host%d/%s", - sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host, entry); + 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; @@ -258,13 +258,13 @@ virVHBAManageVport(const int parent_host, goto cleanup; } - virAsprintf(&operation_path, "%s/host%d/%s", SYSFS_FC_HOST_PATH, - parent_host, operation_file); + 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); - virAsprintf(&operation_path, "%s/host%d/%s", SYSFS_SCSI_HOST_PATH, - parent_host, operation_file); + 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, @@ -281,7 +281,7 @@ virVHBAManageVport(const int parent_host, * 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. */ - virAsprintf(&vport_name, "%s:%s", wwpn, wwnn); + vport_name = g_strdup_printf("%s:%s", wwpn, wwnn); if (virFileWriteStr(operation_path, vport_name, 0) == 0) ret = 0; @@ -321,7 +321,7 @@ vhbaReadCompareWWN(const char *prefix, char *p; int ret = -1; - virAsprintf(&path, "%s/%s/%s", prefix, d_name, f_name); + path = g_strdup_printf("%s/%s/%s", prefix, d_name, f_name); if (!virFileExists(path)) { ret = 0; @@ -425,8 +425,8 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix, /* Existing vHBA's will have the same fabric_name, but won't * have the vport_create file - so we check for both */ - virAsprintf(&vport_create_path, "%s/%s/vport_create", prefix, - entry->d_name); + vport_create_path = g_strdup_printf("%s/%s/vport_create", prefix, + entry->d_name); if (!virFileExists(vport_create_path)) continue; -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list