summaryrefslogtreecommitdiff
path: root/src/shared/virt.c
diff options
context:
space:
mode:
authorRamkumar Ramachandra <artagnon@gmail.com>2013-07-16 16:44:40 +0530
committerLennart Poettering <lennart@poettering.net>2013-07-16 14:27:53 +0200
commit7080ea16b5a0bfd71bfcdffc998e91f5273d47f9 (patch)
tree33c7f57db6479096bd0971308422ef902a526c92 /src/shared/virt.c
parent36c0868b67a9387d39c97983d3d22cfce0fedc62 (diff)
detect-virt: detect User-Mode Linux
In a User-Mode Linux session: $ systemd-detect-virt none Although it is possible to reliably detect virtualization: $ cat /proc/cpuinfo processor : 0 vendor_id : User Mode Linux model name : UML mode : skas host : Linux kytes 3.11.0-rc1-00009-ge5fd680 (...) bogomips : 7007.43 So, grep for the string "\nvendor_id\t: User Mode Linux\n" in /proc/cpuinfo, and say "uml" when asked.
Diffstat (limited to 'src/shared/virt.c')
-rw-r--r--src/shared/virt.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/shared/virt.c b/src/shared/virt.c
index 1c86a3dd1e..1abd6863ea 100644
--- a/src/shared/virt.c
+++ b/src/shared/virt.c
@@ -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;
}