From: Peter Krempa Date: Fri, 5 Feb 2021 13:33:12 +0000 (+0100) Subject: virCgroupGetValueForBlkDev: Rewrite lookup of returned string X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7cc34189158e86d7c609452159ff4994b3c959f8;p=libvirt.git virCgroupGetValueForBlkDev: Rewrite lookup of returned string Lookup the string with prefix locally so that we can remove the helper which isn't universal at all. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 402224813b..8b77ada2f8 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -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; }