]> xenbits.xensource.com Git - libvirt.git/commitdiff
virCgroupGetValueForBlkDev: Rewrite lookup of returned string
authorPeter Krempa <pkrempa@redhat.com>
Fri, 5 Feb 2021 13:33:12 +0000 (14:33 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 11 Feb 2021 16:05:33 +0000 (17:05 +0100)
Lookup the string with prefix locally so that we can remove the helper
which isn't universal at all.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/vircgroup.c

index 402224813b131f132b23ee7dd9cbfd73e32e4bf6..8b77ada2f8a78c521053ad2bba697361587b9cb7 100644 (file)
@@ -600,21 +600,21 @@ virCgroupGetValueForBlkDev(const char *str,
                            char **value)
 {
     g_autofree char *prefix = NULL;
-    char **lines = NULL;
-    int ret = -1;
+    g_auto(GStrv) lines = NULL;
+    GStrv tmp;
 
     if (!(prefix = virCgroupGetBlockDevString(path)))
-        goto error;
+        return -1;
 
     if (!(lines = virStringSplit(str, "\n", -1)))
-        goto error;
+        return -1;
 
-    *value = g_strdup(virStringListGetFirstWithPrefix(lines, prefix));
+    for (tmp = lines; *tmp; tmp++) {
+        if ((*value = g_strdup(STRSKIP(*tmp, prefix))))
+            break;
+    }
 
-    ret = 0;
- error:
-    g_strfreev(lines);
-    return ret;
+    return 0;
 }