virt: detect WSL environment as a container (id: wsl)
This commit is contained in:
committed by
Lennart Poettering
parent
ef9fafbd91
commit
6c8a2c6793
@@ -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",
|
||||
};
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ enum {
|
||||
VIRTUALIZATION_OPENVZ,
|
||||
VIRTUALIZATION_DOCKER,
|
||||
VIRTUALIZATION_RKT,
|
||||
VIRTUALIZATION_WSL,
|
||||
VIRTUALIZATION_CONTAINER_OTHER,
|
||||
VIRTUALIZATION_CONTAINER_LAST = VIRTUALIZATION_CONTAINER_OTHER,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user