]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: use g_strdup instead of VIR_STRDUP
authorJán Tomko <jtomko@redhat.com>
Sun, 20 Oct 2019 11:49:46 +0000 (13:49 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 21 Oct 2019 10:51:58 +0000 (12:51 +0200)
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>
src/util/vircgroup.c
src/util/vircgroupv1.c
src/util/vircgroupv2.c

index d824aee86d2e51b9c14d36a057f51a6b3d5a9af8..8af6906a5717e8a2e6035c28dc4e3e747ed3b3a4 100644 (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)
index 6ab79a1897bc08979e13e0945a3dcca921c385e5..0820c5d638689aad7ab09ed5abd53fbd2feac0db 100644 (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,
index 7a64e74c3a617d6b6ac1b4b45a813c65f7c61215..e976a8d2416ce17a04d1236571a0709b78f18fff 100644 (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="" => "/"