util: Use g_strdup_printf() instead of virAsprintf()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-10-22 15:26:14 +02:00
parent ad1118ebd2
commit 91d88aaf23
54 changed files with 432 additions and 741 deletions

View File

@ -158,8 +158,7 @@ char *virAuditEncode(const char *key, const char *value)
return audit_encode_nv_string(key, value, 0);
#else
char *str;
if (virAsprintf(&str, "%s=%s", key, value) < 0)
return NULL;
str = g_strdup_printf("%s=%s", key, value);
return str;
#endif
}

View File

@ -69,8 +69,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
if (!(userdir = virGetUserConfigDirectory()))
return -1;
if (virAsprintf(path, "%s/auth.conf", userdir) < 0)
return -1;
*path = g_strdup_printf("%s/auth.conf", userdir);
VIR_DEBUG("Checking for readability of '%s'", *path);
if (access(*path, R_OK) == 0)
@ -158,13 +157,10 @@ virAuthGetUsernamePath(const char *path,
memset(&cred, 0, sizeof(virConnectCredential));
if (defaultUsername != NULL) {
if (virAsprintf(&prompt, _("Enter username for %s [%s]"), hostname,
defaultUsername) < 0) {
return NULL;
}
prompt = g_strdup_printf(_("Enter username for %s [%s]"), hostname,
defaultUsername);
} else {
if (virAsprintf(&prompt, _("Enter username for %s"), hostname) < 0)
return NULL;
prompt = g_strdup_printf(_("Enter username for %s"), hostname);
}
for (ncred = 0; ncred < auth->ncredtype; ncred++) {
@ -241,10 +237,7 @@ virAuthGetPasswordPath(const char *path,
memset(&cred, 0, sizeof(virConnectCredential));
if (virAsprintf(&prompt, _("Enter %s's password for %s"), username,
hostname) < 0) {
return NULL;
}
prompt = g_strdup_printf(_("Enter %s's password for %s"), username, hostname);
for (ncred = 0; ncred < auth->ncredtype; ncred++) {
if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE &&

View File

@ -113,13 +113,11 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
if (!hostname)
hostname = "localhost";
if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0)
return -1;
authgroup = g_strdup_printf("auth-%s-%s", service, hostname);
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
VIR_FREE(authgroup);
if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0)
return -1;
authgroup = g_strdup_printf("auth-%s-%s", service, "default");
}
if (!virKeyFileHasGroup(auth->keyfile, authgroup))
@ -132,8 +130,7 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
return -1;
}
if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0)
return -1;
credgroup = g_strdup_printf("credentials-%s", authcred);
if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
virReportError(VIR_ERR_CONF_SYNTAX,

View File

@ -206,8 +206,7 @@ virCgroupPartitionEscape(char **path)
if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0)
return rc;
if (virAsprintf(&newstr, "_%s", *path) < 0)
return -1;
newstr = g_strdup_printf("_%s", *path);
VIR_FREE(*path);
*path = newstr;
@ -291,9 +290,7 @@ virCgroupDetectPlacement(virCgroupPtr group,
if (pid == -1) {
procfile = g_strdup("/proc/self/cgroup");
} else {
if (virAsprintf(&procfile, "/proc/%lld/cgroup",
(long long) pid) < 0)
goto cleanup;
procfile = g_strdup_printf("/proc/%lld/cgroup", (long long)pid);
}
mapping = fopen(procfile, "r");
@ -446,8 +443,7 @@ virCgroupGetBlockDevString(const char *path)
/* Automatically append space after the string since all callers
* use it anyway */
if (virAsprintf(&ret, "%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)) < 0)
return NULL;
ret = g_strdup_printf("%d:%d ", major(sb.st_rdev), minor(sb.st_rdev));
return ret;
}
@ -563,8 +559,7 @@ virCgroupSetValueU64(virCgroupPtr group,
{
g_autofree char *strval = NULL;
if (virAsprintf(&strval, "%llu", value) < 0)
return -1;
strval = g_strdup_printf("%llu", value);
return virCgroupSetValueStr(group, controller, key, strval);
}
@ -578,8 +573,7 @@ virCgroupSetValueI64(virCgroupPtr group,
{
g_autofree char *strval = NULL;
if (virAsprintf(&strval, "%lld", value) < 0)
return -1;
strval = g_strdup_printf("%lld", value);
return virCgroupSetValueStr(group, controller, key, strval);
}
@ -682,11 +676,8 @@ virCgroupNew(pid_t pid,
if (path[0] == '/' || !parent) {
(*group)->path = g_strdup(path);
} else {
if (virAsprintf(&(*group)->path, "%s%s%s",
parent->path,
STREQ(parent->path, "") ? "" : "/",
path) < 0)
goto error;
(*group)->path = g_strdup_printf("%s%s%s", parent->path,
STREQ(parent->path, "") ? "" : "/", path);
}
if (virCgroupDetect(*group, pid, controllers, path, parent) < 0)
@ -918,9 +909,7 @@ virCgroupNewDomainPartition(virCgroupPtr partition,
{
g_autofree char *grpname = NULL;
if (virAsprintf(&grpname, "%s.libvirt-%s",
name, driver) < 0)
return -1;
grpname = g_strdup_printf("%s.libvirt-%s", name, driver);
if (virCgroupPartitionEscape(&grpname) < 0)
return -1;
@ -971,15 +960,13 @@ virCgroupNewThread(virCgroupPtr domain,
switch (nameval) {
case VIR_CGROUP_THREAD_VCPU:
if (virAsprintf(&name, "vcpu%d", id) < 0)
return -1;
name = g_strdup_printf("vcpu%d", id);
break;
case VIR_CGROUP_THREAD_EMULATOR:
name = g_strdup("emulator");
break;
case VIR_CGROUP_THREAD_IOTHREAD:
if (virAsprintf(&name, "iothread%d", id) < 0)
return -1;
name = g_strdup_printf("iothread%d", id);
break;
case VIR_CGROUP_THREAD_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR,
@ -2356,10 +2343,8 @@ virCgroupRemoveRecursively(char *grppath)
if (ent->d_type != DT_DIR) continue;
if (virAsprintf(&path, "%s/%s", grppath, ent->d_name) == -1) {
rc = -ENOMEM;
break;
}
path = g_strdup_printf("%s/%s", grppath, ent->d_name);
rc = virCgroupRemoveRecursively(path);
if (rc != 0)
break;

View File

@ -97,16 +97,15 @@ virCgroupV1ValidateMachineGroup(virCgroupPtr group,
g_autofree char *scopename_new = NULL;
g_autofree char *partmachinename = NULL;
if (virAsprintf(&partname, "%s.libvirt-%s",
name, drivername) < 0)
return false;
partname = g_strdup_printf("%s.libvirt-%s", name, drivername);
if (virCgroupPartitionEscape(&partname) < 0)
return false;
if (virAsprintf(&partmachinename, "%s.libvirt-%s",
machinename, drivername) < 0 ||
virCgroupPartitionEscape(&partmachinename) < 0)
partmachinename = g_strdup_printf("%s.libvirt-%s",
machinename, drivername);
if (virCgroupPartitionEscape(&partmachinename) < 0)
return false;
if (!(scopename_old = virSystemdMakeScopeName(name, drivername, true)))
@ -199,18 +198,16 @@ virCgroupV1CopyPlacement(virCgroupPtr group,
if (path[0] == '/') {
group->legacy[i].placement = g_strdup(path);
} else {
bool delim = STREQ(parent->legacy[i].placement, "/") || STREQ(path, "");
/*
* parent == "/" + path="" => "/"
* parent == "/libvirt.service" + path == "" => "/libvirt.service"
* parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
*/
if (virAsprintf(&group->legacy[i].placement,
"%s%s%s",
parent->legacy[i].placement,
(STREQ(parent->legacy[i].placement, "/") ||
STREQ(path, "") ? "" : "/"),
path) < 0)
return -1;
group->legacy[i].placement = g_strdup_printf("%s%s%s",
parent->legacy[i].placement,
delim ? "" : "/",
path);
}
}
@ -241,8 +238,7 @@ virCgroupV1ResolveMountLink(const char *mntDir,
return 0;
*dirName = '\0';
if (virAsprintf(&linkSrc, "%s/%s", tmp, typeStr) < 0)
return -1;
linkSrc = g_strdup_printf("%s/%s", tmp, typeStr);
*dirName = '/';
if (lstat(linkSrc, &sb) < 0) {
@ -354,12 +350,11 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
group->legacy[i].placement = g_strdup(selfpath);
} else {
if (virAsprintf(&group->legacy[i].placement,
"%s%s%s", selfpath,
(STREQ(selfpath, "/") ||
STREQ(path, "") ? "" : "/"),
path) < 0)
return -1;
bool delim = STREQ(selfpath, "/") || STREQ(path, "");
group->legacy[i].placement = g_strdup_printf("%s%s%s", selfpath,
delim ? "" : "/",
path);
}
}
}
@ -520,11 +515,8 @@ virCgroupV1PathOfController(virCgroupPtr group,
return -1;
}
if (virAsprintf(path, "%s%s/%s",
group->legacy[controller].mountPoint,
group->legacy[controller].placement,
NULLSTR_EMPTY(key)) < 0)
return -1;
*path = g_strdup_printf("%s%s/%s", group->legacy[controller].mountPoint,
group->legacy[controller].placement, NULLSTR_EMPTY(key));
return 0;
}
@ -813,9 +805,7 @@ virCgroupV1BindMount(virCgroupPtr group,
return -1;
}
if (virAsprintf(&opts,
"mode=755,size=65536%s", mountopts) < 0)
return -1;
opts = g_strdup_printf("mode=755,size=65536%s", mountopts);
if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
virReportSystemError(errno,
@ -830,10 +820,7 @@ virCgroupV1BindMount(virCgroupPtr group,
if (!virFileExists(group->legacy[i].mountPoint)) {
g_autofree char *src = NULL;
if (virAsprintf(&src, "%s%s",
oldroot,
group->legacy[i].mountPoint) < 0)
return -1;
src = g_strdup_printf("%s%s", oldroot, group->legacy[i].mountPoint);
VIR_DEBUG("Create mount point '%s'",
group->legacy[i].mountPoint);
@ -893,9 +880,8 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
if (!cgroup->legacy[i].mountPoint)
continue;
if (virAsprintf(&base, "%s%s", cgroup->legacy[i].mountPoint,
cgroup->legacy[i].placement) < 0)
goto cleanup;
base = g_strdup_printf("%s%s", cgroup->legacy[i].mountPoint,
cgroup->legacy[i].placement);
if (virDirOpen(&dh, base) < 0)
goto cleanup;
@ -903,8 +889,7 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
while ((direrr = virDirRead(dh, &de, base)) > 0) {
g_autofree char *entry = NULL;
if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)
goto cleanup;
entry = g_strdup_printf("%s/%s", base, de->d_name);
if (chown(entry, uid, gid) < 0) {
virReportSystemError(errno,
@ -961,8 +946,7 @@ virCgroupV1SetBlkioWeight(virCgroupPtr group,
return -1;
}
if (virAsprintf(&value, "%u", weight) < 0)
return -1;
value = g_strdup_printf("%u", weight);
return virCgroupSetValueRaw(path, value);
}
@ -1204,8 +1188,7 @@ virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(devPath)))
return -1;
if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
return -1;
str = g_strdup_printf("%s%d", blkstr, weight);
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight_device", &path) < 0) {
@ -1272,8 +1255,7 @@ virCgroupV1SetBlkioDeviceReadIops(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
if (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
return -1;
str = g_strdup_printf("%s%u", blkstr, riops);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@ -1324,8 +1306,7 @@ virCgroupV1SetBlkioDeviceWriteIops(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0)
return -1;
str = g_strdup_printf("%s%u", blkstr, wiops);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@ -1376,8 +1357,7 @@ virCgroupV1SetBlkioDeviceReadBps(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0)
return -1;
str = g_strdup_printf("%s%llu", blkstr, rbps);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@ -1428,8 +1408,7 @@ virCgroupV1SetBlkioDeviceWriteBps(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0)
return -1;
str = g_strdup_printf("%s%llu", blkstr, wbps);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@ -1780,17 +1759,16 @@ virCgroupV1AllowDevice(virCgroupPtr group,
if (major < 0)
majorstr = g_strdup("*");
if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
return -1;
else
majorstr = g_strdup_printf("%i", major);
if (minor < 0)
minorstr = g_strdup("*");
if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
return -1;
else
minorstr = g_strdup_printf("%i", minor);
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms)) < 0)
return -1;
devstr = g_strdup_printf("%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms));
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
@ -1815,17 +1793,16 @@ virCgroupV1DenyDevice(virCgroupPtr group,
if (major < 0)
majorstr = g_strdup("*");
if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
return -1;
else
majorstr = g_strdup_printf("%i", major);
if (minor < 0)
minorstr = g_strdup("*");
if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
return -1;
else
minorstr = g_strdup_printf("%i", minor);
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms)) < 0)
return -1;
devstr = g_strdup_printf("%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms));
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,

View File

@ -75,8 +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. */
if (virAsprintf(&contFile, "%s/cgroup.controllers", entry.mnt_dir) < 0)
goto cleanup;
contFile = g_strdup_printf("%s/cgroup.controllers", entry.mnt_dir);
if (virFileReadAll(contFile, 1024 * 1024, &contStr) < 0)
goto cleanup;
@ -104,10 +103,7 @@ virCgroupV2ValidateMachineGroup(virCgroupPtr group,
g_autofree char *scopename = NULL;
char *tmp;
if (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename,
drivername) < 0) {
return false;
}
partmachinename = g_strdup_printf("%s.libvirt-%s", machinename, drivername);
if (virCgroupPartitionEscape(&partmachinename) < 0)
return false;
@ -161,17 +157,16 @@ virCgroupV2CopyPlacement(virCgroupPtr group,
if (path[0] == '/') {
group->unified.placement = g_strdup(path);
} else {
bool delim = STREQ(parent->unified.placement, "/") || STREQ(path, "");
/*
* parent == "/" + path="" => "/"
* parent == "/libvirt.service" + path == "" => "/libvirt.service"
* parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
*/
if (virAsprintf(&group->unified.placement, "%s%s%s",
parent->unified.placement,
(STREQ(parent->unified.placement, "/") ||
STREQ(path, "") ? "" : "/"),
path) < 0)
return -1;
group->unified.placement = g_strdup_printf("%s%s%s",
parent->unified.placement,
delim ? "" : "/",
path);
}
return 0;
@ -215,12 +210,8 @@ virCgroupV2DetectPlacement(virCgroupPtr group,
* selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
* selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
*/
if (virAsprintf(&group->unified.placement,
"%s%s%s", selfpath,
(STREQ(selfpath, "/") ||
STREQ(path, "") ? "" : "/"),
path) < 0)
return -1;
group->unified.placement = g_strdup_printf("%s%s%s", selfpath,
(STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), path);
return 0;
}
@ -258,15 +249,13 @@ virCgroupV2ParseControllersFile(virCgroupPtr group,
char **tmp;
if (parent) {
if (virAsprintf(&contFile, "%s%s/cgroup.subtree_control",
parent->unified.mountPoint,
NULLSTR_EMPTY(parent->unified.placement)) < 0)
return -1;
contFile = g_strdup_printf("%s%s/cgroup.subtree_control",
parent->unified.mountPoint,
NULLSTR_EMPTY(parent->unified.placement));
} else {
if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
group->unified.mountPoint,
NULLSTR_EMPTY(group->unified.placement)) < 0)
return -1;
contFile = g_strdup_printf("%s%s/cgroup.controllers",
group->unified.mountPoint,
NULLSTR_EMPTY(group->unified.placement));
}
rc = virFileReadAll(contFile, 1024 * 1024, &contStr);
@ -353,11 +342,8 @@ virCgroupV2PathOfController(virCgroupPtr group,
return -1;
}
if (virAsprintf(path, "%s%s/%s",
group->unified.mountPoint,
group->unified.placement,
NULLSTR_EMPTY(key)) < 0)
return -1;
*path = g_strdup_printf("%s%s/%s", group->unified.mountPoint,
group->unified.placement, NULLSTR_EMPTY(key));
return 0;
}
@ -379,10 +365,7 @@ virCgroupV2EnableController(virCgroupPtr group,
g_autofree char *val = NULL;
g_autofree char *path = NULL;
if (virAsprintf(&val, "+%s",
virCgroupV2ControllerTypeToString(controller)) < 0) {
return -1;
}
val = g_strdup_printf("+%s", virCgroupV2ControllerTypeToString(controller));
if (virCgroupPathOfController(parent, controller,
"cgroup.subtree_control", &path) < 0) {
@ -564,11 +547,9 @@ virCgroupV2BindMount(virCgroupPtr group,
return -1;
}
if (virAsprintf(&opts, "mode=755,size=65536%s", mountopts) < 0)
return -1;
opts = g_strdup_printf("mode=755,size=65536%s", mountopts);
if (virAsprintf(&src, "%s%s", oldroot, group->unified.mountPoint) < 0)
return -1;
src = g_strdup_printf("%s%s", oldroot, group->unified.mountPoint);
if (mount(src, group->unified.mountPoint, "none", MS_BIND, NULL) < 0) {
virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'"),
@ -588,10 +569,8 @@ virCgroupV2SetOwner(virCgroupPtr cgroup,
{
g_autofree char *base = NULL;
if (virAsprintf(&base, "%s%s", cgroup->unified.mountPoint,
cgroup->unified.placement) < 0) {
return -1;
}
base = g_strdup_printf("%s%s", cgroup->unified.mountPoint,
cgroup->unified.placement);
if (virFileChownFiles(base, uid, gid) < 0)
return -1;
@ -635,8 +614,7 @@ virCgroupV2SetBlkioWeight(virCgroupPtr group,
return -1;
}
if (virAsprintf(&value, format, weight) < 0)
return -1;
value = g_strdup_printf(format, weight);
return virCgroupSetValueRaw(path, value);
}
@ -829,8 +807,7 @@ virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(devPath)))
return -1;
if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
return -1;
str = g_strdup_printf("%s%d", blkstr, weight);
if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight", &path) < 0) {
@ -899,11 +876,9 @@ virCgroupV2SetBlkioDeviceReadIops(virCgroupPtr group,
return -1;
if (riops == 0) {
if (virAsprintf(&str, "%sriops=max", blkstr) < 0)
return -1;
str = g_strdup_printf("%sriops=max", blkstr);
} else {
if (virAsprintf(&str, "%sriops=%u", blkstr, riops) < 0)
return -1;
str = g_strdup_printf("%sriops=%u", blkstr, riops);
}
return virCgroupSetValueStr(group,
@ -970,11 +945,9 @@ virCgroupV2SetBlkioDeviceWriteIops(virCgroupPtr group,
return -1;
if (wiops == 0) {
if (virAsprintf(&str, "%swiops=max", blkstr) < 0)
return -1;
str = g_strdup_printf("%swiops=max", blkstr);
} else {
if (virAsprintf(&str, "%swiops=%u", blkstr, wiops) < 0)
return -1;
str = g_strdup_printf("%swiops=%u", blkstr, wiops);
}
return virCgroupSetValueStr(group,
@ -1041,11 +1014,9 @@ virCgroupV2SetBlkioDeviceReadBps(virCgroupPtr group,
return -1;
if (rbps == 0) {
if (virAsprintf(&str, "%srbps=max", blkstr) < 0)
return -1;
str = g_strdup_printf("%srbps=max", blkstr);
} else {
if (virAsprintf(&str, "%srbps=%llu", blkstr, rbps) < 0)
return -1;
str = g_strdup_printf("%srbps=%llu", blkstr, rbps);
}
return virCgroupSetValueStr(group,
@ -1112,11 +1083,9 @@ virCgroupV2SetBlkioDeviceWriteBps(virCgroupPtr group,
return -1;
if (wbps == 0) {
if (virAsprintf(&str, "%swbps=max", blkstr) < 0)
return -1;
str = g_strdup_printf("%swbps=max", blkstr);
} else {
if (virAsprintf(&str, "%swbps=%llu", blkstr, wbps) < 0)
return -1;
str = g_strdup_printf("%swbps=%llu", blkstr, wbps);
}
return virCgroupSetValueStr(group,
@ -1516,8 +1485,7 @@ virCgroupV2SetCpuCfsPeriod(virCgroupPtr group,
}
*tmp = '\0';
if (virAsprintf(&value, "%s %llu", str, cfs_period) < 0)
return -1;
value = g_strdup_printf("%s %llu", str, cfs_period);
return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPU,
"cpu.max", value);

View File

@ -1514,19 +1514,13 @@ virConfLoadConfigPath(const char *name)
{
char *path;
if (geteuid() == 0) {
if (virAsprintf(&path, "%s/libvirt/%s",
SYSCONFDIR, name) < 0)
return NULL;
path = g_strdup_printf("%s/libvirt/%s", SYSCONFDIR, name);
} else {
char *userdir = virGetUserConfigDirectory();
if (!userdir)
return NULL;
if (virAsprintf(&path, "%s/%s",
userdir, name) < 0) {
VIR_FREE(userdir);
return NULL;
}
path = g_strdup_printf("%s/%s", userdir, name);
VIR_FREE(userdir);
}

View File

@ -127,10 +127,9 @@ virDevMapperGetTargetsImpl(const char *path,
goto cleanup;
for (i = 0; i < deps->count; i++) {
if (virAsprintfQuiet(&devPaths[i], "/dev/block/%u:%u",
major(deps->device[i]),
minor(deps->device[i])) < 0)
goto cleanup;
devPaths[i] = g_strdup_printf("/dev/block/%u:%u",
major(deps->device[i]),
minor(deps->device[i]));
}
recursiveDevPaths = NULL;

View File

@ -177,8 +177,7 @@ addnhostsWrite(const char *path,
* for runtime addition.
*/
if (virAsprintf(&tmp, "%s.new", path) < 0)
return -ENOMEM;
tmp = g_strdup_printf("%s.new", path);
if (!(f = fopen(tmp, "w"))) {
istmp = false;
@ -309,30 +308,24 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile,
/* the first test determines if it is a dhcpv6 host */
if (ipv6) {
if (name && id) {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"id:%s,%s,[%s]", id, name, ipstr) < 0)
goto error;
hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("id:%s,%s,[%s]",
id, name, ipstr);
} else if (name && !id) {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"%s,[%s]", name, ipstr) < 0)
goto error;
hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,[%s]",
name, ipstr);
} else if (!name && id) {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"id:%s,[%s]", id, ipstr) < 0)
goto error;
hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("id:%s,[%s]",
id, ipstr);
}
} else if (name && mac) {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,%s",
mac, ipstr, name) < 0)
goto error;
hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s,%s",
mac, ipstr, name);
} else if (name && !mac) {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s",
name, ipstr) < 0)
goto error;
hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s", name,
ipstr);
} else {
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s",
mac, ipstr) < 0)
goto error;
hostsfile->hosts[hostsfile->nhosts].host = g_strdup_printf("%s,%s", mac,
ipstr);
}
VIR_FREE(ipstr);
@ -387,8 +380,7 @@ hostsfileWrite(const char *path,
* for runtime addition.
*/
if (virAsprintf(&tmp, "%s.new", path) < 0)
return -ENOMEM;
tmp = g_strdup_printf("%s.new", path);
if (!(f = fopen(tmp, "w"))) {
istmp = false;
@ -752,8 +744,7 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force)
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
if (virAsprintf(&complete, "%s\n%s", version, help) < 0)
goto cleanup;
complete = g_strdup_printf("%s\n%s", version, help);
ret = dnsmasqCapsSetFromBuffer(caps, complete);

View File

@ -58,10 +58,7 @@ ebtablesContextNew(const char *driver)
if (VIR_ALLOC(ctx) < 0)
return NULL;
if (virAsprintf(&ctx->chain, "libvirt_%s_FORWARD", driver) < 0) {
VIR_FREE(ctx);
return NULL;
}
ctx->chain = g_strdup_printf("libvirt_%s_FORWARD", driver);
return ctx;
}

View File

@ -1488,8 +1488,7 @@ virLastErrorPrefixMessage(const char *fmt, ...)
if (virVasprintfQuiet(&fmtmsg, fmt, args) < 0)
goto cleanup;
if (virAsprintfQuiet(&newmsg, "%s: %s", fmtmsg, err->message) < 0)
goto cleanup;
newmsg = g_strdup_printf("%s: %s", fmtmsg, err->message);
VIR_FREE(err->message);
err->message = g_steal_pointer(&newmsg);

View File

@ -508,8 +508,7 @@ virFileRewrite(const char *path,
int fd = -1;
int ret = -1;
if (virAsprintf(&newfile, "%s.new", path) < 0)
goto cleanup;
newfile = g_strdup_printf("%s.new", path);
if ((fd = open(newfile, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) {
virReportSystemError(errno, _("cannot create file '%s'"),
@ -666,8 +665,7 @@ static int virFileLoopDeviceOpenLoopCtl(char **dev_name, int *fd)
VIR_DEBUG("Found free loop device number %i", devnr);
if (virAsprintf(&looppath, "/dev/loop%i", devnr) < 0)
return -1;
looppath = g_strdup_printf("/dev/loop%i", devnr);
if ((*fd = open(looppath, O_RDWR)) < 0) {
virReportSystemError(errno,
@ -703,8 +701,7 @@ static int virFileLoopDeviceOpenSearch(char **dev_name)
!c_isdigit(de->d_name[4]))
continue;
if (virAsprintf(&looppath, "/dev/%s", de->d_name) < 0)
goto cleanup;
looppath = g_strdup_printf("/dev/%s", de->d_name);
VIR_DEBUG("Checking up on device %s", looppath);
if ((fd = open(looppath, O_RDWR)) < 0) {
@ -834,9 +831,7 @@ virFileNBDDeviceIsBusy(const char *dev_name)
{
g_autofree char *path = NULL;
if (virAsprintf(&path, SYSFS_BLOCK_DIR "/%s/pid",
dev_name) < 0)
return -1;
path = g_strdup_printf(SYSFS_BLOCK_DIR "/%s/pid", dev_name);
if (!virFileExists(path)) {
if (errno == ENOENT)
@ -868,7 +863,7 @@ virFileNBDDeviceFindUnused(void)
if (rv < 0)
goto cleanup;
if (rv == 0) {
ignore_value(virAsprintf(&ret, "/dev/%s", de->d_name));
ret = g_strdup_printf("/dev/%s", de->d_name);
goto cleanup;
}
}
@ -1013,9 +1008,7 @@ int virFileDeleteTree(const char *dir)
g_autofree char *filepath = NULL;
struct stat sb;
if (virAsprintf(&filepath, "%s/%s",
dir, de->d_name) < 0)
goto cleanup;
filepath = g_strdup_printf("%s/%s", dir, de->d_name);
if (lstat(filepath, &sb) < 0) {
virReportSystemError(errno, _("Cannot access '%s'"),
@ -1556,8 +1549,7 @@ virFileRelLinkPointsTo(const char *directory,
checkLink);
return -1;
}
if (virAsprintf(&candidate, "%s/%s", directory, checkLink) < 0)
return -1;
candidate = g_strdup_printf("%s/%s", directory, checkLink);
return virFileLinkPointsTo(candidate, checkDest);
}
@ -1693,8 +1685,8 @@ virFindFileInPath(const char *file)
*/
pathiter = path;
while ((pathseg = strsep(&pathiter, ":")) != NULL) {
if (virAsprintf(&fullpath, "%s/%s", pathseg, file) < 0 ||
virFileIsExecutable(fullpath))
fullpath = g_strdup_printf("%s/%s", pathseg, file);
if (virFileIsExecutable(fullpath))
break;
VIR_FREE(fullpath);
}
@ -1757,8 +1749,7 @@ virFileFindResourceFull(const char *filename,
else
path = installdir;
if (virAsprintf(&ret, "%s/%s%s%s", path, prefix, filename, suffix) < 0)
return NULL;
ret = g_strdup_printf("%s/%s%s%s", path, prefix, filename, suffix);
VIR_DEBUG("Resolved '%s' to '%s'", filename, ret);
return ret;
@ -2985,8 +2976,7 @@ int virFileChownFiles(const char *name,
while ((direrr = virDirRead(dir, &ent, name)) > 0) {
g_autofree char *path = NULL;
if (virAsprintf(&path, "%s/%s", name, ent->d_name) < 0)
goto cleanup;
path = g_strdup_printf("%s/%s", name, ent->d_name);
if (!virFileIsRegular(path))
continue;
@ -3103,9 +3093,9 @@ virFileBuildPath(const char *dir, const char *name, const char *ext)
char *path;
if (ext == NULL) {
ignore_value(virAsprintf(&path, "%s/%s", dir, name));
path = g_strdup_printf("%s/%s", dir, name);
} else {
ignore_value(virAsprintf(&path, "%s/%s%s", dir, name, ext));
path = g_strdup_printf("%s/%s%s", dir, name, ext);
}
return path;
@ -3293,8 +3283,7 @@ virFileAbsPath(const char *path, char **abspath)
if (buf == NULL)
return -1;
if (virAsprintf(abspath, "%s/%s", buf, path) < 0)
return -1;
*abspath = g_strdup_printf("%s/%s", buf, path);
}
return 0;

View File

@ -627,8 +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
*/
if (virAsprintf(&sysfs_nodedir, "%s/node", SYSFS_SYSTEM_PATH) < 0)
goto cleanup;
sysfs_nodedir = g_strdup_printf("%s/node", SYSFS_SYSTEM_PATH);
if (virDirOpenQuiet(&nodedir, sysfs_nodedir) < 0) {
/* the host isn't probably running a NUMA architecture */
@ -671,9 +670,8 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
(*nodes)++;
if (virAsprintf(&sysfs_cpudir, "%s/node/%s", SYSFS_SYSTEM_PATH,
nodedirent->d_name) < 0)
goto cleanup;
sysfs_cpudir = g_strdup_printf("%s/node/%s", SYSFS_SYSTEM_PATH,
nodedirent->d_name);
if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch,
present_cpus_map,
@ -706,8 +704,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
fallback:
VIR_FREE(sysfs_cpudir);
if (virAsprintf(&sysfs_cpudir, "%s/cpu", SYSFS_SYSTEM_PATH) < 0)
goto cleanup;
sysfs_cpudir = g_strdup_printf("%s/cpu", SYSFS_SYSTEM_PATH);
if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch,
present_cpus_map,

View File

@ -184,8 +184,7 @@ virHostdevManagerNew(void)
if (!(rundir = virGetUserRuntimeDirectory()))
return NULL;
if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < 0)
return NULL;
hostdevMgr->stateDir = g_strdup_printf("%s/hostdevmgr", rundir);
old_umask = umask(077);

View File

@ -280,10 +280,8 @@ virHostMemGetStats(int cellNum G_GNUC_UNUSED,
return -1;
}
if (virAsprintf(&meminfo_path,
SYSFS_SYSTEM_PATH "/node/node%d/meminfo",
cellNum) < 0)
return -1;
meminfo_path = g_strdup_printf(
SYSFS_SYSTEM_PATH "/node/node%d/meminfo", cellNum);
}
meminfo = fopen(meminfo_path, "r");
@ -318,12 +316,9 @@ virHostMemSetParameterValue(virTypedParameterPtr param)
char *field = strchr(param->field, '_');
sa_assert(field);
field++;
if (virAsprintf(&path, "%s/%s",
SYSFS_MEMORY_SHARED_PATH, field) < 0)
return -2;
path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
if (virAsprintf(&strval, "%u", param->value.ui) == -1)
return -2;
strval = g_strdup_printf("%u", param->value.ui);
if ((rc = virFileWriteStr(path, strval, 0)) < 0) {
virReportSystemError(-rc, _("failed to set %s"), param->field);
@ -346,9 +341,7 @@ virHostMemParametersAreAllSupported(virTypedParameterPtr params,
char *field = strchr(param->field, '_');
sa_assert(field);
field++;
if (virAsprintf(&path, "%s/%s",
SYSFS_MEMORY_SHARED_PATH, field) < 0)
return false;
path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_INVALID,
@ -412,9 +405,7 @@ virHostMemGetParameterValue(const char *field,
char *tmp = NULL;
int rc = -1;
if (virAsprintf(&path, "%s/%s",
SYSFS_MEMORY_SHARED_PATH, field) < 0)
return -1;
path = g_strdup_printf("%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
if (!virFileExists(path))
return -2;

View File

@ -401,7 +401,7 @@ static char *iptablesFormatNetwork(virSocketAddr *netaddr,
if (!netstr)
return NULL;
ignore_value(virAsprintf(&ret, "%s/%d", netstr, prefix));
ret = g_strdup_printf("%s/%d", netstr, prefix);
return ret;
}
@ -905,31 +905,25 @@ iptablesForwardMasquerade(virFirewallPtr fw,
}
if (port->start < port->end && port->end < 65536) {
if (virAsprintf(&portRangeStr, ":%u-%u",
port->start, port->end) < 0)
return -1;
portRangeStr = g_strdup_printf(":%u-%u", port->start, port->end);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid port range '%u-%u'."),
port->start, port->end);
return -1;
}
}
/* Use --jump SNAT if public addr is specified */
if (addrStartStr && addrStartStr[0]) {
int r = 0;
if (addrEndStr && addrEndStr[0]) {
r = virAsprintf(&natRangeStr, "%s-%s%s", addrStartStr, addrEndStr,
portRangeStr ? portRangeStr : "");
natRangeStr = g_strdup_printf("%s-%s%s", addrStartStr, addrEndStr,
portRangeStr ? portRangeStr : "");
} else {
r = virAsprintf(&natRangeStr, "%s%s", addrStartStr,
portRangeStr ? portRangeStr : "");
natRangeStr = g_strdup_printf("%s%s", addrStartStr,
portRangeStr ? portRangeStr : "");
}
if (r < 0)
return -1;
virFirewallRuleAddArgList(fw, rule,
"--jump", "SNAT",
"--to-source", natRangeStr, NULL);

View File

@ -213,10 +213,8 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
g_autofree char *temp_ifacename = NULL;
g_autoptr(virCommand) cmd = NULL;
if (virAsprintf(&temp_ifacename,
"libvirt-iface-%08llx",
(unsigned long long)virRandomBits(32)) < 0)
return -1;
temp_ifacename = g_strdup_printf("libvirt-iface-%08llx",
(unsigned long long)virRandomBits(32));
VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'",
temp_ifacename, initiatoriqn);

View File

@ -497,8 +497,7 @@ virJSONValuePtr
virJSONValueNewNumberInt(int data)
{
g_autofree char *str = NULL;
if (virAsprintf(&str, "%i", data) < 0)
return NULL;
str = g_strdup_printf("%i", data);
return virJSONValueNewNumber(str);
}
@ -507,8 +506,7 @@ virJSONValuePtr
virJSONValueNewNumberUint(unsigned int data)
{
g_autofree char *str = NULL;
if (virAsprintf(&str, "%u", data) < 0)
return NULL;
str = g_strdup_printf("%u", data);
return virJSONValueNewNumber(str);
}
@ -517,8 +515,7 @@ virJSONValuePtr
virJSONValueNewNumberLong(long long data)
{
g_autofree char *str = NULL;
if (virAsprintf(&str, "%lld", data) < 0)
return NULL;
str = g_strdup_printf("%lld", data);
return virJSONValueNewNumber(str);
}
@ -527,8 +524,7 @@ virJSONValuePtr
virJSONValueNewNumberUlong(unsigned long long data)
{
g_autofree char *str = NULL;
if (virAsprintf(&str, "%llu", data) < 0)
return NULL;
str = g_strdup_printf("%llu", data);
return virJSONValueNewNumber(str);
}

View File

@ -149,8 +149,7 @@ virKModIsBlacklisted(const char *module)
g_autofree char *drvblklst = NULL;
g_autofree char *outbuf = NULL;
if (virAsprintfQuiet(&drvblklst, "blacklist %s\n", module) < 0)
return false;
drvblklst = g_strdup_printf("blacklist %s\n", module);
/* modprobe will convert all '-' into '_', so we need to as well */
for (i = 0; i < drvblklst[i]; i++)

View File

@ -67,7 +67,7 @@ static char *virLockSpaceGetResourcePath(virLockSpacePtr lockspace,
{
char *ret;
if (lockspace->dir)
ignore_value(virAsprintf(&ret, "%s/%s", lockspace->dir, resname));
ret = g_strdup_printf("%s/%s", lockspace->dir, resname);
else
ret = g_strdup(resname);
return ret;

View File

@ -149,15 +149,15 @@ virLogUnlock(void)
}
static int
static void
virLogSetDefaultOutputToStderr(void)
{
return virAsprintf(&virLogDefaultOutput, "%d:stderr",
virLogDefaultPriority);
virLogDefaultOutput = g_strdup_printf("%d:stderr",
virLogDefaultPriority);
}
static int
static void
virLogSetDefaultOutputToJournald(void)
{
virLogPriority priority = virLogDefaultPriority;
@ -167,7 +167,7 @@ virLogSetDefaultOutputToJournald(void)
if (priority == VIR_LOG_DEBUG)
priority = VIR_LOG_INFO;
return virAsprintf(&virLogDefaultOutput, "%d:journald", priority);
virLogDefaultOutput = g_strdup_printf("%d:journald", priority);
}
@ -179,10 +179,8 @@ virLogSetDefaultOutputToFile(const char *binary, bool privileged)
mode_t old_umask;
if (privileged) {
if (virAsprintf(&virLogDefaultOutput,
"%d:file:%s/log/libvirt/%s.log", virLogDefaultPriority,
LOCALSTATEDIR, binary) < 0)
goto cleanup;
virLogDefaultOutput = g_strdup_printf("%d:file:%s/log/libvirt/%s.log",
virLogDefaultPriority, LOCALSTATEDIR, binary);
} else {
if (!(logdir = virGetUserCacheDirectory()))
goto cleanup;
@ -194,9 +192,8 @@ virLogSetDefaultOutputToFile(const char *binary, bool privileged)
}
umask(old_umask);
if (virAsprintf(&virLogDefaultOutput, "%d:file:%s/%s.log",
virLogDefaultPriority, logdir, binary) < 0)
goto cleanup;
virLogDefaultOutput = g_strdup_printf("%d:file:%s/%s.log",
virLogDefaultPriority, logdir, binary);
}
ret = 0;
@ -216,25 +213,23 @@ virLogSetDefaultOutputToFile(const char *binary, bool privileged)
* Decides on what the default output (journald, file, stderr) should be
* according to @binary, @godaemon, @privileged. This function should be run
* exactly once at daemon startup, so no locks are used.
*
* Returns 0 on success, -1 in case of a failure.
*/
int
void
virLogSetDefaultOutput(const char *binary, bool godaemon, bool privileged)
{
bool have_journald = access("/run/systemd/journal/socket", W_OK) >= 0;
if (godaemon) {
if (have_journald)
return virLogSetDefaultOutputToJournald();
virLogSetDefaultOutputToJournald();
else
virLogSetDefaultOutputToFile(binary, privileged);
} else {
if (!isatty(STDIN_FILENO) && have_journald)
return virLogSetDefaultOutputToJournald();
return virLogSetDefaultOutputToStderr();
virLogSetDefaultOutputToJournald();
else
virLogSetDefaultOutputToStderr();
}
return virLogSetDefaultOutputToFile(binary, privileged);
}
@ -443,15 +438,13 @@ virLogOutputListFree(virLogOutputPtr *list, int count)
}
static int
static void
virLogFormatString(char **msg,
int linenr,
const char *funcname,
virLogPriority priority,
const char *str)
{
int ret;
/*
* Be careful when changing the following log message formatting, we rely
* on it when stripping libvirt debug messages from qemu log files. So when
@ -460,44 +453,38 @@ virLogFormatString(char **msg,
* to just grep for it to find the right place.
*/
if ((funcname != NULL)) {
ret = virAsprintfQuiet(msg, "%llu: %s : %s:%d : %s\n",
*msg = g_strdup_printf("%llu: %s : %s:%d : %s\n",
virThreadSelfID(), virLogPriorityString(priority),
funcname, linenr, str);
} else {
ret = virAsprintfQuiet(msg, "%llu: %s : %s\n",
*msg = g_strdup_printf("%llu: %s : %s\n",
virThreadSelfID(), virLogPriorityString(priority),
str);
}
return ret;
}
static int
static void
virLogVersionString(const char **rawmsg,
char **msg)
{
*rawmsg = VIR_LOG_VERSION_STRING;
return virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
}
/* Similar to virGetHostname() but avoids use of error
* reporting APIs or logging APIs, to prevent recursion
*/
static int
static void
virLogHostnameString(char **rawmsg,
char **msg)
{
char *hoststr;
if (virAsprintfQuiet(&hoststr, "hostname: %s", virLogHostname) < 0)
return -1;
hoststr = g_strdup_printf("hostname: %s", virLogHostname);
if (virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr) < 0) {
VIR_FREE(hoststr);
return -1;
}
virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr);
*rawmsg = hoststr;
return 0;
}
@ -582,7 +569,6 @@ virLogVMessage(virLogSourcePtr source,
char *str = NULL;
char *msg = NULL;
char timestamp[VIR_TIME_STRING_BUFLEN];
int ret;
size_t i;
int saved_errno = errno;
@ -611,9 +597,7 @@ virLogVMessage(virLogSourcePtr source,
if (virVasprintfQuiet(&str, fmt, vargs) < 0)
goto cleanup;
ret = virLogFormatString(&msg, linenr, funcname, priority, str);
if (ret < 0)
goto cleanup;
virLogFormatString(&msg, linenr, funcname, priority, str);
if (virTimeStringNowRaw(timestamp) < 0)
timestamp[0] = '\0';
@ -630,17 +614,18 @@ virLogVMessage(virLogSourcePtr source,
const char *rawinitmsg;
char *hoststr = NULL;
char *initmsg = NULL;
if (virLogVersionString(&rawinitmsg, &initmsg) >= 0)
virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, rawinitmsg, initmsg,
virLogOutputs[i]->data);
virLogVersionString(&rawinitmsg, &initmsg);
virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, rawinitmsg, initmsg,
virLogOutputs[i]->data);
VIR_FREE(initmsg);
if (virLogHostnameString(&hoststr, &initmsg) >= 0)
virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, hoststr, initmsg,
virLogOutputs[i]->data);
virLogHostnameString(&hoststr, &initmsg);
virLogOutputs[i]->f(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, hoststr, initmsg,
virLogOutputs[i]->data);
VIR_FREE(hoststr);
VIR_FREE(initmsg);
virLogOutputs[i]->logInitMessage = false;
@ -656,17 +641,18 @@ virLogVMessage(virLogSourcePtr source,
const char *rawinitmsg;
char *hoststr = NULL;
char *initmsg = NULL;
if (virLogVersionString(&rawinitmsg, &initmsg) >= 0)
virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, rawinitmsg, initmsg,
(void *) STDERR_FILENO);
virLogVersionString(&rawinitmsg, &initmsg);
virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, rawinitmsg, initmsg,
(void *) STDERR_FILENO);
VIR_FREE(initmsg);
if (virLogHostnameString(&hoststr, &initmsg) >= 0)
virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, hoststr, initmsg,
(void *) STDERR_FILENO);
virLogHostnameString(&hoststr, &initmsg);
virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
__FILE__, __LINE__, __func__,
timestamp, NULL, hoststr, initmsg,
(void *) STDERR_FILENO);
VIR_FREE(hoststr);
VIR_FREE(initmsg);
logInitMessageStderr = false;
@ -703,9 +689,7 @@ virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED,
if (fd < 0)
return;
if (virAsprintfQuiet(&msg, "%s: %s", timestamp, str) < 0)
return;
msg = g_strdup_printf("%s: %s", timestamp, str);
ignore_value(safewrite(fd, msg, strlen(msg)));
VIR_FREE(msg);
}

View File

@ -181,7 +181,7 @@ void virLogFilterListFree(virLogFilterPtr *list, int count);
int virLogSetOutputs(const char *outputs);
int virLogSetFilters(const char *filters);
char *virLogGetDefaultOutput(void);
int virLogSetDefaultOutput(const char *fname, bool godaemon, bool privileged);
void virLogSetDefaultOutput(const char *fname, bool godaemon, bool privileged);
/*
* Internal logging API

View File

@ -290,7 +290,7 @@ virMacMapFileName(const char *dnsmasqStateDir,
{
char *filename;
ignore_value(virAsprintf(&filename, "%s/%s.macs", dnsmasqStateDir, bridge));
filename = g_strdup_printf("%s/%s.macs", dnsmasqStateDir, bridge);
return filename;
}

View File

@ -80,8 +80,7 @@ virMediatedDeviceGetSysfsDeviceAPI(virMediatedDevicePtr dev,
g_autofree char *file = NULL;
char *tmp = NULL;
if (virAsprintf(&file, "%s/mdev_type/device_api", dev->path) < 0)
return -1;
file = g_strdup_printf("%s/mdev_type/device_api", dev->path);
/* TODO - make this a generic method to access sysfs files for various
* kinds of devices
@ -215,8 +214,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
if (!dev_path)
return NULL;
if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0)
return NULL;
iommu_path = g_strdup_printf("%s/iommu_group", dev_path);
if (!virFileExists(iommu_path)) {
virReportSystemError(errno, _("failed to access '%s'"), iommu_path);
@ -228,8 +226,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
return NULL;
}
if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path)) < 0)
return NULL;
vfio_path = g_strdup_printf("/dev/vfio/%s", last_component(result_path));
return vfio_path;
}
@ -425,7 +422,7 @@ virMediatedDeviceGetSysfsPath(const char *uuidstr)
{
char *ret = NULL;
ignore_value(virAsprintf(&ret, MDEV_SYSFS_DEVICES "%s", uuidstr));
ret = g_strdup_printf(MDEV_SYSFS_DEVICES "%s", uuidstr);
return ret;
}

View File

@ -511,8 +511,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
char *phy_path = NULL;
int len;
if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1)
return -1;
pid = g_strdup_printf("%lld", (long long) pidInNs);
/* The 802.11 wireless devices only move together with their PHY. */
if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") < 0)
@ -1069,8 +1068,7 @@ int
virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname,
const char *file)
{
if (virAsprintf(pf_sysfs_device_link, SYSFS_NET_DIR "%s/%s", ifname, file) < 0)
return -1;
*pf_sysfs_device_link = g_strdup_printf(SYSFS_NET_DIR "%s/%s", ifname, file);
return 0;
}
@ -1078,9 +1076,8 @@ static int
virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname,
const char *file)
{
if (virAsprintf(pf_sysfs_device_link, SYSFS_NET_DIR "%s/device/%s", ifname,
file) < 0)
return -1;
*pf_sysfs_device_link = g_strdup_printf(SYSFS_NET_DIR "%s/device/%s", ifname,
file);
return 0;
}
@ -1102,8 +1099,7 @@ virNetDevIsPCIDevice(const char *devpath)
char *subsys = NULL;
bool ret = false;
if (virAsprintf(&subsys_link, "%s/subsystem", devpath) < 0)
return false;
subsys_link = g_strdup_printf("%s/subsystem", devpath);
if (!virFileExists(subsys_link))
goto cleanup;
@ -1404,8 +1400,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **vfname)
if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0)
goto cleanup;
if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0)
goto cleanup;
virtfnName = g_strdup_printf("virtfn%d", vf);
/* this provides the path to the VF's directory in sysfs,
* e.g. "/sys/class/net/enp2s0f0/virtfn3"
@ -1893,8 +1888,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf,
*/
if (pfDevName && saveVlan) {
if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) < 0)
goto cleanup;
filePath = g_strdup_printf("%s/%s_vf%d", stateDir, pfDevName, vf);
/* get admin MAC and vlan tag */
if (virNetDevGetVfConfig(pfDevName, vf, &oldMAC, &oldVlanTag) < 0)
@ -1910,8 +1904,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf,
}
} else {
if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0)
goto cleanup;
filePath = g_strdup_printf("%s/%s", stateDir, linkdev);
}
if (linkdev) {
@ -2016,8 +2009,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
*/
if (pfDevName) {
if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) < 0)
goto cleanup;
filePath = g_strdup_printf("%s/%s_vf%d", stateDir, pfDevName, vf);
if (linkdev && !virFileExists(filePath)) {
/* the device may have been stored in a file named for the
@ -2030,10 +2022,8 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
}
}
if (!pfDevName) {
if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0)
goto cleanup;
}
if (!pfDevName)
filePath = g_strdup_printf("%s/%s", stateDir, linkdev);
if (!virFileExists(filePath)) {
/* having no file to read is not necessarily an error, so we
@ -2913,8 +2903,7 @@ virNetDevRDMAFeature(const char *ifname,
if (virDirOpen(&dirp, SYSFS_INFINIBAND_DIR) < 0)
return -1;
if (virAsprintf(&eth_devpath, SYSFS_NET_DIR "%s/device/resource", ifname) < 0)
goto cleanup;
eth_devpath = g_strdup_printf(SYSFS_NET_DIR "%s/device/resource", ifname);
/* If /sys/class/net/<ifname>/device/resource doesn't exist it is not a PCI
* device and therefore it will not have RDMA. */
@ -2927,9 +2916,8 @@ virNetDevRDMAFeature(const char *ifname,
goto cleanup;
while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) {
if (virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resource",
dp->d_name) < 0)
continue;
ib_devpath = g_strdup_printf(SYSFS_INFINIBAND_DIR "%s/device/resource",
dp->d_name);
if (virFileReadAll(ib_devpath, RESOURCE_FILE_LEN, &ib_res_buf) > 0 &&
STREQ(eth_res_buf, ib_res_buf)) {
ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_RDMA));

View File

@ -114,8 +114,7 @@ virNetDevBandwidthManipulateFilter(const char *ifname,
}
/* u32 filters must have 800:: prefix. Don't ask. */
if (virAsprintf(&filter_id, "800::%u", id) < 0)
goto cleanup;
filter_id = g_strdup_printf("800::%u", id);
if (remove_old) {
int cmd_ret = 0;
@ -132,10 +131,9 @@ virNetDevBandwidthManipulateFilter(const char *ifname,
if (create_new) {
virMacAddrGetRaw(ifmac_ptr, ifmac);
if (virAsprintf(&mac[0], "0x%02x%02x%02x%02x", ifmac[2],
ifmac[3], ifmac[4], ifmac[5]) < 0 ||
virAsprintf(&mac[1], "0x%02x%02x", ifmac[0], ifmac[1]) < 0)
goto cleanup;
mac[0] = g_strdup_printf("0x%02x%02x%02x%02x", ifmac[2],
ifmac[3], ifmac[4], ifmac[5]);
mac[1] = g_strdup_printf("0x%02x%02x", ifmac[0], ifmac[1]);
virCommandFree(cmd);
cmd = virCommandNew(TC);
@ -232,14 +230,11 @@ virNetDevBandwidthSet(const char *ifname,
virNetDevBandwidthClear(ifname);
if (tx && tx->average) {
if (virAsprintf(&average, "%llukbps", tx->average) < 0)
goto cleanup;
if (tx->peak &&
(virAsprintf(&peak, "%llukbps", tx->peak) < 0))
goto cleanup;
if (tx->burst &&
(virAsprintf(&burst, "%llukb", tx->burst) < 0))
goto cleanup;
average = g_strdup_printf("%llukbps", tx->average);
if (tx->peak)
peak = g_strdup_printf("%llukbps", tx->peak);
if (tx->burst)
burst = g_strdup_printf("%llukb", tx->burst);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname, "root",
@ -362,10 +357,8 @@ virNetDevBandwidthSet(const char *ifname,
}
if (rx) {
if (virAsprintf(&average, "%llukbps", rx->average) < 0)
goto cleanup;
if (virAsprintf(&burst, "%llukb", rx->burst ? rx->burst : rx->average) < 0)
goto cleanup;
average = g_strdup_printf("%llukbps", rx->average);
burst = g_strdup_printf("%llukb", rx->burst ? rx->burst : rx->average);
virCommandFree(cmd);
cmd = virCommandNew(TC);
@ -575,13 +568,12 @@ virNetDevBandwidthPlug(const char *brname,
return -1;
}
if (virAsprintf(&class_id, "1:%x", id) < 0 ||
virAsprintf(&qdisc_id, "%x:", id) < 0 ||
virAsprintf(&floor, "%llukbps", bandwidth->in->floor) < 0 ||
virAsprintf(&ceil, "%llukbps", net_bandwidth->in->peak ?
net_bandwidth->in->peak :
net_bandwidth->in->average) < 0)
goto cleanup;
class_id = g_strdup_printf("1:%x", id);
qdisc_id = g_strdup_printf("%x:", id);
floor = g_strdup_printf("%llukbps", bandwidth->in->floor);
ceil = g_strdup_printf("%llukbps", net_bandwidth->in->peak ?
net_bandwidth->in->peak :
net_bandwidth->in->average);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "class", "add", "dev", brname, "parent", "1:1",
@ -640,9 +632,8 @@ virNetDevBandwidthUnplug(const char *brname,
return -1;
}
if (virAsprintf(&class_id, "1:%x", id) < 0 ||
virAsprintf(&qdisc_id, "%x:", id) < 0)
goto cleanup;
class_id = g_strdup_printf("1:%x", id);
qdisc_id = g_strdup_printf("%x:", id);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "del", "dev", brname,
@ -700,12 +691,11 @@ virNetDevBandwidthUpdateRate(const char *ifname,
char *rate = NULL;
char *ceil = NULL;
if (virAsprintf(&class_id, "1:%x", id) < 0 ||
virAsprintf(&rate, "%llukbps", new_rate) < 0 ||
virAsprintf(&ceil, "%llukbps", bandwidth->in->peak ?
bandwidth->in->peak :
bandwidth->in->average) < 0)
goto cleanup;
class_id = g_strdup_printf("1:%x", id);
rate = g_strdup_printf("%llukbps", new_rate);
ceil = g_strdup_printf("%llukbps", bandwidth->in->peak ?
bandwidth->in->peak :
bandwidth->in->average);
cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "class", "change", "dev", ifname,
@ -751,8 +741,7 @@ virNetDevBandwidthUpdateFilter(const char *ifname,
int ret = -1;
char *class_id = NULL;
if (virAsprintf(&class_id, "1:%x", id) < 0)
goto cleanup;
class_id = g_strdup_printf("1:%x", id);
if (virNetDevBandwidthManipulateFilter(ifname, ifmac_ptr, id,
class_id, true, true) < 0)

View File

@ -122,8 +122,7 @@ static int virNetDevBridgeSet(const char *brname,
{
g_autofree char *path = NULL;
if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname) < 0)
return -1;
path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname);
if (virFileExists(path)) {
char valuestr[INT_BUFSIZE_BOUND(value)];
@ -165,8 +164,7 @@ static int virNetDevBridgeGet(const char *brname,
g_autofree char *path = NULL;
VIR_AUTOCLOSE fd = -1;
if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname) < 0)
return -1;
path = g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramname);
if (virFileExists(path)) {
g_autofree char *valuestr = NULL;
@ -223,9 +221,8 @@ virNetDevBridgePortSet(const char *brname,
snprintf(valuestr, sizeof(valuestr), "%lu", value);
if (virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s",
brname, ifname, paramname) < 0)
return -1;
path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname,
paramname);
if (!virFileExists(path))
errno = EINVAL;
@ -251,9 +248,8 @@ virNetDevBridgePortGet(const char *brname,
g_autofree char *path = NULL;
g_autofree char *valuestr = NULL;
if (virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s",
brname, ifname, paramname) < 0)
return -1;
path = g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname,
paramname);
if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0)
return -1;

View File

@ -487,9 +487,8 @@ virNetDevIPGetAcceptRA(const char *ifname)
char *suffix;
int accept_ra = -1;
if (virAsprintf(&path, "/proc/sys/net/ipv6/conf/%s/accept_ra",
ifname ? ifname : "all") < 0)
return -1;
path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/accept_ra",
ifname ? ifname : "all");
if ((virFileReadAll(path, 512, &buf) < 0) ||
(virStrToLong_i(buf, &suffix, 10, &accept_ra) < 0))

View File

@ -294,8 +294,7 @@ virNetDevMacVLanIsMacvtap(const char *ifname)
if (virNetDevGetIndex(ifname, &ifindex) < 0)
return false;
if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
return false;
tapname = g_strdup_printf("/dev/tap%d", ifindex);
return virFileExists(tapname);
}
@ -393,8 +392,7 @@ virNetDevMacVLanTapOpen(const char *ifname,
if (virNetDevGetIndex(ifname, &ifindex) < 0)
return -1;
if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
goto cleanup;
tapname = g_strdup_printf("/dev/tap%d", ifindex);
for (i = 0; i < tapfdSize; i++) {
int fd = -1;

View File

@ -148,19 +148,13 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
virUUIDFormat(ovsport->interfaceID, ifuuidstr);
virUUIDFormat(vmuuid, vmuuidstr);
if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=\"%s\"",
macaddrstr) < 0)
return -1;
if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"",
ifuuidstr) < 0)
return -1;
if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=\"%s\"",
vmuuidstr) < 0)
return -1;
attachedmac_ex_id = g_strdup_printf("external-ids:attached-mac=\"%s\"",
macaddrstr);
ifaceid_ex_id = g_strdup_printf("external-ids:iface-id=\"%s\"", ifuuidstr);
vmid_ex_id = g_strdup_printf("external-ids:vm-id=\"%s\"", vmuuidstr);
if (ovsport->profileID[0] != '\0') {
if (virAsprintf(&profile_ex_id, "external-ids:port-profile=\"%s\"",
ovsport->profileID) < 0)
return -1;
profile_ex_id = g_strdup_printf("external-ids:port-profile=\"%s\"",
ovsport->profileID);
}
cmd = virCommandNew(OVSVSCTL);

View File

@ -395,8 +395,7 @@ int virNetDevTapCreate(char **ifname,
for (i = 0; i <= IF_MAXUNIT; i++) {
g_autofree char *newname = NULL;
if (virAsprintf(&newname, *ifname, i) < 0)
goto cleanup;
newname = g_strdup_printf(*ifname, i);
if (virNetDevExists(newname) == 0) {
newifname = g_steal_pointer(&newname);
@ -416,8 +415,7 @@ int virNetDevTapCreate(char **ifname,
if (tapfd) {
g_autofree char *dev_path = NULL;
if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0)
goto cleanup;
dev_path = g_strdup_printf("/dev/%s", ifr.ifr_name);
if ((*tapfd = open(dev_path, O_RDWR)) < 0) {
virReportSystemError(errno,

View File

@ -44,8 +44,7 @@ static int virNetDevVethExists(int devNum)
int ret;
g_autofree char *path = NULL;
if (virAsprintf(&path, SYSFS_NET_DIR "vnet%d/", devNum) < 0)
return -1;
path = g_strdup_printf(SYSFS_NET_DIR "vnet%d/", devNum);
ret = virFileExists(path) ? 1 : 0;
VIR_DEBUG("Checked dev vnet%d usage: %d", devNum, ret);
return ret;
@ -128,8 +127,7 @@ int virNetDevVethCreate(char** veth1, char** veth2)
if ((veth1num = virNetDevVethGetFreeNum(vethNum)) < 0)
goto cleanup;
if (virAsprintf(&veth1auto, "vnet%d", veth1num) < 0)
goto cleanup;
veth1auto = g_strdup_printf("vnet%d", veth1num);
vethNum = veth1num + 1;
}
if (!*veth2) {
@ -137,8 +135,7 @@ int virNetDevVethCreate(char** veth1, char** veth2)
if ((veth2num = virNetDevVethGetFreeNum(vethNum)) < 0)
goto cleanup;
if (virAsprintf(&veth2auto, "vnet%d", veth2num) < 0)
goto cleanup;
veth2auto = g_strdup_printf("vnet%d", veth2num);
vethNum = veth2num + 1;
}

View File

@ -538,23 +538,18 @@ virNumaGetHugePageInfoPath(char **path,
unsigned int page_size,
const char *suffix)
{
int ret;
if (node == -1) {
/* We are aiming at overall system info */
ret = virAsprintf(path,
HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
page_size, NULLSTR_EMPTY(suffix));
*path = g_strdup_printf(HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
page_size, NULLSTR_EMPTY(suffix));
} else {
/* We are aiming on specific NUMA node */
ret = virAsprintf(path,
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
HUGEPAGES_PREFIX "%ukB/%s",
node, page_size, NULLSTR_EMPTY(suffix));
*path = g_strdup_printf(HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
HUGEPAGES_PREFIX "%ukB/%s",
node, page_size, NULLSTR_EMPTY(suffix));
}
if (ret >= 0 && !virFileExists(*path)) {
ret = -1;
if (!virFileExists(*path)) {
if (node != -1) {
if (!virNumaNodeIsAvailable(node)) {
virReportError(VIR_ERR_OPERATION_FAILED,
@ -570,9 +565,10 @@ virNumaGetHugePageInfoPath(char **path,
_("page size %u is not available"),
page_size);
}
return -1;
}
return ret;
return 0;
}
static int
@ -582,9 +578,9 @@ virNumaGetHugePageInfoDir(char **path, int node)
*path = g_strdup(HUGEPAGES_SYSTEM_PREFIX);
return 0;
} else {
return virAsprintf(path,
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
node);
*path = g_strdup_printf(HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
node);
return 0;
}
}
@ -930,8 +926,7 @@ virNumaSetPagePoolSize(int node,
* all the pages we wanted. So do the second read to check.
*/
VIR_FREE(nr_buf);
if (virAsprintf(&nr_buf, "%llu", page_count) < 0)
return -1;
nr_buf = g_strdup_printf("%llu", page_count);
if (virFileWriteStr(nr_path, nr_buf, 0) < 0) {
virReportSystemError(errno,

View File

@ -213,7 +213,7 @@ virPCIDriverDir(const char *driver)
{
char *buffer;
ignore_value(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;
ignore_value(virAsprintf(&buffer, PCI_SYSFS "devices/%s/%s", device, file));
buffer = g_strdup_printf(PCI_SYSFS "devices/%s/%s", device, file);
return buffer;
}
@ -604,8 +604,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd)
* device is a VF, we just assume FLR works
*/
if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name) < 0)
return -1;
path = g_strdup_printf(PCI_SYSFS "devices/%s/physfn", dev->name);
found = virFileExists(path);
if (found) {
@ -1346,12 +1345,11 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr)
{
char *str;
ignore_value(virAsprintf(&str,
VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain,
addr->bus,
addr->slot,
addr->function));
str = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain,
addr->bus,
addr->slot,
addr->function);
return str;
}
@ -1373,14 +1371,10 @@ virPCIDeviceNew(unsigned int domain,
dev->address.slot = slot;
dev->address.function = function;
if (virAsprintf(&dev->name,
VIR_PCI_DEVICE_ADDRESS_FMT,
domain, bus, slot, function) < 0)
return NULL;
dev->name = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, domain, bus, slot,
function);
if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config",
dev->name) < 0)
return NULL;
dev->path = g_strdup_printf(PCI_SYSFS "devices/%s/config", dev->name);
if (!virFileExists(dev->path)) {
virReportSystemError(errno,
@ -1725,10 +1719,9 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
struct dirent *ent;
int direrr;
if (virAsprintf(&pcidir, "/sys/bus/pci/devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
dev->address.domain, dev->address.bus,
dev->address.slot, dev->address.function) < 0)
goto cleanup;
pcidir = g_strdup_printf("/sys/bus/pci/devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
dev->address.domain, dev->address.bus, dev->address.slot,
dev->address.function);
if (virDirOpen(&dir, pcidir) < 0)
goto cleanup;
@ -1745,8 +1738,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
STREQ(ent->d_name, "vendor") ||
STREQ(ent->d_name, "device") ||
STREQ(ent->d_name, "reset")) {
if (virAsprintf(&file, "%s/%s", pcidir, ent->d_name) < 0)
goto cleanup;
file = g_strdup_printf("%s/%s", pcidir, ent->d_name);
if ((actor)(dev, file, opaque) < 0)
goto cleanup;
}
@ -1778,10 +1770,8 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
struct dirent *ent;
int direrr;
if (virAsprintf(&groupPath,
PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT "/iommu_group/devices",
orig->domain, orig->bus, orig->slot, orig->function) < 0)
goto cleanup;
groupPath = g_strdup_printf(PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT "/iommu_group/devices",
orig->domain, orig->bus, orig->slot, orig->function);
if (virDirOpenQuiet(&groupDir, groupPath) < 0) {
/* just process the original device, nothing more */
@ -1928,10 +1918,8 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr)
const char *groupNumStr;
unsigned int groupNum;
if (virAsprintf(&devName,
VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain, addr->bus, addr->slot, addr->function) < 0)
return -1;
devName = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain, addr->bus,
addr->slot, addr->function);
if (!(devPath = virPCIFile(devName, "iommu_group")))
return -1;
@ -1981,9 +1969,7 @@ virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev)
dev->name, devPath);
return NULL;
}
if (virAsprintf(&groupDev, "/dev/vfio/%s",
last_component(groupPath)) < 0)
return NULL;
groupDev = g_strdup_printf("/dev/vfio/%s", last_component(groupPath));
return groupDev;
}
@ -2282,8 +2268,7 @@ virPCIGetVirtualFunctions(const char *sysfs_path,
*num_virtual_functions = 0;
*max_virtual_functions = 0;
if (virAsprintf(&totalvfs_file, "%s/sriov_totalvfs", sysfs_path) < 0)
goto error;
totalvfs_file = g_strdup_printf("%s/sriov_totalvfs", sysfs_path);
if (virFileExists(totalvfs_file)) {
char *end = NULL; /* so that terminating \n doesn't create error */
@ -2300,8 +2285,8 @@ virPCIGetVirtualFunctions(const char *sysfs_path,
do {
g_autofree char *device_link = NULL;
/* look for virtfn%d links until one isn't found */
if (virAsprintf(&device_link, "%s/virtfn%zu", sysfs_path, *num_virtual_functions) < 0)
goto error;
device_link = g_strdup_printf("%s/virtfn%zu", sysfs_path,
*num_virtual_functions);
if (!virFileExists(device_link))
break;
@ -2342,9 +2327,7 @@ virPCIIsVirtualFunction(const char *vf_sysfs_device_link)
{
g_autofree char *vf_sysfs_physfn_link = NULL;
if (virAsprintf(&vf_sysfs_physfn_link, "%s/physfn",
vf_sysfs_device_link) < 0)
return -1;
vf_sysfs_physfn_link = g_strdup_printf("%s/physfn", vf_sysfs_device_link);
return virFileExists(vf_sysfs_physfn_link);
}
@ -2402,9 +2385,8 @@ virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
int
virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link)
{
if (virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
virPCIDeviceName) < 0)
return -1;
*pci_sysfs_device_link = g_strdup_printf(PCI_SYSFS "devices/%s",
virPCIDeviceName);
return 0;
}
@ -2412,11 +2394,8 @@ int
virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr addr,
char **pci_sysfs_device_link)
{
if (virAsprintf(pci_sysfs_device_link,
PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain, addr->bus,
addr->slot, addr->function) < 0)
return -1;
*pci_sysfs_device_link = g_strdup_printf(PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain,
addr->bus, addr->slot, addr->function);
return 0;
}
@ -2601,8 +2580,7 @@ virPCIGetMdevTypes(const char *sysfspath,
size_t ntypes = 0;
size_t i;
if (virAsprintf(&types_path, "%s/mdev_supported_types", sysfspath) < 0)
return -1;
types_path = g_strdup_printf("%s/mdev_supported_types", sysfspath);
if ((dirret = virDirOpenIfExists(&dir, types_path)) < 0)
goto cleanup;
@ -2615,8 +2593,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 */
if (virAsprintf(&tmppath, "%s/%s", types_path, entry->d_name) < 0)
goto cleanup;
tmppath = g_strdup_printf("%s/%s", types_path, entry->d_name);
if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0)
goto cleanup;

View File

@ -226,8 +226,7 @@ int virPidFileReadPathIfAlive(const char *path,
goto cleanup;
}
if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) < 0)
return -ENOMEM;
procPath = g_strdup_printf("/proc/%lld/exe", (long long)retPid);
if ((ret = virFileIsLink(procPath)) < 0)
return ret;
@ -488,8 +487,7 @@ virPidFileConstructPath(bool privileged,
"%s", _("No runstatedir specified"));
return -1;
}
if (virAsprintf(pidfile, "%s/%s.pid", runstatedir, progname) < 0)
return -1;
*pidfile = g_strdup_printf("%s/%s.pid", runstatedir, progname);
} else {
if (!(rundir = virGetUserRuntimeDirectory()))
return -1;
@ -501,8 +499,7 @@ virPidFileConstructPath(bool privileged,
return -1;
}
if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0)
return -1;
*pidfile = g_strdup_printf("%s/%s.pid", rundir, progname);
}
return 0;

