提交 8212e5e4 编写于 作者: J Ján Tomko

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: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 5a101469
...@@ -289,8 +289,7 @@ virCgroupDetectPlacement(virCgroupPtr group, ...@@ -289,8 +289,7 @@ virCgroupDetectPlacement(virCgroupPtr group,
VIR_DEBUG("Detecting placement for pid %lld path %s", VIR_DEBUG("Detecting placement for pid %lld path %s",
(long long) pid, path); (long long) pid, path);
if (pid == -1) { if (pid == -1) {
if (VIR_STRDUP(procfile, "/proc/self/cgroup") < 0) procfile = g_strdup("/proc/self/cgroup");
goto cleanup;
} else { } else {
if (virAsprintf(&procfile, "/proc/%lld/cgroup", if (virAsprintf(&procfile, "/proc/%lld/cgroup",
(long long) pid) < 0) (long long) pid) < 0)
...@@ -547,8 +546,7 @@ virCgroupGetValueForBlkDev(const char *str, ...@@ -547,8 +546,7 @@ virCgroupGetValueForBlkDev(const char *str,
if (!(lines = virStringSplit(str, "\n", -1))) if (!(lines = virStringSplit(str, "\n", -1)))
goto error; goto error;
if (VIR_STRDUP(*value, virStringListGetFirstWithPrefix(lines, prefix)) < 0) *value = g_strdup(virStringListGetFirstWithPrefix(lines, prefix));
goto error;
ret = 0; ret = 0;
error: error:
...@@ -682,8 +680,7 @@ virCgroupNew(pid_t pid, ...@@ -682,8 +680,7 @@ virCgroupNew(pid_t pid,
goto error; goto error;
if (path[0] == '/' || !parent) { if (path[0] == '/' || !parent) {
if (VIR_STRDUP((*group)->path, path) < 0) (*group)->path = g_strdup(path);
goto error;
} else { } else {
if (virAsprintf(&(*group)->path, "%s%s%s", if (virAsprintf(&(*group)->path, "%s%s%s",
parent->path, parent->path,
...@@ -863,8 +860,7 @@ virCgroupNewPartition(const char *path, ...@@ -863,8 +860,7 @@ virCgroupNewPartition(const char *path,
if (STRNEQ(newPath, "/")) { if (STRNEQ(newPath, "/")) {
char *tmp; char *tmp;
if (VIR_STRDUP(parentPath, newPath) < 0) parentPath = g_strdup(newPath);
goto cleanup;
tmp = strrchr(parentPath, '/'); tmp = strrchr(parentPath, '/');
tmp++; tmp++;
...@@ -979,8 +975,7 @@ virCgroupNewThread(virCgroupPtr domain, ...@@ -979,8 +975,7 @@ virCgroupNewThread(virCgroupPtr domain,
return -1; return -1;
break; break;
case VIR_CGROUP_THREAD_EMULATOR: case VIR_CGROUP_THREAD_EMULATOR:
if (VIR_STRDUP(name, "emulator") < 0) name = g_strdup("emulator");
return -1;
break; break;
case VIR_CGROUP_THREAD_IOTHREAD: case VIR_CGROUP_THREAD_IOTHREAD:
if (virAsprintf(&name, "iothread%d", id) < 0) if (virAsprintf(&name, "iothread%d", id) < 0)
......
...@@ -175,13 +175,9 @@ virCgroupV1CopyMounts(virCgroupPtr group, ...@@ -175,13 +175,9 @@ virCgroupV1CopyMounts(virCgroupPtr group,
if (!parent->legacy[i].mountPoint) if (!parent->legacy[i].mountPoint)
continue; continue;
if (VIR_STRDUP(group->legacy[i].mountPoint, group->legacy[i].mountPoint = g_strdup(parent->legacy[i].mountPoint);
parent->legacy[i].mountPoint) < 0)
return -1;
if (VIR_STRDUP(group->legacy[i].linkPoint, group->legacy[i].linkPoint = g_strdup(parent->legacy[i].linkPoint);
parent->legacy[i].linkPoint) < 0)
return -1;
} }
return 0; return 0;
} }
...@@ -201,8 +197,7 @@ virCgroupV1CopyPlacement(virCgroupPtr group, ...@@ -201,8 +197,7 @@ virCgroupV1CopyPlacement(virCgroupPtr group,
continue; continue;
if (path[0] == '/') { if (path[0] == '/') {
if (VIR_STRDUP(group->legacy[i].placement, path) < 0) group->legacy[i].placement = g_strdup(path);
return -1;
} else { } else {
/* /*
* parent == "/" + path="" => "/" * parent == "/" + path="" => "/"
...@@ -233,8 +228,7 @@ virCgroupV1ResolveMountLink(const char *mntDir, ...@@ -233,8 +228,7 @@ virCgroupV1ResolveMountLink(const char *mntDir,
char *dirName; char *dirName;
struct stat sb; struct stat sb;
if (VIR_STRDUP(tmp, mntDir) < 0) tmp = g_strdup(mntDir);
return -1;
dirName = strrchr(tmp, '/'); dirName = strrchr(tmp, '/');
if (!dirName) { if (!dirName) {
...@@ -325,8 +319,7 @@ virCgroupV1DetectMounts(virCgroupPtr group, ...@@ -325,8 +319,7 @@ virCgroupV1DetectMounts(virCgroupPtr group,
VIR_FREE(controller->mountPoint); VIR_FREE(controller->mountPoint);
VIR_FREE(controller->linkPoint); VIR_FREE(controller->linkPoint);
if (VIR_STRDUP(controller->mountPoint, mntDir) < 0) controller->mountPoint = g_strdup(mntDir);
return -1;
/* If it is a co-mount it has a filename like "cpu,cpuacct" /* If it is a co-mount it has a filename like "cpu,cpuacct"
* and we must identify the symlink path */ * and we must identify the symlink path */
...@@ -359,9 +352,7 @@ virCgroupV1DetectPlacement(virCgroupPtr group, ...@@ -359,9 +352,7 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
* selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo" * selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
*/ */
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) { if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
if (VIR_STRDUP(group->legacy[i].placement, group->legacy[i].placement = g_strdup(selfpath);
selfpath) < 0)
return -1;
} else { } else {
if (virAsprintf(&group->legacy[i].placement, if (virAsprintf(&group->legacy[i].placement,
"%s%s%s", selfpath, "%s%s%s", selfpath,
...@@ -1791,12 +1782,14 @@ virCgroupV1AllowDevice(virCgroupPtr group, ...@@ -1791,12 +1782,14 @@ virCgroupV1AllowDevice(virCgroupPtr group,
g_autofree char *majorstr = NULL; g_autofree char *majorstr = NULL;
g_autofree char *minorstr = NULL; g_autofree char *minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || if (major < 0)
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)) majorstr = g_strdup("*");
if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
return -1; return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || if (minor < 0)
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)) minorstr = g_strdup("*");
if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
return -1; return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
...@@ -1824,12 +1817,14 @@ virCgroupV1DenyDevice(virCgroupPtr group, ...@@ -1824,12 +1817,14 @@ virCgroupV1DenyDevice(virCgroupPtr group,
g_autofree char *majorstr = NULL; g_autofree char *majorstr = NULL;
g_autofree char *minorstr = NULL; g_autofree char *minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || if (major < 0)
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)) majorstr = g_strdup("*");
if (major >= 0 && virAsprintf(&majorstr, "%i", major) < 0)
return -1; return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || if (minor < 0)
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)) minorstr = g_strdup("*");
if (minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0)
return -1; return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
......
...@@ -159,8 +159,7 @@ virCgroupV2CopyPlacement(virCgroupPtr group, ...@@ -159,8 +159,7 @@ virCgroupV2CopyPlacement(virCgroupPtr group,
VIR_DEBUG("group=%p path=%s parent=%p", group, path, parent); VIR_DEBUG("group=%p path=%s parent=%p", group, path, parent);
if (path[0] == '/') { if (path[0] == '/') {
if (VIR_STRDUP(group->unified.placement, path) < 0) group->unified.placement = g_strdup(path);
return -1;
} else { } else {
/* /*
* parent == "/" + path="" => "/" * parent == "/" + path="" => "/"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册