]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl: Check for control_d string to decide about dom0
authorStefan Bader <stefan.bader@canonical.com>
Wed, 12 Mar 2014 12:03:26 +0000 (13:03 +0100)
committerJim Fehlig <jfehlig@suse.com>
Thu, 13 Mar 2014 00:41:11 +0000 (18:41 -0600)
As soon as any guest mounts xenfs to /proc/xen, there is a capabilities
file in that directory. However it returns nothing when reading from it.
Change the test to actually check the contents of the file.

BugLink: http://bugs.launchpad.net/bugs/1248025
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
src/libxl/libxl_driver.c

index c8e014e3a5121de6455c9eff5fff6d8f7d6904c1..ae7342a9baca955583baadec94523951726a2092 100644 (file)
@@ -962,6 +962,7 @@ libxlDriverShouldLoad(bool privileged)
     bool ret = false;
     virCommandPtr cmd;
     int status;
+    char *output = NULL;
 
     /* Don't load if non-root */
     if (!privileged) {
@@ -969,8 +970,17 @@ libxlDriverShouldLoad(bool privileged)
         return ret;
     }
 
-    /* Don't load if not running on a Xen control domain (dom0) */
-    if (!virFileExists("/proc/xen/capabilities")) {
+    /*
+     * Don't load if not running on a Xen control domain (dom0). It is not
+     * sufficient to check for the file to exist as any guest can mount
+     * xenfs to /proc/xen.
+     */
+    status = virFileReadAll("/proc/xen/capabilities", 10, &output);
+    if (status >= 0) {
+        status = strncmp(output, "control_d", 9);
+    }
+    VIR_FREE(output);
+    if (status) {
         VIR_INFO("No Xen capabilities detected, probably not running "
                  "in a Xen Dom0.  Disabling libxenlight driver");