/* 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__)
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:
*
return r;
/* http://lwn.net/Articles/301888/ */
- zero(sig);
#if defined (__i386__)
#define REG_a "eax"
}
#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
*id = "other";
}
- free(e);
-
return r;
}