summaryrefslogtreecommitdiff
path: root/src/basic/virt.c
diff options
context:
space:
mode:
authorBalint Reczey <balint.reczey@canonical.com>2019-03-06 18:46:04 +0100
committerLennart Poettering <lennart@poettering.net>2019-03-13 18:42:27 +0100
commit6c8a2c679313f8283514923daf65f5e9d050d94c (patch)
tree5999e814ee4eaa5a08bdeff93dcd031cf613981d /src/basic/virt.c
parentef9fafbd9143a1d6278f65ce857735ad08c79f66 (diff)
downloadsystemd-6c8a2c679313f8283514923daf65f5e9d050d94c.tar.gz
virt: detect WSL environment as a container (id: wsl)
Diffstat (limited to 'src/basic/virt.c')
-rw-r--r--src/basic/virt.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/basic/virt.c b/src/basic/virt.c
index 0717347b35..5dd1bd6633 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -438,10 +438,12 @@ int detect_container(void) {
{ "systemd-nspawn", VIRTUALIZATION_SYSTEMD_NSPAWN },
{ "docker", VIRTUALIZATION_DOCKER },
{ "rkt", VIRTUALIZATION_RKT },
+ { "wsl", VIRTUALIZATION_WSL },
};
static thread_local int cached_found = _VIRTUALIZATION_INVALID;
_cleanup_free_ char *m = NULL;
+ _cleanup_free_ char *o = NULL;
const char *e = NULL;
unsigned j;
int r;
@@ -456,6 +458,15 @@ int detect_container(void) {
goto finish;
}
+ /* "Official" way of detecting WSL https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364 */
+ r = read_one_line_file("/proc/sys/kernel/osrelease", &o);
+ if (r >= 0) {
+ if (strstr(o, "Microsoft") || strstr(o, "WSL")) {
+ r = VIRTUALIZATION_WSL;
+ goto finish;
+ }
+ }
+
if (getpid_cached() == 1) {
/* If we are PID 1 we can just check our own environment variable, and that's authoritative. */
@@ -639,6 +650,7 @@ static const char *const virtualization_table[_VIRTUALIZATION_MAX] = {
[VIRTUALIZATION_OPENVZ] = "openvz",
[VIRTUALIZATION_DOCKER] = "docker",
[VIRTUALIZATION_RKT] = "rkt",
+ [VIRTUALIZATION_WSL] = "wsl",
[VIRTUALIZATION_CONTAINER_OTHER] = "container-other",
};