diff --git a/src/shared/Core/WslUtils.cs b/src/shared/Core/WslUtils.cs index 1db63d329..3e6fb332c 100644 --- a/src/shared/Core/WslUtils.cs +++ b/src/shared/Core/WslUtils.cs @@ -18,7 +18,6 @@ public static class WslUtils private const string WslUncPrefix = @"\\wsl$\"; private const string WslLocalHostUncPrefix = @"\\wsl.localhost\"; private const string WslCommandName = "wsl.exe"; - private const string WslInteropEnvar = "WSL_INTEROP"; private const string WslConfFilePath = "/etc/wsl.conf"; private const string DefaultWslMountPrefix = "/mnt"; private const string DefaultWslSysDriveMountName = "c"; @@ -61,29 +60,17 @@ private static int GetWslVersion(IEnvironment env, IFileSystem fs) return 0; } - // The WSL_INTEROP variable is set in WSL2 distributions - if (env.Variables.TryGetValue(WslInteropEnvar, out _)) + const string procWslInteropPath = "/proc/sys/fs/binfmt_misc/WSLInterop"; + const string procWslInteropLatePath = "/proc/sys/fs/binfmt_misc/WSLInterop-Late"; + // The WSLInterop file exists in WSL1 distributions + if (fs.FileExists(procWslInteropPath)) { - return 2; + return 1; } - - const string procVersionPath = "/proc/version"; - if (fs.FileExists(procVersionPath)) + // The WSLInterop-Late file exists in WSL2 distributions + if (fs.FileExists(procWslInteropLatePath)) { - // Both WSL1 and WSL2 distributions include "[Mm]icrosoft" in the version string - string procVersion = fs.ReadAllText(procVersionPath); - if (!Regex.IsMatch(procVersion, "[Mm]icrosoft")) - { - return 0; - } - - // WSL2 distributions return "WSL2" in the version string - if (Regex.IsMatch(procVersion, "wsl2", RegexOptions.IgnoreCase)) - { - return 2; - } - - return 1; + return 2; } return 0;