]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
detect-virt: also detect "microsoft" as WSL
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 3 Apr 2020 17:38:50 +0000 (19:38 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 4 Apr 2020 14:52:32 +0000 (16:52 +0200)
From https://github.com/microsoft/WSL/issues/423#issuecomment-221627364:
> it's unlikely we'll change it to something that doesn't contain "Microsoft"
> or "WSL".

... but well, it happened. If they change it incompatibly w/o adding an stable
detection mechanism, I think we should not add yet another detection method.
But adding a different casing of "microsoft" is not a very big step, so let's
do that.

Follow-up for #11932.

src/basic/virt.c

index 07831634da784666ed43c9015b433dbb5de87cf7..f567696265a0399f10f91567d85227d010941e76 100644 (file)
@@ -462,13 +462,14 @@ int detect_container(void) {
                 goto finish;
         }
 
-        /* "Official" way of detecting WSL https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364 */
+        /* "Official" way of detecting WSL https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364,
+         * ... and a working one, since the official one doesn't actually work ;(
+         */
         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 (r >= 0 &&
+            (strstr(o, "Microsoft") || strstr(o, "microsoft") || strstr(o, "WSL"))) {
+                r = VIRTUALIZATION_WSL;
+                goto finish;
         }
 
         if (getpid_cached() == 1) {