chiark / gitweb /
journalctl: use _COMM= match for scripts
[elogind.git] / src / shared / virt.c
index fddb45d6e832e1e4106eae3f3e065078d21304d9..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 *e = NULL;
+        _cleanup_free_ char *e = NULL;
         int r;
 
         /* Unfortunately many of these operations require root access
@@ -216,8 +227,6 @@ int detect_container(const char **id) {
                         *id = "other";
         }
 
-        free(e);
-
         return r;
 }