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:
+ *
+ * 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);
#if defined (__i386__)
#define REG_a "eax"
}
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;
NULSTR_FOREACH_PAIR(j, k, dmi_vendor_table)
if (startswith(s, j))
found = k;
- free(s);
if (found) {
if (id)
}
}
- if (hypervisor) {
+ if (hypervisor || hvtype) {
if (id)
*id = "other";
}
int detect_container(const char **id) {
- char *e = NULL;
+ char _cleanup_free_ *e = NULL;
int r;
/* Unfortunately many of these operations require root access
*id = "other";
}
- free(e);
-
return r;
}