From 84ff52af6ee74c7bd5bd2064b43e84e8b709afc5 Mon Sep 17 00:00:00 2001 From: David Bidorff Date: Mon, 13 Oct 2025 23:49:10 +0200 Subject: [PATCH] Further adjustments to WSL detection It seems that using /proc/1/cgroup is now broken to detect docker. Other projects have been using /proc/1/mountinfo instead (see https://github.com/pre-commit/pre-commit/pull/3535) --- util/util.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/util.go b/util/util.go index 0097e50..e271eec 100644 --- a/util/util.go +++ b/util/util.go @@ -28,11 +28,17 @@ func IsWSL() (bool, error) { return false, fmt.Errorf("Unable to read /proc/1/cgroup: %w", err) } + mountinfoData, err := ioutil.ReadFile("/proc/1/mountinfo") + if err != nil { + return false, fmt.Errorf("Unable to read /proc/1/mountinfo: %w", err) + } + + isContainer := strings.Contains(strings.ToLower(string(mountinfoData)), "/containers/") isDocker := strings.Contains(strings.ToLower(string(cgroupData)), "/docker/") isLxc := strings.Contains(strings.ToLower(string(cgroupData)), "/lxc/") isMsLinux := strings.Contains(strings.ToLower(string(procData)), "microsoft") - return isMsLinux && !(isDocker || isLxc), nil + return isMsLinux && !(isContainer || isDocker || isLxc), nil } // OpenURL opens the specified URL in the default browser of the user. Source: