]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Some function to check if a host is running in a virtual environment.
authorFlorian Menne <florianmenne@aol.com>
Sun, 21 Nov 2010 21:11:07 +0000 (22:11 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 21 Nov 2010 21:11:07 +0000 (22:11 +0100)
src/fireinfo.c

index c9c5700c2fe610a5c4f7e7f664cac6da3abbebfc..1ff0ae0feaf605d555c2333abe1fea258f4d3436 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <Python.h>
 
+#include <stdbool.h>
 #include <sys/utsname.h>
 
 /*
@@ -396,6 +397,22 @@ read_hypervisor(struct lscpu_desc *desc)
        }
 }
 
+static bool
+is_virtualized() {
+       unsigned int eax, ebx, ecx, edx;
+
+       cpuid(0x1, &eax, &ebx, &ecx, &edx);
+
+       /*
+               Bitwise detection of the 31st bit.
+               This indicates if a host runs in a virtual environment.
+       */
+       if (ecx & (1<<31))
+               return true;
+
+       return false;
+}
+
 static PyObject *
 do_cpuinfo() {
        /*