X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fvirt.c;h=7c0666cc244445a22d69e0229fd90c0ee75dce39;hb=166f4e4fb53a82900ff9ae080e0ff37d35d4dacd;hp=73bf0d7cfecabbc288877c8e3e9b38d0cb0436db;hpb=5d945323d594ac23a43d9936c7e2f5266776a7b1;p=elogind.git diff --git a/src/basic/virt.c b/src/basic/virt.c index 73bf0d7cf..7c0666cc2 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -19,14 +19,20 @@ along with systemd; If not, see . ***/ -#include #include +#include #include -#include "util.h" +#include "alloc-util.h" +#include "dirent-util.h" +#include "fd-util.h" +#include "fileio.h" #include "process-util.h" +#include "stat-util.h" +#include "string-table.h" +#include "string-util.h" +#include "util.h" #include "virt.h" -#include "fileio.h" static int detect_vm_cpuid(void) { @@ -263,12 +269,7 @@ int detect_vm(void) { if (cached_found >= 0) return cached_found; - /* Try xen capabilities file first, if not found try - * high-level hypervisor sysfs file: - * - * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */ - - r = detect_vm_xen(); + r = detect_vm_cpuid(); if (r < 0) return r; if (r != VIRTUALIZATION_NONE) @@ -280,7 +281,14 @@ int detect_vm(void) { if (r != VIRTUALIZATION_NONE) goto finish; - r = detect_vm_cpuid(); + /* x86 xen will most likely be detected by cpuid. If not (most likely + * because we're not an x86 guest), then we should try the xen capabilities + * file next. If that's not found, then we check for the high-level + * hypervisor sysfs file: + * + * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */ + + r = detect_vm_xen(); if (r < 0) return r; if (r != VIRTUALIZATION_NONE) @@ -323,6 +331,7 @@ int detect_container(void) { { "lxc-libvirt", VIRTUALIZATION_LXC_LIBVIRT }, { "systemd-nspawn", VIRTUALIZATION_SYSTEMD_NSPAWN }, { "docker", VIRTUALIZATION_DOCKER }, + { "rkt", VIRTUALIZATION_RKT }, }; static thread_local int cached_found = _VIRTUALIZATION_INVALID; @@ -393,15 +402,14 @@ int detect_container(void) { goto finish; } - r = VIRTUALIZATION_NONE; + r = VIRTUALIZATION_CONTAINER_OTHER; finish: cached_found = r; return r; } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind int detect_virtualization(void) { int r; @@ -413,6 +421,16 @@ int detect_virtualization(void) { } #endif // 0 +int running_in_chroot(void) { + int ret; + + ret = files_same("/proc/1/root", "/"); + if (ret < 0) + return ret; + + return ret == 0; +} + static const char *const virtualization_table[_VIRTUALIZATION_MAX] = { [VIRTUALIZATION_NONE] = "none", [VIRTUALIZATION_KVM] = "kvm", @@ -432,6 +450,7 @@ static const char *const virtualization_table[_VIRTUALIZATION_MAX] = { [VIRTUALIZATION_LXC] = "lxc", [VIRTUALIZATION_OPENVZ] = "openvz", [VIRTUALIZATION_DOCKER] = "docker", + [VIRTUALIZATION_RKT] = "rkt", [VIRTUALIZATION_CONTAINER_OTHER] = "container-other", };