[libvirt] [PATCH 60/75] util: Use g_strdup_printf() instead of virAsprintf()
Daniel Henrique Barboza
danielhb413 at gmail.com
Thu Oct 24 14:19:56 UTC 2019
On 10/22/19 10:58 AM, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> 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, "") ? "" : "/"),
Not sure how to break this one into two shorter lines (perhaps an extra
variable to hold the result of the ternary prior to the g_strdup_printf
call), but would be good to make this shorter somehow.
> + 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, "") ? "" : "/"),
Same rant I just did above.
> + 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, "") ? "" : "/"),
Same rant as before :)
> + 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);
Extra newline after the '('.
> }
> } 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
[...]
> 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);
Extra newline after '('.
> 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);
Extra newline after '('.
Reviewed-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
More information about the libvir-list
mailing list