These functions can't fail really. Drop checking of their retval
then.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/util/viraudit.c | 3 +-
src/util/virauth.c | 17 ++---
src/util/virauthconfig.c | 9 +--
src/util/vircgroup.c | 39 ++++-------
src/util/vircgroupv1.c | 102 ++++++++++-----------------
src/util/vircgroupv2.c | 97 +++++++++-----------------
src/util/virconf.c | 10 +--
src/util/virdevmapper.c | 7 +-
src/util/virdnsmasq.c | 39 ++++-------
src/util/virebtables.c | 5 +-
src/util/virerror.c | 3 +-
src/util/virfile.c | 39 ++++-------
src/util/virhostcpu.c | 11 ++-
src/util/virhostdev.c | 3 +-
src/util/virhostmem.c | 21 ++----
src/util/viriptables.c | 16 ++---
src/util/viriscsi.c | 6 +-
src/util/virjson.c | 12 ++--
src/util/virkmod.c | 3 +-
src/util/virlockspace.c | 2 +-
src/util/virlog.c | 120 ++++++++++++++------------------
src/util/virlog.h | 2 +-
src/util/virmacmap.c | 2 +-
src/util/virmdev.c | 11 ++-
src/util/virnetdev.c | 40 ++++-------
src/util/virnetdevbandwidth.c | 61 +++++++---------
src/util/virnetdevbridge.c | 16 ++---
src/util/virnetdevip.c | 5 +-
src/util/virnetdevmacvlan.c | 6 +-
src/util/virnetdevopenvswitch.c | 18 ++---
src/util/virnetdevtap.c | 6 +-
src/util/virnetdevveth.c | 9 +--
src/util/virnuma.c | 32 ++++-----
src/util/virpci.c | 86 +++++++++--------------
src/util/virpidfile.c | 9 +--
src/util/virprocess.c | 24 +++----
src/util/virqemu.c | 6 +-
src/util/virrandom.c | 5 +-
src/util/virresctrl.c | 21 ++----
src/util/virrotatingfile.c | 12 ++--
src/util/virscsi.c | 31 +++------
src/util/virscsihost.c | 18 ++---
src/util/virscsivhost.c | 4 +-
src/util/virsocketaddr.c | 19 ++---
src/util/virstoragefile.c | 14 ++--
src/util/virstring.c | 5 +-
src/util/virstring.h | 2 +-
src/util/virsystemd.c | 3 +-
src/util/virtpm.c | 44 ++++++------
src/util/virtypedparam.c | 12 ++--
src/util/viruri.c | 3 +-
src/util/virusb.c | 19 ++---
src/util/virutil.c | 18 +++--
src/util/virvhba.c | 52 +++++---------
54 files changed, 436 insertions(+), 743 deletions(-)
diff --git a/src/util/viraudit.c b/src/util/viraudit.c
index 9bf42824f6..9d423e8f53 100644
--- a/src/util/viraudit.c
+++ b/src/util/viraudit.c
@@ -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;
+ virAsprintf(&str, "%s=%s", key, value);
return str;
#endif
}
diff --git a/src/util/virauth.c b/src/util/virauth.c
index ddb46cc498..9ff639ffa8 100644
--- a/src/util/virauth.c
+++ b/src/util/virauth.c
@@ -69,8 +69,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
if (!(userdir = virGetUserConfigDirectory()))
return -1;
- if (virAsprintf(path, "%s/auth.conf", userdir) < 0)
- return -1;
+ virAsprintf(path, "%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;
- }
+ virAsprintf(&prompt, _("Enter username for %s [%s]"), hostname,
+ defaultUsername);
} else {
- if (virAsprintf(&prompt, _("Enter username for %s"), hostname) <
0)
- return NULL;
+ virAsprintf(&prompt, _("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;
- }
+ virAsprintf(&prompt, _("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 6a9001f2d8..b7263ebccb 100644
--- a/src/util/virauthconfig.c
+++ b/src/util/virauthconfig.c
@@ -113,13 +113,11 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
if (!hostname)
hostname = "localhost";
- if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0)
- return -1;
+ virAsprintf(&authgroup, "auth-%s-%s", service, hostname);
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
VIR_FREE(authgroup);
- if (virAsprintf(&authgroup, "auth-%s-%s", service,
"default") < 0)
- return -1;
+ virAsprintf(&authgroup, "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;
+ virAsprintf(&credgroup, "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 b46f20abfd..8545cd3049 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -206,8 +206,7 @@ virCgroupPartitionEscape(char **path)
if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0)
return rc;
- if (virAsprintf(&newstr, "_%s", *path) < 0)
- return -1;
+ virAsprintf(&newstr, "_%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;
+ virAsprintf(&procfile, "/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;
+ virAsprintf(&ret, "%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;
+ virAsprintf(&strval, "%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;
+ virAsprintf(&strval, "%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;
+ virAsprintf(&(*group)->path, "%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;
+ virAsprintf(&grpname, "%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;
+ virAsprintf(&name, "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;
+ virAsprintf(&name, "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;
- }
+ virAsprintf(&path, "%s/%s", grppath, ent->d_name);
+
rc = virCgroupRemoveRecursively(path);
if (rc != 0)
break;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 0820c5d638..d04fa521fc 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -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;
+ virAsprintf(&partname, "%s.libvirt-%s", name, drivername);
if (virCgroupPartitionEscape(&partname) < 0)
return false;
- if (virAsprintf(&partmachinename, "%s.libvirt-%s",
- machinename, drivername) < 0 ||
- virCgroupPartitionEscape(&partmachinename) < 0)
+ virAsprintf(&partmachinename, "%s.libvirt-%s",
+ machinename, drivername);
+
+ if (virCgroupPartitionEscape(&partmachinename) < 0)
return false;
if (!(scopename_old = virSystemdMakeScopeName(name, drivername, true)))
@@ -204,13 +203,10 @@ virCgroupV1CopyPlacement(virCgroupPtr group,
* 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;
+ virAsprintf(&group->legacy[i].placement, "%s%s%s",
+ parent->legacy[i].placement,
+ (STREQ(parent->legacy[i].placement, "/") ||
STREQ(path, "") ? "" : "/"),
+ path);
}
}
@@ -241,8 +237,7 @@ virCgroupV1ResolveMountLink(const char *mntDir,
return 0;
*dirName = '\0';
- if (virAsprintf(&linkSrc, "%s/%s", tmp, typeStr) < 0)
- return -1;
+ virAsprintf(&linkSrc, "%s/%s", tmp, typeStr);
*dirName = '/';
if (lstat(linkSrc, &sb) < 0) {
@@ -354,12 +349,9 @@ 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;
+ virAsprintf(&group->legacy[i].placement, "%s%s%s",
selfpath,
+ (STREQ(selfpath, "/") || STREQ(path, "")
? "" : "/"),
+ path);
}
}
}
@@ -524,11 +516,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;
+ virAsprintf(path, "%s%s/%s", group->legacy[controller].mountPoint,
+ group->legacy[controller].placement, NULLSTR_EMPTY(key));
return 0;
}
@@ -817,9 +806,7 @@ virCgroupV1BindMount(virCgroupPtr group,
return -1;
}
- if (virAsprintf(&opts,
- "mode=755,size=65536%s", mountopts) < 0)
- return -1;
+ virAsprintf(&opts, "mode=755,size=65536%s", mountopts);
if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC,
opts) < 0) {
virReportSystemError(errno,
@@ -834,10 +821,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;
+ virAsprintf(&src, "%s%s", oldroot,
group->legacy[i].mountPoint);
VIR_DEBUG("Create mount point '%s'",
group->legacy[i].mountPoint);
@@ -897,9 +881,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;
+ virAsprintf(&base, "%s%s", cgroup->legacy[i].mountPoint,
+ cgroup->legacy[i].placement);
if (virDirOpen(&dh, base) < 0)
goto cleanup;
@@ -907,8 +890,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;
+ virAsprintf(&entry, "%s/%s", base, de->d_name);
if (chown(entry, uid, gid) < 0) {
virReportSystemError(errno,
@@ -965,8 +947,7 @@ virCgroupV1SetBlkioWeight(virCgroupPtr group,
return -1;
}
- if (virAsprintf(&value, "%u", weight) < 0)
- return -1;
+ virAsprintf(&value, "%u", weight);
return virCgroupSetValueRaw(path, value);
}
@@ -1208,8 +1189,7 @@ virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(devPath)))
return -1;
- if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
- return -1;
+ virAsprintf(&str, "%s%d", blkstr, weight);
if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight_device", &path) < 0)
{
@@ -1276,8 +1256,7 @@ virCgroupV1SetBlkioDeviceReadIops(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%u", blkstr, riops) < 0)
- return -1;
+ virAsprintf(&str, "%s%u", blkstr, riops);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@@ -1328,8 +1307,7 @@ virCgroupV1SetBlkioDeviceWriteIops(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0)
- return -1;
+ virAsprintf(&str, "%s%u", blkstr, wiops);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@@ -1380,8 +1358,7 @@ virCgroupV1SetBlkioDeviceReadBps(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0)
- return -1;
+ virAsprintf(&str, "%s%llu", blkstr, rbps);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@@ -1432,8 +1409,7 @@ virCgroupV1SetBlkioDeviceWriteBps(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
- if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0)
- return -1;
+ virAsprintf(&str, "%s%llu", blkstr, wbps);
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
@@ -1784,17 +1760,16 @@ virCgroupV1AllowDevice(virCgroupPtr group,
if (major < 0)
majorstr = g_strdup("*");
- if (major >= 0 && virAsprintf(&majorstr, "%i", major) <
0)
- return -1;
+ else
+ virAsprintf(&majorstr, "%i", major);
if (minor < 0)
minorstr = g_strdup("*");
- if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) <
0)
- return -1;
+ else
+ virAsprintf(&minorstr, "%i", minor);
- if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
- virCgroupGetDevicePermsString(perms)) < 0)
- return -1;
+ virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
+ virCgroupGetDevicePermsString(perms));
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
@@ -1819,17 +1794,16 @@ virCgroupV1DenyDevice(virCgroupPtr group,
if (major < 0)
majorstr = g_strdup("*");
- if (major >= 0 && virAsprintf(&majorstr, "%i", major) <
0)
- return -1;
+ else
+ virAsprintf(&majorstr, "%i", major);
if (minor < 0)
minorstr = g_strdup("*");
- if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) <
0)
- return -1;
+ else
+ virAsprintf(&minorstr, "%i", minor);
- if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
- virCgroupGetDevicePermsString(perms)) < 0)
- return -1;
+ virAsprintf(&devstr, "%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 e976a8d241..f0ce4a48bc 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -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;
+ virAsprintf(&contFile, "%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;
- }
+ virAsprintf(&partmachinename, "%s.libvirt-%s", machinename,
drivername);
if (virCgroupPartitionEscape(&partmachinename) < 0)
return false;
@@ -166,12 +162,10 @@ virCgroupV2CopyPlacement(virCgroupPtr group,
* 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;
+ virAsprintf(&group->unified.placement, "%s%s%s",
+ parent->unified.placement,
+ (STREQ(parent->unified.placement, "/") || STREQ(path,
"") ? "" : "/"),
+ path);
}
return 0;
@@ -215,12 +209,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;
+ virAsprintf(&group->unified.placement, "%s%s%s", selfpath,
+ (STREQ(selfpath, "/") || STREQ(path, "") ?
"" : "/"), path);
return 0;
}
@@ -262,15 +252,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;
+ virAsprintf(&contFile, "%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;
+ virAsprintf(&contFile, "%s%s/cgroup.controllers",
+ group->unified.mountPoint,
+ NULLSTR_EMPTY(group->unified.placement));
}
rc = virFileReadAll(contFile, 1024 * 1024, &contStr);
@@ -357,11 +345,8 @@ virCgroupV2PathOfController(virCgroupPtr group,
return -1;
}
- if (virAsprintf(path, "%s%s/%s",
- group->unified.mountPoint,
- group->unified.placement,
- NULLSTR_EMPTY(key)) < 0)
- return -1;
+ virAsprintf(path, "%s%s/%s", group->unified.mountPoint,
+ group->unified.placement, NULLSTR_EMPTY(key));
return 0;
}
@@ -383,10 +368,7 @@ virCgroupV2EnableController(virCgroupPtr group,
g_autofree char *val = NULL;
g_autofree char *path = NULL;
- if (virAsprintf(&val, "+%s",
- virCgroupV2ControllerTypeToString(controller)) < 0) {
- return -1;
- }
+ virAsprintf(&val, "+%s",
virCgroupV2ControllerTypeToString(controller));
if (virCgroupPathOfController(parent, controller,
"cgroup.subtree_control", &path) < 0)
{
@@ -568,11 +550,9 @@ virCgroupV2BindMount(virCgroupPtr group,
return -1;
}
- if (virAsprintf(&opts, "mode=755,size=65536%s", mountopts) < 0)
- return -1;
+ virAsprintf(&opts, "mode=755,size=65536%s", mountopts);
- if (virAsprintf(&src, "%s%s", oldroot, group->unified.mountPoint)
< 0)
- return -1;
+ virAsprintf(&src, "%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'"),
@@ -592,10 +572,8 @@ virCgroupV2SetOwner(virCgroupPtr cgroup,
{
g_autofree char *base = NULL;
- if (virAsprintf(&base, "%s%s", cgroup->unified.mountPoint,
- cgroup->unified.placement) < 0) {
- return -1;
- }
+ virAsprintf(&base, "%s%s", cgroup->unified.mountPoint,
+ cgroup->unified.placement);
if (virFileChownFiles(base, uid, gid) < 0)
return -1;
@@ -639,8 +617,7 @@ virCgroupV2SetBlkioWeight(virCgroupPtr group,
return -1;
}
- if (virAsprintf(&value, format, weight) < 0)
- return -1;
+ virAsprintf(&value, format, weight);
return virCgroupSetValueRaw(path, value);
}
@@ -833,8 +810,7 @@ virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group,
if (!(blkstr = virCgroupGetBlockDevString(devPath)))
return -1;
- if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
- return -1;
+ virAsprintf(&str, "%s%d", blkstr, weight);
if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight", &path) < 0) {
@@ -903,11 +879,9 @@ virCgroupV2SetBlkioDeviceReadIops(virCgroupPtr group,
return -1;
if (riops == 0) {
- if (virAsprintf(&str, "%sriops=max", blkstr) < 0)
- return -1;
+ virAsprintf(&str, "%sriops=max", blkstr);
} else {
- if (virAsprintf(&str, "%sriops=%u", blkstr, riops) < 0)
- return -1;
+ virAsprintf(&str, "%sriops=%u", blkstr, riops);
}
return virCgroupSetValueStr(group,
@@ -974,11 +948,9 @@ virCgroupV2SetBlkioDeviceWriteIops(virCgroupPtr group,
return -1;
if (wiops == 0) {
- if (virAsprintf(&str, "%swiops=max", blkstr) < 0)
- return -1;
+ virAsprintf(&str, "%swiops=max", blkstr);
} else {
- if (virAsprintf(&str, "%swiops=%u", blkstr, wiops) < 0)
- return -1;
+ virAsprintf(&str, "%swiops=%u", blkstr, wiops);
}
return virCgroupSetValueStr(group,
@@ -1045,11 +1017,9 @@ virCgroupV2SetBlkioDeviceReadBps(virCgroupPtr group,
return -1;
if (rbps == 0) {
- if (virAsprintf(&str, "%srbps=max", blkstr) < 0)
- return -1;
+ virAsprintf(&str, "%srbps=max", blkstr);
} else {
- if (virAsprintf(&str, "%srbps=%llu", blkstr, rbps) < 0)
- return -1;
+ virAsprintf(&str, "%srbps=%llu", blkstr, rbps);
}
return virCgroupSetValueStr(group,
@@ -1116,11 +1086,9 @@ virCgroupV2SetBlkioDeviceWriteBps(virCgroupPtr group,
return -1;
if (wbps == 0) {
- if (virAsprintf(&str, "%swbps=max", blkstr) < 0)
- return -1;
+ virAsprintf(&str, "%swbps=max", blkstr);
} else {
- if (virAsprintf(&str, "%swbps=%llu", blkstr, wbps) < 0)
- return -1;
+ virAsprintf(&str, "%swbps=%llu", blkstr, wbps);
}
return virCgroupSetValueStr(group,
@@ -1520,8 +1488,7 @@ virCgroupV2SetCpuCfsPeriod(virCgroupPtr group,
}
*tmp = '\0';
- if (virAsprintf(&value, "%s %llu", str, cfs_period) < 0)
- return -1;
+ virAsprintf(&value, "%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 3b678015f5..d4071d1945 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -1520,19 +1520,13 @@ virConfLoadConfigPath(const char *name)
{
char *path;
if (geteuid() == 0) {
- if (virAsprintf(&path, "%s/libvirt/%s",
- SYSCONFDIR, name) < 0)
- return NULL;
+ virAsprintf(&path, "%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;
- }
+ virAsprintf(&path, "%s/%s", userdir, name);
VIR_FREE(userdir);
}
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index a9996b067c..1c8f356387 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -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;
+ virAsprintfQuiet(&devPaths[i], "/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 f22250a07e..a93c851f7d 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -180,8 +180,7 @@ addnhostsWrite(const char *path,
* for runtime addition.
*/
- if (virAsprintf(&tmp, "%s.new", path) < 0)
- return -ENOMEM;
+ virAsprintf(&tmp, "%s.new", path);
if (!(f = fopen(tmp, "w"))) {
istmp = false;
@@ -312,30 +311,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;
+ virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
+ "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;
+ virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"%s,[%s]",
+ name, ipstr);
} else if (!name && id) {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
- "id:%s,[%s]", id, ipstr) < 0)
- goto error;
+ virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
+ "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;
+ virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"%s,%s,%s",
+ mac, ipstr, name);
} else if (name && !mac) {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"%s,%s",
- name, ipstr) < 0)
- goto error;
+ virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"%s,%s", name,
+ ipstr);
} else {
- if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"%s,%s",
- mac, ipstr) < 0)
- goto error;
+ virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
"%s,%s", mac,
+ ipstr);
}
VIR_FREE(ipstr);
@@ -393,8 +386,7 @@ hostsfileWrite(const char *path,
* for runtime addition.
*/
- if (virAsprintf(&tmp, "%s.new", path) < 0)
- return -ENOMEM;
+ virAsprintf(&tmp, "%s.new", path);
if (!(f = fopen(tmp, "w"))) {
istmp = false;
@@ -758,8 +750,7 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force)
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
- if (virAsprintf(&complete, "%s\n%s", version, help) < 0)
- goto cleanup;
+ virAsprintf(&complete, "%s\n%s", version, help);
ret = dnsmasqCapsSetFromBuffer(caps, complete);
diff --git a/src/util/virebtables.c b/src/util/virebtables.c
index 3fda362a13..9f4ba9013e 100644
--- a/src/util/virebtables.c
+++ b/src/util/virebtables.c
@@ -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;
- }
+ virAsprintf(&ctx->chain, "libvirt_%s_FORWARD", driver);
return ctx;
}
diff --git a/src/util/virerror.c b/src/util/virerror.c
index f0ef7e337c..c31103c3b7 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -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;
+ virAsprintfQuiet(&newmsg, "%s: %s", fmtmsg, err->message);
VIR_FREE(err->message);
err->message = g_steal_pointer(&newmsg);
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 7c97317994..0636fb8f08 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -508,8 +508,7 @@ virFileRewrite(const char *path,
int fd = -1;
int ret = -1;
- if (virAsprintf(&newfile, "%s.new", path) < 0)
- goto cleanup;
+ virAsprintf(&newfile, "%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;
+ virAsprintf(&looppath, "/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;
+ virAsprintf(&looppath, "/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;
+ virAsprintf(&path, 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));
+ virAsprintf(&ret, "/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;
+ virAsprintf(&filepath, "%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;
+ virAsprintf(&candidate, "%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))
+ virAsprintf(&fullpath, "%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;
+ virAsprintf(&ret, "%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;
+ virAsprintf(&path, "%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));
+ virAsprintf(&path, "%s/%s", dir, name);
} else {
- ignore_value(virAsprintf(&path, "%s/%s%s", dir, name, ext));
+ virAsprintf(&path, "%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;
+ virAsprintf(abspath, "%s/%s", buf, path);
}
return 0;
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index d544d36c61..26b2fdc17f 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -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;
+ virAsprintf(&sysfs_nodedir, "%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;
+ virAsprintf(&sysfs_cpudir, "%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;
+ virAsprintf(&sysfs_cpudir, "%s/cpu", SYSFS_SYSTEM_PATH);
if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch,
present_cpus_map,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 010eb551a9..ab40c5faaa 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -184,8 +184,7 @@ virHostdevManagerNew(void)
if (!(rundir = virGetUserRuntimeDirectory()))
return NULL;
- if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir)
< 0)
- return NULL;
+ virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir);
old_umask = umask(077);
diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index c1dfc1225c..0d57d47529 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -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;
+ virAsprintf(&meminfo_path,
+ 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;
+ virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
- if (virAsprintf(&strval, "%u", param->value.ui) == -1)
- return -2;
+ virAsprintf(&strval, "%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;
+ virAsprintf(&path, "%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;
+ virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field);
if (!virFileExists(path))
return -2;
diff --git a/src/util/viriptables.c b/src/util/viriptables.c
index e95aaa4773..e339368040 100644
--- a/src/util/viriptables.c
+++ b/src/util/viriptables.c
@@ -401,7 +401,7 @@ static char *iptablesFormatNetwork(virSocketAddr *netaddr,
if (!netstr)
return NULL;
- ignore_value(virAsprintf(&ret, "%s/%d", netstr, prefix));
+ virAsprintf(&ret, "%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;
+ virAsprintf(&portRangeStr, ":%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,
+ virAsprintf(&natRangeStr, "%s-%s%s", addrStartStr, addrEndStr,
portRangeStr ? portRangeStr : "");
} else {
- r = virAsprintf(&natRangeStr, "%s%s", addrStartStr,
+ virAsprintf(&natRangeStr, "%s%s", addrStartStr,
portRangeStr ? portRangeStr : "");
}
- if (r < 0)
- return -1;
-
virFirewallRuleAddArgList(fw, rule,
"--jump", "SNAT",
"--to-source", natRangeStr, NULL);
diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c
index ba90c41763..55a30470d6 100644
--- a/src/util/viriscsi.c
+++ b/src/util/viriscsi.c
@@ -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;
+ virAsprintf(&temp_ifacename, "libvirt-iface-%08llx",
+ (unsigned long long)virRandomBits(32));
VIR_DEBUG("Attempting to create interface '%s' with IQN
'%s'",
temp_ifacename, initiatoriqn);
diff --git a/src/util/virjson.c b/src/util/virjson.c
index eb6207f13f..ec8d706edd 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -497,8 +497,7 @@ virJSONValuePtr
virJSONValueNewNumberInt(int data)
{
g_autofree char *str = NULL;
- if (virAsprintf(&str, "%i", data) < 0)
- return NULL;
+ virAsprintf(&str, "%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;
+ virAsprintf(&str, "%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;
+ virAsprintf(&str, "%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;
+ virAsprintf(&str, "%llu", data);
return virJSONValueNewNumber(str);
}
diff --git a/src/util/virkmod.c b/src/util/virkmod.c
index 2f6ab90ded..962b132d31 100644
--- a/src/util/virkmod.c
+++ b/src/util/virkmod.c
@@ -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;
+ virAsprintfQuiet(&drvblklst, "blacklist %s\n", module);
/* modprobe will convert all '-' into '_', so we need to as well */
for (i = 0; i < drvblklst[i]; i++)
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index b0f73c2a8a..30868035a9 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -67,7 +67,7 @@ static char *virLockSpaceGetResourcePath(virLockSpacePtr lockspace,
{
char *ret;
if (lockspace->dir)
- ignore_value(virAsprintf(&ret, "%s/%s", lockspace->dir,
resname));
+ virAsprintf(&ret, "%s/%s", lockspace->dir, resname);
else
ret = g_strdup(resname);
return ret;
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 27843363e7..bfb2430ed3 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -149,15 +149,15 @@ virLogUnlock(void)
}
-static int
+static void
virLogSetDefaultOutputToStderr(void)
{
- return virAsprintf(&virLogDefaultOutput, "%d:stderr",
- virLogDefaultPriority);
+ virAsprintf(&virLogDefaultOutput, "%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);
+ virAsprintf(&virLogDefaultOutput, "%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;
+ virAsprintf(&virLogDefaultOutput, "%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;
+ virAsprintf(&virLogDefaultOutput, "%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",
- virThreadSelfID(), virLogPriorityString(priority),
- funcname, linenr, str);
+ virAsprintfQuiet(msg, "%llu: %s : %s:%d : %s\n",
+ virThreadSelfID(), virLogPriorityString(priority),
+ funcname, linenr, str);
} else {
- ret = virAsprintfQuiet(msg, "%llu: %s : %s\n",
- virThreadSelfID(), virLogPriorityString(priority),
- str);
+ virAsprintfQuiet(msg, "%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;
+ virAsprintfQuiet(&hoststr, "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;
-
+ virAsprintfQuiet(&msg, "%s: %s", timestamp, str);
ignore_value(safewrite(fd, msg, strlen(msg)));
VIR_FREE(msg);
}
diff --git a/src/util/virlog.h b/src/util/virlog.h
index 8846fae9aa..feb2f85904 100644
--- a/src/util/virlog.h
+++ b/src/util/virlog.h
@@ -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
diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index 43cefc1e8e..c515e3e7b0 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -290,7 +290,7 @@ virMacMapFileName(const char *dnsmasqStateDir,
{
char *filename;
- ignore_value(virAsprintf(&filename, "%s/%s.macs", dnsmasqStateDir,
bridge));
+ virAsprintf(&filename, "%s/%s.macs", dnsmasqStateDir, bridge);
return filename;
}
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 9f8cb95423..c5fd4ad42f 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -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;
+ virAsprintf(&file, "%s/mdev_type/device_api", dev->path);
/* TODO - make this a generic method to access sysfs files for various
* kinds of devices
@@ -218,8 +217,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
if (!dev_path)
return NULL;
- if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0)
- return NULL;
+ virAsprintf(&iommu_path, "%s/iommu_group", dev_path);
if (!virFileExists(iommu_path)) {
virReportSystemError(errno, _("failed to access '%s'"),
iommu_path);
@@ -231,8 +229,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
return NULL;
}
- if (virAsprintf(&vfio_path, "/dev/vfio/%s",
last_component(result_path)) < 0)
- return NULL;
+ virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path));
return vfio_path;
}
@@ -428,7 +425,7 @@ virMediatedDeviceGetSysfsPath(const char *uuidstr)
{
char *ret = NULL;
- ignore_value(virAsprintf(&ret, MDEV_SYSFS_DEVICES "%s", uuidstr));
+ virAsprintf(&ret, MDEV_SYSFS_DEVICES "%s", uuidstr);
return ret;
}
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 5391f0030b..20f7ef5428 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -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;
+ virAsprintf(&pid, "%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;
+ virAsprintf(pf_sysfs_device_link, 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;
+ virAsprintf(pf_sysfs_device_link, 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;
+ virAsprintf(&subsys_link, "%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;
+ virAsprintf(&virtfnName, "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;
+ virAsprintf(&filePath, "%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;
+ virAsprintf(&filePath, "%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;
+ virAsprintf(&filePath, "%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)
+ virAsprintf(&filePath, "%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(ð_devpath, SYSFS_NET_DIR "%s/device/resource",
ifname) < 0)
- goto cleanup;
+ virAsprintf(ð_devpath, 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;
+ virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR
"%s/device/resource",
+ dp->d_name);
if (virFileReadAll(ib_devpath, RESOURCE_FILE_LEN, &ib_res_buf) > 0
&&
STREQ(eth_res_buf, ib_res_buf)) {
ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_RDMA));
diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c
index b90bd55d32..b7e0c0c7c1 100644
--- a/src/util/virnetdevbandwidth.c
+++ b/src/util/virnetdevbandwidth.c
@@ -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;
+ virAsprintf(&filter_id, "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;
+ virAsprintf(&mac[0], "0x%02x%02x%02x%02x", ifmac[2],
+ ifmac[3], ifmac[4], ifmac[5]);
+ virAsprintf(&mac[1], "0x%02x%02x", ifmac[0], ifmac[1]);
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;
+ virAsprintf(&average, "%llukbps", tx->average);
+ if (tx->peak)
+ virAsprintf(&peak, "%llukbps", tx->peak);
+ if (tx->burst)
+ virAsprintf(&burst, "%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;
+ virAsprintf(&average, "%llukbps", rx->average);
+ virAsprintf(&burst, "%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;
+ virAsprintf(&class_id, "1:%x", id);
+ virAsprintf(&qdisc_id, "%x:", id);
+ virAsprintf(&floor, "%llukbps", bandwidth->in->floor);
+ virAsprintf(&ceil, "%llukbps", net_bandwidth->in->peak ?
+ net_bandwidth->in->peak :
+ net_bandwidth->in->average);
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;
+ virAsprintf(&class_id, "1:%x", id);
+ virAsprintf(&qdisc_id, "%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;
+ virAsprintf(&class_id, "1:%x", id);
+ virAsprintf(&rate, "%llukbps", new_rate);
+ virAsprintf(&ceil, "%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;
+ virAsprintf(&class_id, "1:%x", id);
if (virNetDevBandwidthManipulateFilter(ifname, ifmac_ptr, id,
class_id, true, true) < 0)
diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
index edf4cc6236..0a0834be69 100644
--- a/src/util/virnetdevbridge.c
+++ b/src/util/virnetdevbridge.c
@@ -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;
+ virAsprintf(&path, 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;
+ virAsprintf(&path, 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;
+ virAsprintf(&path, 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;
+ virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname,
+ paramname);
if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0)
return -1;
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 1bd18ea30a..057e75e5e1 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -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;
+ virAsprintf(&path, "/proc/sys/net/ipv6/conf/%s/accept_ra",
+ ifname ? ifname : "all");
if ((virFileReadAll(path, 512, &buf) < 0) ||
(virStrToLong_i(buf, &suffix, 10, &accept_ra) < 0))
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 2ccd83d1bb..11fcb96400 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -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;
+ virAsprintf(&tapname, "/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;
+ virAsprintf(&tapname, "/dev/tap%d", ifindex);
for (i = 0; i < tapfdSize; i++) {
int fd = -1;
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index 1d2bbf9dd7..9862e550b7 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -151,19 +151,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;
+ virAsprintf(&attachedmac_ex_id,
"external-ids:attached-mac=\"%s\"",
+ macaddrstr);
+ virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"",
ifuuidstr);
+ virAsprintf(&vmid_ex_id, "external-ids:vm-id=\"%s\"",
vmuuidstr);
if (ovsport->profileID[0] != '\0') {
- if (virAsprintf(&profile_ex_id,
"external-ids:port-profile=\"%s\"",
- ovsport->profileID) < 0)
- return -1;
+ virAsprintf(&profile_ex_id,
"external-ids:port-profile=\"%s\"",
+ ovsport->profileID);
}
cmd = virCommandNew(OVSVSCTL);
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index fe4f55f8fc..23f2882bc3 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -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;
+ virAsprintf(&newname, *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;
+ virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name);
if ((*tapfd = open(dev_path, O_RDWR)) < 0) {
virReportSystemError(errno,
diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
index 4e10cdf12b..5e5074dd68 100644
--- a/src/util/virnetdevveth.c
+++ b/src/util/virnetdevveth.c
@@ -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;
+ virAsprintf(&path, 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;
+ virAsprintf(&veth1auto, "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;
+ virAsprintf(&veth2auto, "vnet%d", veth2num);
vethNum = veth2num + 1;
}
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index 448833d8d1..e6213df6da 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -538,23 +538,20 @@ 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));
+ virAsprintf(path,
+ 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));
+ virAsprintf(path,
+ 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 +567,10 @@ virNumaGetHugePageInfoPath(char **path,
_("page size %u is not available"),
page_size);
}
+ return -1;
}
- return ret;
+ return 0;
}
static int
@@ -582,9 +580,10 @@ virNumaGetHugePageInfoDir(char **path, int node)
*path = g_strdup(HUGEPAGES_SYSTEM_PREFIX);
return 0;
} else {
- return virAsprintf(path,
- HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
- node);
+ virAsprintf(path,
+ HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
+ node);
+ return 0;
}
}
@@ -930,8 +929,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;
+ virAsprintf(&nr_buf, "%llu", page_count);
if (virFileWriteStr(nr_path, nr_buf, 0) < 0) {
virReportSystemError(errno,
diff --git a/src/util/virpci.c b/src/util/virpci.c
index f9e39e79d8..3ae13469bd 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -213,7 +213,7 @@ virPCIDriverDir(const char *driver)
{
char *buffer;
- ignore_value(virAsprintf(&buffer, PCI_SYSFS "drivers/%s", driver));
+ virAsprintf(&buffer, 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));
+ virAsprintf(&buffer, 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;
+ virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name);
found = virFileExists(path);
if (found) {
@@ -1354,12 +1353,12 @@ virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr)
{
char *str;
- ignore_value(virAsprintf(&str,
- VIR_PCI_DEVICE_ADDRESS_FMT,
- addr->domain,
- addr->bus,
- addr->slot,
- addr->function));
+ virAsprintf(&str,
+ VIR_PCI_DEVICE_ADDRESS_FMT,
+ addr->domain,
+ addr->bus,
+ addr->slot,
+ addr->function);
return str;
}
@@ -1381,14 +1380,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;
+ virAsprintf(&dev->name, VIR_PCI_DEVICE_ADDRESS_FMT, domain, bus, slot,
+ function);
- if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config",
- dev->name) < 0)
- return NULL;
+ virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config",
dev->name);
if (!virFileExists(dev->path)) {
virReportSystemError(errno,
@@ -1733,10 +1728,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;
+ virAsprintf(&pcidir, "/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;
@@ -1753,8 +1747,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;
+ virAsprintf(&file, "%s/%s", pcidir, ent->d_name);
if ((actor)(dev, file, opaque) < 0)
goto cleanup;
}
@@ -1786,10 +1779,9 @@ 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;
+ virAsprintf(&groupPath,
+ 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 */
@@ -1936,10 +1928,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;
+ virAsprintf(&devName, VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain, addr->bus,
+ addr->slot, addr->function);
if (!(devPath = virPCIFile(devName, "iommu_group")))
return -1;
@@ -1989,9 +1979,7 @@ virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev)
dev->name, devPath);
return NULL;
}
- if (virAsprintf(&groupDev, "/dev/vfio/%s",
- last_component(groupPath)) < 0)
- return NULL;
+ virAsprintf(&groupDev, "/dev/vfio/%s", last_component(groupPath));
return groupDev;
}
@@ -2290,8 +2278,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;
+ virAsprintf(&totalvfs_file, "%s/sriov_totalvfs", sysfs_path);
if (virFileExists(totalvfs_file)) {
char *end = NULL; /* so that terminating \n doesn't create error */
@@ -2308,8 +2295,8 @@ virPCIGetVirtualFunctions(const char *sysfs_path,
do {
g_autofree char *device_link = NULL;
/* look for virtfn%d links until one isn't found */
- if (virAsprintf(&device_link, "%s/virtfn%zu", sysfs_path,
*num_virtual_functions) < 0)
- goto error;
+ virAsprintf(&device_link, "%s/virtfn%zu", sysfs_path,
+ *num_virtual_functions);
if (!virFileExists(device_link))
break;
@@ -2350,9 +2337,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;
+ virAsprintf(&vf_sysfs_physfn_link, "%s/physfn", vf_sysfs_device_link);
return virFileExists(vf_sysfs_physfn_link);
}
@@ -2410,9 +2395,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;
+ virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
+ virPCIDeviceName);
return 0;
}
@@ -2420,11 +2404,9 @@ 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;
+ virAsprintf(pci_sysfs_device_link,
+ PCI_SYSFS "devices/" VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain,
+ addr->bus, addr->slot, addr->function);
return 0;
}
@@ -2609,8 +2591,7 @@ virPCIGetMdevTypes(const char *sysfspath,
size_t ntypes = 0;
size_t i;
- if (virAsprintf(&types_path, "%s/mdev_supported_types", sysfspath) <
0)
- return -1;
+ virAsprintf(&types_path, "%s/mdev_supported_types", sysfspath);
if ((dirret = virDirOpenIfExists(&dir, types_path)) < 0)
goto cleanup;
@@ -2623,8 +2604,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;
+ virAsprintf(&tmppath, "%s/%s", types_path, entry->d_name);
if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0)
goto cleanup;
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index f7849d91a6..2faa6215e4 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -233,8 +233,7 @@ int virPidFileReadPathIfAlive(const char *path,
goto cleanup;
}
- if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) <
0)
- return -ENOMEM;
+ virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid);
if ((ret = virFileIsLink(procPath)) < 0)
return ret;
@@ -495,8 +494,7 @@ virPidFileConstructPath(bool privileged,
"%s", _("No runstatedir specified"));
return -1;
}
- if (virAsprintf(pidfile, "%s/%s.pid", runstatedir, progname) < 0)
- return -1;
+ virAsprintf(pidfile, "%s/%s.pid", runstatedir, progname);
} else {
if (!(rundir = virGetUserRuntimeDirectory()))
return -1;
@@ -508,8 +506,7 @@ virPidFileConstructPath(bool privileged,
return -1;
}
- if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0)
- return -1;
+ virAsprintf(pidfile, "%s/%s.pid", rundir, progname);
}
return 0;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index b5fda05e0c..032d09e904 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -129,13 +129,13 @@ virProcessTranslateStatus(int status)
{
char *buf;
if (WIFEXITED(status)) {
- ignore_value(virAsprintfQuiet(&buf, _("exit status %d"),
- WEXITSTATUS(status)));
+ virAsprintfQuiet(&buf, _("exit status %d"),
+ WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
- ignore_value(virAsprintfQuiet(&buf, _("fatal signal %d"),
- WTERMSIG(status)));
+ virAsprintfQuiet(&buf, _("fatal signal %d"),
+ WTERMSIG(status));
} else {
- ignore_value(virAsprintfQuiet(&buf, _("invalid value %d"),
status));
+ virAsprintfQuiet(&buf, _("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;
+ virAsprintf(&taskPath, "/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;
+ virAsprintf(&nsfile, "/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;
+ virAsprintf(&filename, "/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;
+ virAsprintf(&path, "/proc/%lld/ns/mnt", (long long)data->pid);
if ((fd = open(path, O_RDONLY)) < 0) {
virReportSystemError(errno, "%s",
diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index 162c3c603f..1eee238771 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -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;
+ virAsprintf(&prefix, "%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;
+ virAsprintf(&tmpkey, "%s.%s", data->prefix, key);
return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
data->arrayFunc, false);
diff --git a/src/util/virrandom.c b/src/util/virrandom.c
index 8dcab1ac47..12ea9bbbdc 100644
--- a/src/util/virrandom.c
+++ b/src/util/virrandom.c
@@ -194,8 +194,7 @@ virRandomGenerateWWN(char **wwn,
return -1;
}
- if (virAsprintf(wwn, "5" "%s%09llx", oui,
- (unsigned long long)virRandomBits(36)) < 0)
- return -1;
+ virAsprintf(wwn, "5" "%s%09llx", oui,
+ (unsigned long long)virRandomBits(36));
return 0;
}
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 29ea52a16f..55c15d04a4 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -2319,8 +2319,7 @@ virResctrlDeterminePath(const char *parentpath,
return NULL;
}
- if (virAsprintf(&path, "%s/%s-%s", parentpath, prefix, id) < 0)
- return NULL;
+ virAsprintf(&path, "%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;
+ virAsprintf(&schemata_path, "%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;
+ virAsprintf(&tasks, "%s/tasks", path);
- if (virAsprintf(&pidstr, "%lld", (long long int) pid) < 0)
- goto cleanup;
+ virAsprintf(&pidstr, "%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;
+ virAsprintf(&parentpath, "%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;
+ virAsprintf(&datapath, "%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;
+ virAsprintf(&filepath, "%s/%s", datapath, ent->d_name);
if (!virFileIsDir(filepath))
continue;
diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index 82a677b743..826a3db2c2 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -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;
+ virAsprintf(&oldpath, "%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;
+ virAsprintf(&tmppath, "%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;
+ virAsprintf(&nextpath, "%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;
+ virAsprintf(&thispath, "%s.%zu", file->basepath, i -
2);
}
VIR_DEBUG("Rollover %s -> %s", thispath, nextpath);
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index 705571f8ec..0f28c617b0 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -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;
+ virAsprintf(&path, "%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;
+ virAsprintf(&path, "%s/%d:%u:%u:%llu/block", prefix, adapter_id, bus,
+ target, unit);
if (virDirOpen(&dir, path) < 0)
goto cleanup;
@@ -207,11 +203,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;
+ virAsprintf(&dev->name, "%d:%u:%u:%llu", dev->adapter,
+ dev->bus, dev->target, dev->unit);
+ virAsprintf(&dev->sg_path, "%s/%s",
+ sysfs_prefix ? sysfs_prefix : "/dev", sg);
if (!virFileExists(dev->sg_path)) {
virReportSystemError(errno,
@@ -220,11 +215,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;
+ virAsprintf(&vendor_path, "%s/%s/vendor", prefix, dev->name);
+ virAsprintf(&model_path, "%s/%s/model", prefix, dev->name);
if (virFileReadAll(vendor_path, 1024, &vendor) < 0)
return NULL;
@@ -235,8 +227,7 @@ virSCSIDeviceNew(const char *sysfs_prefix,
virTrimSpaces(vendor, NULL);
virTrimSpaces(model, NULL);
- if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0)
- return NULL;
+ virAsprintf(&dev->id, "%s:%s", vendor, model);
ret = g_steal_pointer(&dev);
return ret;
diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c
index 10524f49fa..53da460fdf 100644
--- a/src/util/virscsihost.c
+++ b/src/util/virscsihost.c
@@ -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;
+ virAsprintf(&sysfs_path, "%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;
+ virAsprintf(&host_link, "%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;
+ virAsprintf(&unique_path, "%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;
+ virAsprintf(&parentaddr, "%04x:%02x:%02x.%01x", domain, bus, slot,
+ function);
if (!(name = virSCSIHostFindByPCI(NULL, parentaddr, unique_id))) {
virReportError(VIR_ERR_XML_ERROR,
_("Failed to find scsi_host using PCI '%s' "
diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c
index 5f523636be..4687c30f97 100644
--- a/src/util/virscsivhost.c
+++ b/src/util/virscsivhost.c
@@ -256,9 +256,7 @@ virSCSIVHostDeviceNew(const char *name)
dev->name = g_strdup(name);
- if (virAsprintf(&dev->path, "%s/%s",
- SYSFS_VHOST_SCSI_DEVICES, name) < 0)
- return NULL;
+ virAsprintf(&dev->path, "%s/%s", SYSFS_VHOST_SCSI_DEVICES, name);
VIR_DEBUG("%s: initialized", dev->name);
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index efe942b44c..ba1cde05cd 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -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;
+ virAsprintf(&addrstr, 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)
+ virAsprintf(&ipv6_host, "[%s]", host);
- if (virAsprintf(&addrstr, "%s%s%s",
- ipv6_host ? ipv6_host : host,
- separator ? separator : ":", port) == -1) {
- return NULL;
- }
+ virAsprintf(&addrstr, "%s%s%s",
+ ipv6_host ? ipv6_host : host,
+ separator ? separator : ":", port);
} else {
addrstr = g_strdup(host);
}
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index be2b5479bb..f3b388a7bc 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1541,7 +1541,7 @@ virStorageFileGetNPIVKey(const char *path,
*tmp = '\0';
if (*serial != '\0' && *port != '\0')
- ignore_value(virAsprintf(key, "%s_PORT%s", serial, port));
+ virAsprintf(key, "%s_PORT%s", serial, port);
}
return 0;
@@ -2620,11 +2620,9 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
}
if (STRNEQ(dirname, "/")) {
- if (virAsprintf(&def->path, "%s/%s", dirname, rel) < 0)
- return NULL;
+ virAsprintf(&def->path, "%s/%s", dirname, rel);
} else {
- if (virAsprintf(&def->path, "/%s", rel) < 0)
- return NULL;
+ virAsprintf(&def->path, "/%s", rel);
}
if (virStorageSourceGetActualType(parent) == VIR_STORAGE_TYPE_NETWORK) {
@@ -3283,8 +3281,7 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
*port = '\0';
}
- if (virAsprintf(&src->path, "%s/%s", target, lun) < 0)
- return -1;
+ virAsprintf(&src->path, "%s/%s", target, lun);
/* Libvirt doesn't handle inline authentication. Make the caller aware. */
if (virJSONValueObjectGetString(json, "user") ||
@@ -4196,8 +4193,7 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top,
VIR_FREE(path);
- if (virAsprintf(&path, "%s%s", tmp, next->relPath) < 0)
- return -1;
+ virAsprintf(&path, "%s%s", tmp, next->relPath);
VIR_FREE(tmp);
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 4294b7456e..24a9e41493 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -709,18 +709,15 @@ int
virDoubleToStr(char **strp, double number)
{
virLocale oldlocale;
- int rc = -1;
if (virLocaleSetRaw(&oldlocale) < 0)
return -1;
- rc = virAsprintf(strp, "%lf", number);
+ virAsprintf(strp, "%lf", number);
virLocaleRevert(&oldlocale);
virLocaleFixupRadix(strp);
- if (rc < 0)
- return -1;
return 0;
}
diff --git a/src/util/virstring.h b/src/util/virstring.h
index f5e2302b8b..d7881be2d1 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -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);
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 2ff0341b11..bb6ee24f4e 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -301,8 +301,7 @@ int virSystemdCreateMachine(const char *name,
ret = -1;
- if (virAsprintf(&creatorname, "libvirt-%s", drivername) < 0)
- goto cleanup;
+ virAsprintf(&creatorname, "libvirt-%s", drivername);
if (partition) {
if (!(slicename = virSystemdMakeSliceName(partition)))
diff --git a/src/util/virtpm.c b/src/util/virtpm.c
index 9244697902..149a82310d 100644
--- a/src/util/virtpm.c
+++ b/src/util/virtpm.c
@@ -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++) {
+ virAsprintf(&path, "/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;
}
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index f50d926860..d8c296c138 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -176,22 +176,22 @@ virTypedParameterToString(virTypedParameterPtr param)
switch (param->type) {
case VIR_TYPED_PARAM_INT:
- ignore_value(virAsprintf(&value, "%d", param->value.i));
+ virAsprintf(&value, "%d", param->value.i);
break;
case VIR_TYPED_PARAM_UINT:
- ignore_value(virAsprintf(&value, "%u", param->value.ui));
+ virAsprintf(&value, "%u", param->value.ui);
break;
case VIR_TYPED_PARAM_LLONG:
- ignore_value(virAsprintf(&value, "%lld", param->value.l));
+ virAsprintf(&value, "%lld", param->value.l);
break;
case VIR_TYPED_PARAM_ULLONG:
- ignore_value(virAsprintf(&value, "%llu", param->value.ul));
+ virAsprintf(&value, "%llu", param->value.ul);
break;
case VIR_TYPED_PARAM_DOUBLE:
- ignore_value(virAsprintf(&value, "%g", param->value.d));
+ virAsprintf(&value, "%g", param->value.d);
break;
case VIR_TYPED_PARAM_BOOLEAN:
- ignore_value(virAsprintf(&value, "%d", param->value.b));
+ virAsprintf(&value, "%d", param->value.b);
break;
case VIR_TYPED_PARAM_STRING:
value = g_strdup(param->value.s);
diff --git a/src/util/viruri.c b/src/util/viruri.c
index 3532fa5576..241e4ea102 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -234,8 +234,7 @@ virURIFormat(virURIPtr uri)
if (xmluri.server != NULL &&
strchr(xmluri.server, ':') != NULL) {
- if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0)
- return NULL;
+ virAsprintf(&tmpserver, "[%s]", xmluri.server);
xmluri.server = tmpserver;
}
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 5a9f369ac1..3e97480b1a 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -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;
+ virAsprintf(&filename, 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);
+ virAsprintf(&dev->path, "%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;
+ virAsprintf(&dev->path, USB_DEVFS "%03d/%03d",
+ dev->bus, dev->dev);
}
/* XXX fixme. this should be product/vendor */
diff --git a/src/util/virutil.c b/src/util/virutil.c
index f2528e257c..705fb6bd74 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -744,11 +744,11 @@ static char *virGetXDGDirectory(const char *xdgenvname, const char
*xdgdefdir)
char *home = NULL;
if (path && path[0]) {
- ignore_value(virAsprintf(&ret, "%s/libvirt", path));
+ virAsprintf(&ret, "%s/libvirt", path);
} else {
home = virGetUserDirectory();
if (home)
- ignore_value(virAsprintf(&ret, "%s/%s/libvirt", home,
xdgdefdir));
+ virAsprintf(&ret, "%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));
+ virAsprintf(&ret, "%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));
+ virAsprintf(&sysfs_path, "%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;
+ virAsprintf(&val, "%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;
+ virAsprintf(&ret, "%s/%s", driPath, ent->d_name);
cleanup:
VIR_DIR_CLOSE(driDir);
diff --git a/src/util/virvhba.c b/src/util/virvhba.c
index dbbd8d0f52..c78d5e2cd9 100644
--- a/src/util/virvhba.c
+++ b/src/util/virvhba.c
@@ -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;
+ virAsprintf(&sysfs_path, "%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;
+ virAsprintf(&fc_host_path, "%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;
+ virAsprintf(&scsi_host_path, "%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;
+ virAsprintf(&sysfs_path, "%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;
+ virAsprintf(&operation_path, "%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;
+ virAsprintf(&operation_path, "%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;
+ virAsprintf(&vport_name, "%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;
+ virAsprintf(&path, "%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;
+ virAsprintf(&vport_create_path, "%s/%s/vport_create", prefix,
+ entry->d_name);
if (!virFileExists(vport_create_path))
continue;
--
2.21.0