vircgroup: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-20 13:49:46 +02:00
parent 5a101469fc
commit 8212e5e4ab
3 changed files with 24 additions and 35 deletions

View File

@ -289,8 +289,7 @@ virCgroupDetectPlacement(virCgroupPtr group,
VIR_DEBUG("Detecting placement for pid %lld path %s",
(long long) pid, path);
if (pid == -1) {
if (VIR_STRDUP(procfile, "/proc/self/cgroup") < 0)
goto cleanup;
procfile = g_strdup("/proc/self/cgroup");
} else {
if (virAsprintf(&procfile, "/proc/%lld/cgroup",
(long long) pid) < 0)
@ -547,8 +546,7 @@ virCgroupGetValueForBlkDev(const char *str,
if (!(lines = virStringSplit(str, "\n", -1)))
goto error;
if (VIR_STRDUP(*value, virStringListGetFirstWithPrefix(lines, prefix)) < 0)
goto error;
*value = g_strdup(virStringListGetFirstWithPrefix(lines, prefix));
ret = 0;
error:
@ -682,8 +680,7 @@ virCgroupNew(pid_t pid,
goto error;
if (path[0] == '/' || !parent) {
if (VIR_STRDUP((*group)->path, path) < 0)
goto error;
(*group)->path = g_strdup(path);
} else {
if (virAsprintf(&(*group)->path, "%s%s%s",
parent->path,
@ -863,8 +860,7 @@ virCgroupNewPartition(const char *path,
if (STRNEQ(newPath, "/")) {
char *tmp;
if (VIR_STRDUP(parentPath, newPath) < 0)
goto cleanup;
parentPath = g_strdup(newPath);
tmp = strrchr(parentPath, '/');
tmp++;
@ -979,8 +975,7 @@ virCgroupNewThread(virCgroupPtr domain,
return -1;
break;
case VIR_CGROUP_THREAD_EMULATOR:
if (VIR_STRDUP(name, "emulator") < 0)
return -1;
name = g_strdup("emulator");
break;
case VIR_CGROUP_THREAD_IOTHREAD:
if (virAsprintf(&name, "iothread%d", id) < 0)

View File

@ -175,13 +175,9 @@ virCgroupV1CopyMounts(virCgroupPtr group,
if (!parent->legacy[i].mountPoint)
continue;
if (VIR_STRDUP(group->legacy[i].mountPoint,
parent->legacy[i].mountPoint) < 0)
return -1;
group->legacy[i].mountPoint = g_strdup(parent->legacy[i].mountPoint);
if (VIR_STRDUP(group->legacy[i].linkPoint,
parent->legacy[i].linkPoint) < 0)
return -1;
group->legacy[i].linkPoint = g_strdup(parent->legacy[i].linkPoint);
}
return 0;
}
@ -201,8 +197,7 @@ virCgroupV1CopyPlacement(virCgroupPtr group,
continue;
if (path[0] == '/') {
if (VIR_STRDUP(group->legacy[i].placement, path) < 0)
return -1;
group->legacy[i].placement = g_strdup(path);
} else {
/*
* parent == "/" + path="" => "/"
@ -233,8 +228,7 @@ virCgroupV1ResolveMountLink(const char *mntDir,
char *dirName;
struct stat sb;
if (VIR_STRDUP(tmp, mntDir) < 0)
return -1;
tmp = g_strdup(mntDir);
dirName = strrchr(tmp, '/');
if (!dirName) {
@ -325,8 +319,7 @@ virCgroupV1DetectMounts(virCgroupPtr group,
VIR_FREE(controller->mountPoint);
VIR_FREE(controller->linkPoint);
if (VIR_STRDUP(controller->mountPoint, mntDir) < 0)
return -1;
controller->mountPoint = g_strdup(mntDir);
/* If it is a co-mount it has a filename like "cpu,cpuacct"
* and we must identify the symlink path */
@ -359,9 +352,7 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
* selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
*/
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
if (VIR_STRDUP(group->legacy[i].placement,
selfpath) < 0)
return -1;
group->legacy[i].placement = g_strdup(selfpath);
} else {
if (virAsprintf(&group->legacy[i].placement,
"%s%s%s", selfpath,
@ -1791,12 +1782,14 @@ virCgroupV1AllowDevice(virCgroupPtr group,
g_autofree char *majorstr = NULL;
g_autofree char *minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) ||
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0))
if (major < 0)
majorstr = g_strdup("*");
if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) ||
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0))
if (minor < 0)
minorstr = g_strdup("*");
if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
@ -1824,12 +1817,14 @@ virCgroupV1DenyDevice(virCgroupPtr group,
g_autofree char *majorstr = NULL;
g_autofree char *minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) ||
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0))
if (major < 0)
majorstr = g_strdup("*");
if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) ||
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0))
if (minor < 0)
minorstr = g_strdup("*");
if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,

View File

@ -159,8 +159,7 @@ virCgroupV2CopyPlacement(virCgroupPtr group,
VIR_DEBUG("group=%p path=%s parent=%p", group, path, parent);
if (path[0] == '/') {
if (VIR_STRDUP(group->unified.placement, path) < 0)
return -1;
group->unified.placement = g_strdup(path);
} else {
/*
* parent == "/" + path="" => "/"