virt: detect WSL environment as a container (id: wsl)
This commit is contained in:
parent
ef9fafbd91
commit
6c8a2c6793
|
@ -131,7 +131,7 @@
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry valign="top" morerows="5">Container</entry>
|
<entry valign="top" morerows="6">Container</entry>
|
||||||
<entry><varname>openvz</varname></entry>
|
<entry><varname>openvz</varname></entry>
|
||||||
<entry>OpenVZ/Virtuozzo</entry>
|
<entry>OpenVZ/Virtuozzo</entry>
|
||||||
</row>
|
</row>
|
||||||
|
@ -160,6 +160,11 @@
|
||||||
<entry><varname>rkt</varname></entry>
|
<entry><varname>rkt</varname></entry>
|
||||||
<entry>rkt app container runtime</entry>
|
<entry>rkt app container runtime</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
|
<row>
|
||||||
|
<entry><varname>wsl</varname></entry>
|
||||||
|
<entry><ulink url="https://docs.microsoft.com/en-us/windows/wsl/about">Windows Subsystem for Linux</ulink></entry>
|
||||||
|
</row>
|
||||||
</tbody>
|
</tbody>
|
||||||
</tgroup>
|
</tgroup>
|
||||||
</table>
|
</table>
|
||||||
|
@ -169,6 +174,12 @@
|
||||||
machine and container virtualization are used in
|
machine and container virtualization are used in
|
||||||
conjunction, only the latter will be identified (unless
|
conjunction, only the latter will be identified (unless
|
||||||
<option>--vm</option> is passed).</para>
|
<option>--vm</option> is passed).</para>
|
||||||
|
<para> Windows Subsystem for Linux is not a Linux container,
|
||||||
|
but an environment for running Linux userspace applications on
|
||||||
|
top of the Windows kernel using a Linux-compatible interface.
|
||||||
|
WSL is categorized as a container for practical purposes.
|
||||||
|
Multiple WSL environments share the same kernel and services
|
||||||
|
should generally behave like when being run in a container.</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
|
|
|
@ -1089,6 +1089,7 @@
|
||||||
<varname>systemd-nspawn</varname>,
|
<varname>systemd-nspawn</varname>,
|
||||||
<varname>docker</varname>,
|
<varname>docker</varname>,
|
||||||
<varname>rkt</varname>,
|
<varname>rkt</varname>,
|
||||||
|
<varname>wsl</varname>,
|
||||||
<varname>acrn</varname> to test
|
<varname>acrn</varname> to test
|
||||||
against a specific implementation, or
|
against a specific implementation, or
|
||||||
<varname>private-users</varname> to check whether we are running in a user namespace. See
|
<varname>private-users</varname> to check whether we are running in a user namespace. See
|
||||||
|
|
|
@ -438,10 +438,12 @@ int detect_container(void) {
|
||||||
{ "systemd-nspawn", VIRTUALIZATION_SYSTEMD_NSPAWN },
|
{ "systemd-nspawn", VIRTUALIZATION_SYSTEMD_NSPAWN },
|
||||||
{ "docker", VIRTUALIZATION_DOCKER },
|
{ "docker", VIRTUALIZATION_DOCKER },
|
||||||
{ "rkt", VIRTUALIZATION_RKT },
|
{ "rkt", VIRTUALIZATION_RKT },
|
||||||
|
{ "wsl", VIRTUALIZATION_WSL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static thread_local int cached_found = _VIRTUALIZATION_INVALID;
|
static thread_local int cached_found = _VIRTUALIZATION_INVALID;
|
||||||
_cleanup_free_ char *m = NULL;
|
_cleanup_free_ char *m = NULL;
|
||||||
|
_cleanup_free_ char *o = NULL;
|
||||||
const char *e = NULL;
|
const char *e = NULL;
|
||||||
unsigned j;
|
unsigned j;
|
||||||
int r;
|
int r;
|
||||||
|
@ -456,6 +458,15 @@ int detect_container(void) {
|
||||||
goto finish;
|
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 (getpid_cached() == 1) {
|
||||||
/* If we are PID 1 we can just check our own environment variable, and that's authoritative. */
|
/* 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_OPENVZ] = "openvz",
|
||||||
[VIRTUALIZATION_DOCKER] = "docker",
|
[VIRTUALIZATION_DOCKER] = "docker",
|
||||||
[VIRTUALIZATION_RKT] = "rkt",
|
[VIRTUALIZATION_RKT] = "rkt",
|
||||||
|
[VIRTUALIZATION_WSL] = "wsl",
|
||||||
[VIRTUALIZATION_CONTAINER_OTHER] = "container-other",
|
[VIRTUALIZATION_CONTAINER_OTHER] = "container-other",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ enum {
|
||||||
VIRTUALIZATION_OPENVZ,
|
VIRTUALIZATION_OPENVZ,
|
||||||
VIRTUALIZATION_DOCKER,
|
VIRTUALIZATION_DOCKER,
|
||||||
VIRTUALIZATION_RKT,
|
VIRTUALIZATION_RKT,
|
||||||
|
VIRTUALIZATION_WSL,
|
||||||
VIRTUALIZATION_CONTAINER_OTHER,
|
VIRTUALIZATION_CONTAINER_OTHER,
|
||||||
VIRTUALIZATION_CONTAINER_LAST = VIRTUALIZATION_CONTAINER_OTHER,
|
VIRTUALIZATION_CONTAINER_LAST = VIRTUALIZATION_CONTAINER_OTHER,
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue