summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-07 15:59:26 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-07 16:03:12 +0100
commitb1b8e8169496d3c4f991de9a9d2975ffada6fa0f (patch)
tree3b2bd3712cb613cdb5dbb1f2d3de16abb05fb157 /src/shared
parentf2d88580b50e3c173dcc2838f92fa85291bc5495 (diff)
virt: check for /sys/hypervisor/type for detecting xen PV
https://bugs.freedesktop.org/show_bug.cgi?id=61491
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/virt.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/shared/virt.c b/src/shared/virt.c
index eed321016d..78016eec89 100644
--- a/src/shared/virt.c
+++ b/src/shared/virt.c
@@ -66,6 +66,22 @@ int detect_vm(const char **id) {
unsigned i;
const char *j, *k;
bool hypervisor;
+ _cleanup_free_ char *hvtype = NULL;
+ int r;
+
+ /* Try high-level hypervisor sysfs file first:
+ *
+ * https://bugs.freedesktop.org/show_bug.cgi?id=61491 */
+ r = read_one_line_file("/sys/hypervisor/type", &hvtype);
+ if (r >= 0) {
+ if (streq(hvtype, "xen")) {
+ if (id)
+ *id = "xen";
+
+ return 1;
+ }
+ } else if (r != -ENOENT)
+ return r;
/* http://lwn.net/Articles/301888/ */
zero(sig);
@@ -118,11 +134,11 @@ int detect_vm(const char **id) {
}
for (i = 0; i < ELEMENTSOF(dmi_vendors); i++) {
- char *s;
- int r;
+ _cleanup_free_ char *s = NULL;
const char *found = NULL;
- if ((r = read_one_line_file(dmi_vendors[i], &s)) < 0) {
+ r = read_one_line_file(dmi_vendors[i], &s);
+ if (r < 0) {
if (r != -ENOENT)
return r;
@@ -132,7 +148,6 @@ int detect_vm(const char **id) {
NULSTR_FOREACH_PAIR(j, k, dmi_vendor_table)
if (startswith(s, j))
found = k;
- free(s);
if (found) {
if (id)
@@ -142,7 +157,7 @@ int detect_vm(const char **id) {
}
}
- if (hypervisor) {
+ if (hypervisor || hvtype) {
if (id)
*id = "other";