[PATCH 2/2] host-validate: Be more careful when checking for cgroup mounts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The existing code was built with the assumption that no cgroup
name could appear as part of another cgroup name. Rewrite it to
handle such cases correctly.
---
 tools/virt-host-validate-common.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c
index 18b9f20..ced29e3 100644
--- a/tools/virt-host-validate-common.c
+++ b/tools/virt-host-validate-common.c
@@ -340,16 +340,20 @@ static int virHostValidateCGroupMount(const char *hvname,
         goto error;
 
     while (getmntent_r(fp, &ent, mntbuf, sizeof(mntbuf)) && !matched) {
-        char *tmp = strstr(ent.mnt_opts, cg_name);
-        if (!tmp)
-            continue;
+        char **opts;
+        size_t nopts;
+        size_t i;
 
-        tmp += strlen(cg_name);
-        if (*tmp != ',' &&
-            *tmp != '\0')
+        if (!(opts = virStringSplitCount(ent.mnt_opts, ",", 0, &nopts)))
             continue;
 
-        matched = true;
+        /* Look for a mount option matching the cgroup name */
+        for (i = 0; i < nopts; i++) {
+            if (STREQ(opts[i], cg_name))
+                matched = true;
+        }
+
+        virStringFreeListCount(opts, nopts);
     }
     endmntent(fp);
     if (!matched)
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]