X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fvirt.c;h=4f8134a7732c964839eea9cb91056f4f988a7ff8;hb=ea52e2aee8dd7b3f51e9a00e76a54ef12dc0e898;hp=78016eec8927d3e3245141e9f11144dfd8566401;hpb=b1b8e8169496d3c4f991de9a9d2975ffada6fa0f;p=elogind.git diff --git a/src/shared/virt.c b/src/shared/virt.c index 78016eec8..4f8134a77 100644 --- a/src/shared/virt.c +++ b/src/shared/virt.c @@ -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__) @@ -62,12 +64,11 @@ int detect_vm(const char **id) { union { uint32_t sig32[3]; char text[13]; - } sig; + } sig = {}; unsigned i; const char *j, *k; bool hypervisor; _cleanup_free_ char *hvtype = NULL; - int r; /* Try high-level hypervisor sysfs file first: * @@ -84,7 +85,6 @@ int detect_vm(const char **id) { return r; /* http://lwn.net/Articles/301888/ */ - zero(sig); #if defined (__i386__) #define REG_a "eax" @@ -165,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 @@ -217,8 +227,6 @@ int detect_container(const char **id) { *id = "other"; } - free(e); - return r; }