r = read_one_line_file("/sys/hypervisor/type", &hvtype);
if (r >= 0) {
if (streq(hvtype, "xen")) {
r = read_one_line_file("/sys/hypervisor/type", &hvtype);
if (r >= 0) {
if (streq(hvtype, "xen")) {
NULSTR_FOREACH_PAIR(j, k, cpuid_vendor_table)
if (streq(sig.text, j)) {
NULSTR_FOREACH_PAIR(j, k, cpuid_vendor_table)
if (streq(sig.text, j)) {
}
/* /proc/vz exists in container and outside of the container,
* /proc/bc only outside of the container. */
if (access("/proc/vz", F_OK) >= 0 &&
access("/proc/bc", F_OK) < 0) {
}
/* /proc/vz exists in container and outside of the container,
* /proc/bc only outside of the container. */
if (access("/proc/vz", F_OK) >= 0 &&
access("/proc/bc", F_OK) < 0) {
/* We only recognize a selected few here, since we want to
* enforce a redacted namespace */
/* We only recognize a selected few here, since we want to
* enforce a redacted namespace */
- if (streq(e, "lxc")) {
- if (id)
- *id = "lxc";
- } else if (streq(e, "lxc-libvirt")) {
- if (id)
- *id = "lxc-libvirt";
- } else if (streq(e, "systemd-nspawn")) {
- if (id)
- *id = "systemd-nspawn";
- } else {
- if (id)
- *id = "other";
- }
+ if (streq(e, "lxc"))
+ _id ="lxc";
+ else if (streq(e, "lxc-libvirt"))
+ _id = "lxc-libvirt";
+ else if (streq(e, "systemd-nspawn"))
+ _id = "systemd-nspawn";
+ else
+ _id = "other";
+
+finish:
+ cached_found = r;
+
+ cached_id = _id;
+ if (id)
+ *id = _id;
return r;
}
/* Returns a short identifier for the various VM/container implementations */
Virtualization detect_virtualization(const char **id) {
return r;
}
/* Returns a short identifier for the various VM/container implementations */
Virtualization detect_virtualization(const char **id) {
- return cached_virt;
- }
-
- r = detect_container(&_id);
- if (r < 0) {
- v = r;
- goto finish;
- } else if (r > 0) {
- v = VIRTUALIZATION_CONTAINER;
- goto finish;
- }
-
- r = detect_vm(&_id);
- if (r < 0) {
- v = r;
- goto finish;
- } else if (r > 0) {
- v = VIRTUALIZATION_VM;
- goto finish;
- }
-
- v = VIRTUALIZATION_NONE;
-
-finish:
- if (v > 0) {
- cached_id = _id;
-
- if (id)
- *id = _id;
- }
+ r = detect_container(id);
+ if (r < 0)
+ return r;
+ if (r > 0)
+ return VIRTUALIZATION_CONTAINER;