chiark / gitweb /
kernel-install: add compat with 'installkernel'
[elogind.git] / src / shared / virt.c
index 78016eec8927d3e3245141e9f11144dfd8566401..4f8134a7732c964839eea9cb91056f4f988a7ff8 100644 (file)
@@ -29,6 +29,8 @@
 
 /* Returns a short identifier for the various VM implementations */
 int detect_vm(const char **id) {
+        _cleanup_free_ char *cpuinfo_contents = NULL;
+        int r;
 
 #if defined(__i386__) || defined(__x86_64__)
 
@@ -62,12 +64,11 @@ int detect_vm(const char **id) {
         union {
                 uint32_t sig32[3];
                 char text[13];
-        } sig;
+        } sig = {};
         unsigned i;
         const char *j, *k;
         bool hypervisor;
         _cleanup_free_ char *hvtype = NULL;
-        int r;
 
         /* Try high-level hypervisor sysfs file first:
          *
@@ -84,7 +85,6 @@ int detect_vm(const char **id) {
                 return r;
 
         /* http://lwn.net/Articles/301888/ */
-        zero(sig);
 
 #if defined (__i386__)
 #define REG_a "eax"
@@ -165,11 +165,21 @@ int detect_vm(const char **id) {
         }
 
 #endif
+
+        /* Detect User-Mode Linux by reading /proc/cpuinfo */
+        r = read_full_file("/proc/cpuinfo", &cpuinfo_contents, NULL);
+        if (r < 0)
+                return r;
+        if (strstr(cpuinfo_contents, "\nvendor_id\t: User Mode Linux\n")) {
+                *id = "uml";
+                return 1;
+        }
+
         return 0;
 }
 
 int detect_container(const char **id) {
-        char *e = NULL;
+        _cleanup_free_ char *e = NULL;
         int r;
 
         /* Unfortunately many of these operations require root access
@@ -217,8 +227,6 @@ int detect_container(const char **id) {
                         *id = "other";
         }
 
-        free(e);
-
         return r;
 }