chiark / gitweb /
detect-virt: detect User-Mode Linux
[elogind.git] / src / shared / virt.c
index 1c86a3dd1e62dee901b4c482203b8b3a3e91839b..1abd6863ea5aa5fb6d010113b8415eaed2a8e85d 100644 (file)
@@ -67,6 +67,7 @@ int detect_vm(const char **id) {
         const char *j, *k;
         bool hypervisor;
         _cleanup_free_ char *hvtype = NULL;
+        _cleanup_free_ char *cpuinfo_contents = NULL;
         int r;
 
         /* Try high-level hypervisor sysfs file first:
@@ -164,6 +165,16 @@ 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;
 }