chiark / gitweb /
shared: fix build on !x86
[elogind.git] / src / shared / virt.c
index 7b18e58c166f9d4cf21cda8d35f2da8a337e60a8..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__)
 
@@ -67,7 +69,6 @@ int detect_vm(const char **id) {
         const char *j, *k;
         bool hypervisor;
         _cleanup_free_ char *hvtype = NULL;
-        int r;
 
         /* Try high-level hypervisor sysfs file first:
          *
@@ -164,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 _cleanup_free_ *e = NULL;
+        _cleanup_free_ char *e = NULL;
         int r;
 
         /* Unfortunately many of these operations require root access