View File

@ -129,13 +129,13 @@ virProcessTranslateStatus(int status)
{
char *buf;
if (WIFEXITED(status)) {
ignore_value(virAsprintfQuiet(&buf, _("exit status %d"),
WEXITSTATUS(status)));
buf = g_strdup_printf(_("exit status %d"),
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
ignore_value(virAsprintfQuiet(&buf, _("fatal signal %d"),
WTERMSIG(status)));
buf = g_strdup_printf(_("fatal signal %d"),
WTERMSIG(status));
} else {
ignore_value(virAsprintfQuiet(&buf, _("invalid value %d"), status));
buf = g_strdup_printf(_("invalid value %d"), status);
}
return buf;
}
@ -586,8 +586,7 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
*npids = 0;
*pids = NULL;
if (virAsprintf(&taskPath, "/proc/%llu/task", (long long) pid) < 0)
goto cleanup;
taskPath = g_strdup_printf("/proc/%llu/task", (long long)pid);
if (virDirOpen(&dir, taskPath) < 0)
goto cleanup;
@ -632,10 +631,7 @@ int virProcessGetNamespaces(pid_t pid,
int fd;
g_autofree char *nsfile = NULL;
if (virAsprintf(&nsfile, "/proc/%llu/ns/%s",
(long long) pid,
ns[i]) < 0)
goto cleanup;
nsfile = g_strdup_printf("/proc/%llu/ns/%s", (long long)pid, ns[i]);
if ((fd = open(nsfile, O_RDONLY)) >= 0) {
if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) {
@ -954,8 +950,7 @@ int virProcessGetStartTime(pid_t pid,
g_autofree char *buf = NULL;
VIR_AUTOSTRINGLIST tokens = NULL;
if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0)
return -1;
filename = g_strdup_printf("/proc/%llu/stat", (long long)pid);
if ((len = virFileReadAll(filename, 1024, &buf)) < 0)
return -1;
@ -1054,8 +1049,7 @@ static int virProcessNamespaceHelper(pid_t pid G_GNUC_UNUSED,
int ret = -1;
g_autofree char *path = NULL;
if (virAsprintf(&path, "/proc/%lld/ns/mnt", (long long) data->pid) < 0)
goto cleanup;
path = g_strdup_printf("/proc/%lld/ns/mnt", (long long)data->pid);
if ((fd = open(path, O_RDONLY)) < 0) {
virReportSystemError(errno, "%s",

View File

@ -89,8 +89,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
member = virJSONValueArrayGet((virJSONValuePtr) array, i);
g_autofree char *prefix = NULL;
if (virAsprintf(&prefix, "%s.%zu", key, i) < 0)
return 0;
prefix = g_strdup_printf("%s.%zu", key, i);
if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf,
virQEMUBuildCommandLineJSONArrayNumbered,
@ -113,8 +112,7 @@ virQEMUBuildCommandLineJSONIterate(const char *key,
if (data->prefix) {
g_autofree char *tmpkey = NULL;
if (virAsprintf(&tmpkey, "%s.%s", data->prefix, key) < 0)
return -1;
tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
data->arrayFunc, false);

View File

@ -194,8 +194,7 @@ virRandomGenerateWWN(char **wwn,
return -1;
}
if (virAsprintf(wwn, "5" "%s%09llx", oui,
(unsigned long long)virRandomBits(36)) < 0)
return -1;
*wwn = g_strdup_printf("5" "%s%09llx", oui,
(unsigned long long)virRandomBits(36));
return 0;
}

View File

@ -2319,8 +2319,7 @@ virResctrlDeterminePath(const char *parentpath,
return NULL;
}
if (virAsprintf(&path, "%s/%s-%s", parentpath, prefix, id) < 0)
return NULL;
path = g_strdup_printf("%s/%s-%s", parentpath, prefix, id);
return path;
}
@ -2416,8 +2415,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
if (!alloc_str)
goto cleanup;
if (virAsprintf(&schemata_path, "%s/schemata", alloc->path) < 0)
goto cleanup;
schemata_path = g_strdup_printf("%s/schemata", alloc->path);
VIR_DEBUG("Writing resctrl schemata '%s' into '%s'", alloc_str, schemata_path);
if (virFileWriteStr(schemata_path, alloc_str, 0) < 0) {
@ -2451,11 +2449,9 @@ virResctrlAddPID(const char *path,
return -1;
}
if (virAsprintf(&tasks, "%s/tasks", path) < 0)
return -1;
tasks = g_strdup_printf("%s/tasks", path);
if (virAsprintf(&pidstr, "%lld", (long long int) pid) < 0)
goto cleanup;
pidstr = g_strdup_printf("%lld", (long long int)pid);
if (virFileWriteStr(tasks, pidstr, 0) < 0) {
virReportSystemError(errno,
@ -2566,8 +2562,7 @@ virResctrlMonitorDeterminePath(virResctrlMonitorPtr monitor,
return 0;
}
if (virAsprintf(&parentpath, "%s/mon_groups", monitor->alloc->path) < 0)
return -1;
parentpath = g_strdup_printf("%s/mon_groups", monitor->alloc->path);
monitor->path = virResctrlDeterminePath(parentpath, machinename,
monitor->id);
@ -2699,8 +2694,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
return -1;
}
if (virAsprintf(&datapath, "%s/mon_data", monitor->path) < 0)
return -1;
datapath = g_strdup_printf("%s/mon_data", monitor->path);
if (virDirOpen(&dirp, datapath) < 0)
goto cleanup;
@ -2717,8 +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.
*/
if (virAsprintf(&filepath, "%s/%s", datapath, ent->d_name) < 0)
goto cleanup;
filepath = g_strdup_printf("%s/%s", datapath, ent->d_name);
if (!virFileIsDir(filepath))
continue;

View File

@ -195,8 +195,7 @@ virRotatingFileWriterDelete(virRotatingFileWriterPtr file)
for (i = 0; i < file->maxbackup; i++) {
char *oldpath;
if (virAsprintf(&oldpath, "%s.%zu", file->basepath, i) < 0)
return -1;
oldpath = g_strdup_printf("%s.%zu", file->basepath, i);
if (unlink(oldpath) < 0 &&
errno != ENOENT) {
@ -308,8 +307,7 @@ virRotatingFileReaderNew(const char *path,
for (i = 0; i < maxbackup; i++) {
char *tmppath;
if (virAsprintf(&tmppath, "%s.%zu", path, i) < 0)
goto error;
tmppath = g_strdup_printf("%s.%zu", path, i);
file->entries[file->nentries - (i + 2)] = virRotatingFileReaderEntryNew(tmppath);
VIR_FREE(tmppath);
@ -382,15 +380,13 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr file)
goto cleanup;
}
} else {
if (virAsprintf(&nextpath, "%s.%zu", file->basepath, file->maxbackup - 1) < 0)
return -1;
nextpath = g_strdup_printf("%s.%zu", file->basepath, file->maxbackup - 1);
for (i = file->maxbackup; i > 0; i--) {
if (i == 1) {
thispath = g_strdup(file->basepath);
} else {
if (virAsprintf(&thispath, "%s.%zu", file->basepath, i - 2) < 0)
goto cleanup;
thispath = g_strdup_printf("%s.%zu", file->basepath, i - 2);
}
VIR_DEBUG("Rollover %s -> %s", thispath, nextpath);

View File

@ -117,10 +117,8 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
return NULL;
if (virAsprintf(&path,
"%s/%d:%u:%u:%llu/scsi_generic",
prefix, adapter_id, bus, target, unit) < 0)
return NULL;
path = g_strdup_printf("%s/%d:%u:%u:%llu/scsi_generic", prefix, adapter_id,
bus, target, unit);
if (virDirOpen(&dir, path) < 0)
goto cleanup;
@ -156,10 +154,8 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
return NULL;
if (virAsprintf(&path,
"%s/%d:%u:%u:%llu/block",
prefix, adapter_id, bus, target, unit) < 0)
return NULL;
path = g_strdup_printf("%s/%d:%u:%u:%llu/block", prefix, adapter_id, bus,
target, unit);
if (virDirOpen(&dir, path) < 0)
goto cleanup;
@ -206,11 +202,10 @@ virSCSIDeviceNew(const char *sysfs_prefix,
if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0)
return NULL;
if (virAsprintf(&dev->name, "%d:%u:%u:%llu", dev->adapter,
dev->bus, dev->target, dev->unit) < 0 ||
virAsprintf(&dev->sg_path, "%s/%s",
sysfs_prefix ? sysfs_prefix : "/dev", sg) < 0)
return NULL;
dev->name = g_strdup_printf("%d:%u:%u:%llu", dev->adapter,
dev->bus, dev->target, dev->unit);
dev->sg_path = g_strdup_printf("%s/%s",
sysfs_prefix ? sysfs_prefix : "/dev", sg);
if (!virFileExists(dev->sg_path)) {
virReportSystemError(errno,
@ -219,11 +214,8 @@ virSCSIDeviceNew(const char *sysfs_prefix,
return NULL;
}
if (virAsprintf(&vendor_path,
"%s/%s/vendor", prefix, dev->name) < 0 ||
virAsprintf(&model_path,
"%s/%s/model", prefix, dev->name) < 0)
return NULL;
vendor_path = g_strdup_printf("%s/%s/vendor", prefix, dev->name);
model_path = g_strdup_printf("%s/%s/model", prefix, dev->name);
if (virFileReadAll(vendor_path, 1024, &vendor) < 0)
return NULL;
@ -234,8 +226,7 @@ virSCSIDeviceNew(const char *sysfs_prefix,
virTrimSpaces(vendor, NULL);
virTrimSpaces(model, NULL);
if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0)
return NULL;
dev->id = g_strdup_printf("%s:%s", vendor, model);
return g_steal_pointer(&dev);
}

View File

@ -52,10 +52,8 @@ virSCSIHostGetUniqueId(const char *sysfs_prefix,
char *buf = NULL;
int unique_id;
if (virAsprintf(&sysfs_path, "%s/host%d/unique_id",
sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH,
host) < 0)
return -1;
sysfs_path = g_strdup_printf("%s/host%d/unique_id",
sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host);
if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
goto cleanup;
@ -118,8 +116,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix,
if (!virFileIsLink(entry->d_name))
continue;
if (virAsprintf(&host_link, "%s/%s", prefix, entry->d_name) < 0)
goto cleanup;
host_link = g_strdup_printf("%s/%s", prefix, entry->d_name);
if (virFileResolveLink(host_link, &host_path) < 0)
goto cleanup;
@ -132,9 +129,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix,
VIR_FREE(host_link);
VIR_FREE(host_path);
if (virAsprintf(&unique_path, "%s/%s/unique_id", prefix,
entry->d_name) < 0)
goto cleanup;
unique_path = g_strdup_printf("%s/%s/unique_id", prefix, entry->d_name);
if (!virFileExists(unique_path)) {
VIR_FREE(unique_path);
@ -240,9 +235,8 @@ virSCSIHostGetNameByParentaddr(unsigned int domain,
char *name = NULL;
char *parentaddr = NULL;
if (virAsprintf(&parentaddr, "%04x:%02x:%02x.%01x",
domain, bus, slot, function) < 0)
goto cleanup;
parentaddr = g_strdup_printf("%04x:%02x:%02x.%01x", domain, bus, slot,
function);
if (!(name = virSCSIHostFindByPCI(NULL, parentaddr, unique_id))) {
virReportError(VIR_ERR_XML_ERROR,
_("Failed to find scsi_host using PCI '%s' "

View File

@ -255,9 +255,7 @@ virSCSIVHostDeviceNew(const char *name)
dev->name = g_strdup(name);
if (virAsprintf(&dev->path, "%s/%s",
SYSFS_VHOST_SCSI_DEVICES, name) < 0)
return NULL;
dev->path = g_strdup_printf("%s/%s", SYSFS_VHOST_SCSI_DEVICES, name);
VIR_DEBUG("%s: initialized", dev->name);

View File

@ -477,9 +477,8 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
* nicely for UNIX sockets */
if (addr->data.sa.sa_family == AF_UNIX) {
if (withService) {
if (virAsprintf(&addrstr, VIR_LOOPBACK_IPV4_ADDR"%s0",
separator ? separator : ":") < 0)
return NULL;
addrstr = g_strdup_printf(VIR_LOOPBACK_IPV4_ADDR "%s0",
separator ? separator : ":");
} else {
addrstr = g_strdup(VIR_LOOPBACK_IPV4_ADDR);
}
@ -503,16 +502,12 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
* a.b.c.d;port or e:f:g:h:i:j:k:l;port, so use square brackets for
* IPv6 only if no separator is passed to the function
*/
if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET6) {
if (virAsprintf(&ipv6_host, "[%s]", host) < 0)
return NULL;
}
if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET6)
ipv6_host = g_strdup_printf("[%s]", host);
if (virAsprintf(&addrstr, "%s%s%s",
ipv6_host ? ipv6_host : host,
separator ? separator : ":", port) == -1) {
return NULL;
}
addrstr = g_strdup_printf("%s%s%s",
ipv6_host ? ipv6_host : host,
separator ? separator : ":", port);
} else {
addrstr = g_strdup(host);
}

View File

@ -1536,7 +1536,7 @@ virStorageFileGetNPIVKey(const char *path,
*tmp = '\0';
if (*serial != '\0' && *port != '\0')
ignore_value(virAsprintf(key, "%s_PORT%s", serial, port));
*key = g_strdup_printf("%s_PORT%s", serial, port);
}
return 0;
@ -2610,11 +2610,9 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
}
if (STRNEQ(dirname, "/")) {
if (virAsprintf(&def->path, "%s/%s", dirname, rel) < 0)
return NULL;
def->path = g_strdup_printf("%s/%s", dirname, rel);
} else {
if (virAsprintf(&def->path, "/%s", rel) < 0)
return NULL;
def->path = g_strdup_printf("/%s", rel);
}
if (virStorageSourceGetActualType(parent) == VIR_STORAGE_TYPE_NETWORK) {
@ -3272,8 +3270,7 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
*port = '\0';
}
if (virAsprintf(&src->path, "%s/%s", target, lun) < 0)
return -1;
src->path = g_strdup_printf("%s/%s", target, lun);
/* Libvirt doesn't handle inline authentication. Make the caller aware. */
if (virJSONValueObjectGetString(json, "user") ||
@ -4182,8 +4179,7 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top,
VIR_FREE(path);
if (virAsprintf(&path, "%s%s", tmp, next->relPath) < 0)
return -1;
path = g_strdup_printf("%s%s", tmp, next->relPath);
VIR_FREE(tmp);

View File

@ -707,18 +707,15 @@ int
virDoubleToStr(char **strp, double number)
{
virLocale oldlocale;
int rc;
if (virLocaleSetRaw(&oldlocale) < 0)
return -1;
rc = virAsprintf(strp, "%lf", number);
*strp = g_strdup_printf("%lf", number);
virLocaleRevert(&oldlocale);
virLocaleFixupRadix(strp);
if (rc < 0)
return -1;
return 0;
}

View File

@ -111,7 +111,7 @@ int virStrToDouble(char const *s,
G_GNUC_WARN_UNUSED_RESULT;
int virDoubleToStr(char **strp, double number)
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
ATTRIBUTE_NONNULL(1);
void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);

View File

@ -295,8 +295,7 @@ int virSystemdCreateMachine(const char *name,
ret = -1;
if (virAsprintf(&creatorname, "libvirt-%s", drivername) < 0)
goto cleanup;
creatorname = g_strdup_printf("libvirt-%s", drivername);
if (partition) {
if (!(slicename = virSystemdMakeSliceName(partition)))

View File

@ -59,33 +59,31 @@ virTPMCreateCancelPath(const char *devpath)
const char *dev;
const char *prefix[] = {"misc/", "tpm/"};
size_t i;
if (devpath) {
dev = strrchr(devpath, '/');
if (dev) {
dev++;
for (i = 0; i < G_N_ELEMENTS(prefix); i++) {
if (virAsprintf(&path, "/sys/class/%s%s/device/cancel",
prefix[i], dev) < 0)
goto cleanup;
if (virFileExists(path))
break;
VIR_FREE(path);
}
if (!path)
path = g_strdup("/dev/null");
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("TPM device path %s is invalid"), devpath);
}
} else {
if (!devpath) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing TPM device path"));
return NULL;
}
cleanup:
if (!(dev = strrchr(devpath, '/'))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("TPM device path %s is invalid"), devpath);
return NULL;
}
dev++;
for (i = 0; i < G_N_ELEMENTS(prefix); i++) {
path = g_strdup_printf("/sys/class/%s%s/device/cancel", prefix[i],
dev);
if (virFileExists(path))
break;
VIR_FREE(path);
}
if (!path)
path = g_strdup("/dev/null");
return path;
}

View File

@ -176,22 +176,22 @@ virTypedParameterToString(virTypedParameterPtr param)
switch (param->type) {
case VIR_TYPED_PARAM_INT:
ignore_value(virAsprintf(&value, "%d", param->value.i));
value = g_strdup_printf("%d", param->value.i);
break;
case VIR_TYPED_PARAM_UINT:
ignore_value(virAsprintf(&value, "%u", param->value.ui));
value = g_strdup_printf("%u", param->value.ui);
break;
case VIR_TYPED_PARAM_LLONG:
ignore_value(virAsprintf(&value, "%lld", param->value.l));
value = g_strdup_printf("%lld", param->value.l);
break;
case VIR_TYPED_PARAM_ULLONG:
ignore_value(virAsprintf(&value, "%llu", param->value.ul));
value = g_strdup_printf("%llu", param->value.ul);
break;
case VIR_TYPED_PARAM_DOUBLE:
ignore_value(virAsprintf(&value, "%g", param->value.d));
value = g_strdup_printf("%g", param->value.d);
break;
case VIR_TYPED_PARAM_BOOLEAN:
ignore_value(virAsprintf(&value, "%d", param->value.b));
value = g_strdup_printf("%d", param->value.b);
break;
case VIR_TYPED_PARAM_STRING:
value = g_strdup(param->value.s);

View File

@ -234,8 +234,7 @@ virURIFormat(virURIPtr uri)
if (xmluri.server != NULL &&
strchr(xmluri.server, ':') != NULL) {
if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0)
return NULL;
tmpserver = g_strdup_printf("[%s]", xmluri.server);
xmluri.server = tmpserver;
}

View File

@ -85,14 +85,11 @@ VIR_ONCE_GLOBAL_INIT(virUSB);
static int virUSBSysReadFile(const char *f_name, const char *d_name,
int base, unsigned int *value)
{
int tmp;
g_autofree char *buf = NULL;
g_autofree char *filename = NULL;
char *ignore = NULL;
tmp = virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name);
if (tmp < 0)
return -1;
filename = g_strdup_printf(USB_SYSFS "/devices/%s/%s", d_name, f_name);
if (virFileReadAll(filename, 1024, &buf) < 0)
return -1;
@ -315,7 +312,6 @@ virUSBDeviceNew(unsigned int bus,
const char *vroot)
{
virUSBDevicePtr dev;
int rc;
if (VIR_ALLOC(dev) < 0)
return NULL;
@ -333,16 +329,11 @@ virUSBDeviceNew(unsigned int bus,
}
if (vroot) {
rc = virAsprintf(&dev->path, "%s/%03d/%03d",
vroot, dev->bus, dev->dev);
dev->path = g_strdup_printf("%s/%03d/%03d",
vroot, dev->bus, dev->dev);
} else {
rc = virAsprintf(&dev->path, USB_DEVFS "%03d/%03d",
dev->bus, dev->dev);
}
if (rc < 0) {
virUSBDeviceFree(dev);
return NULL;
dev->path = g_strdup_printf(USB_DEVFS "%03d/%03d",
dev->bus, dev->dev);
}
/* XXX fixme. this should be product/vendor */

View File

@ -744,11 +744,11 @@ static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir)
char *home = NULL;
if (path && path[0]) {
ignore_value(virAsprintf(&ret, "%s/libvirt", path));
ret = g_strdup_printf("%s/libvirt", path);
} else {
home = virGetUserDirectory();
if (home)
ignore_value(virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir));
ret = g_strdup_printf("%s/%s/libvirt", home, xdgdefdir);
}
VIR_FREE(home);
@ -774,7 +774,7 @@ char *virGetUserRuntimeDirectory(void)
} else {
char *ret;
ignore_value(virAsprintf(&ret, "%s/libvirt", path));
ret = g_strdup_printf("%s/libvirt", path);
return ret;
}
}
@ -1587,9 +1587,9 @@ virGetUnprivSGIOSysfsPath(const char *path,
return NULL;
}
ignore_value(virAsprintf(&sysfs_path, "%s/%d:%d/queue/unpriv_sgio",
sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH,
maj, min));
sysfs_path = g_strdup_printf("%s/%d:%d/queue/unpriv_sgio",
sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH,
maj, min);
return sysfs_path;
}
@ -1612,8 +1612,7 @@ virSetDeviceUnprivSGIO(const char *path,
goto cleanup;
}
if (virAsprintf(&val, "%d", unpriv_sgio) < 0)
goto cleanup;
val = g_strdup_printf("%d", unpriv_sgio);
if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
@ -1878,8 +1877,7 @@ virHostGetDRMRenderNode(void)
goto cleanup;
}
if (virAsprintf(&ret, "%s/%s", driPath, ent->d_name) < 0)
goto cleanup;
ret = g_strdup_printf("%s/%s", driPath, ent->d_name);
cleanup:
VIR_DIR_CLOSE(driDir);

View File

@ -52,10 +52,8 @@ virVHBAPathExists(const char *sysfs_prefix,
char *sysfs_path = NULL;
bool ret = false;
if (virAsprintf(&sysfs_path, "%s/host%d",
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
host) < 0)
return false;
sysfs_path = g_strdup_printf("%s/host%d",
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host);
if (virFileExists(sysfs_path))
ret = true;
@ -85,24 +83,17 @@ virVHBAIsVportCapable(const char *sysfs_prefix,
char *fc_host_path = NULL;
bool ret = false;
if (virAsprintf(&fc_host_path,
"%s/host%d/%s",
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
host,
"vport_create") < 0)
return false;
fc_host_path = g_strdup_printf("%s/host%d/%s",
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host,
"vport_create");
if (virAsprintf(&scsi_host_path,
"%s/host%d/%s",
sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH,
host,
"vport_create") < 0)
goto cleanup;
scsi_host_path = g_strdup_printf("%s/host%d/%s",
sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host,
"vport_create");
if (virFileExists(fc_host_path) || virFileExists(scsi_host_path))
ret = true;
cleanup:
VIR_FREE(fc_host_path);
VIR_FREE(scsi_host_path);
return ret;
@ -129,10 +120,8 @@ virVHBAGetConfig(const char *sysfs_prefix,
char *buf = NULL;
char *result = NULL;
if (virAsprintf(&sysfs_path, "%s/host%d/%s",
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
host, entry) < 0)
goto cleanup;
sysfs_path = g_strdup_printf("%s/host%d/%s",
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH, host, entry);
if (!virFileExists(sysfs_path))
goto cleanup;
@ -269,15 +258,13 @@ virVHBAManageVport(const int parent_host,
goto cleanup;
}
if (virAsprintf(&operation_path, "%s/host%d/%s",
SYSFS_FC_HOST_PATH, parent_host, operation_file) < 0)
goto cleanup;
operation_path = g_strdup_printf("%s/host%d/%s", SYSFS_FC_HOST_PATH,
parent_host, operation_file);
if (!virFileExists(operation_path)) {
VIR_FREE(operation_path);
if (virAsprintf(&operation_path, "%s/host%d/%s",
SYSFS_SCSI_HOST_PATH, parent_host, operation_file) < 0)
goto cleanup;
operation_path = g_strdup_printf("%s/host%d/%s", SYSFS_SCSI_HOST_PATH,
parent_host, operation_file);
if (!virFileExists(operation_path)) {
virReportError(VIR_ERR_OPERATION_INVALID,
@ -294,8 +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. */
if (virAsprintf(&vport_name, "%s:%s", wwpn, wwnn) < 0)
goto cleanup;
vport_name = g_strdup_printf("%s:%s", wwpn, wwnn);
if (virFileWriteStr(operation_path, vport_name, 0) == 0)
ret = 0;
@ -335,8 +321,7 @@ vhbaReadCompareWWN(const char *prefix,
char *p;
int ret = -1;
if (virAsprintf(&path, "%s/%s/%s", prefix, d_name, f_name) < 0)
return -1;
path = g_strdup_printf("%s/%s/%s", prefix, d_name, f_name);
if (!virFileExists(path)) {
ret = 0;
@ -440,9 +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 */
if (virAsprintf(&vport_create_path, "%s/%s/vport_create", prefix,
entry->d_name) < 0)
goto cleanup;
vport_create_path = g_strdup_printf("%s/%s/vport_create", prefix,
entry->d_name);
if (!virFileExists(vport_create_path))
continue;