Skip to content

Commit 84ff52a

Browse files
authored
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 pre-commit/pre-commit#3535)
1 parent 70a13e3 commit 84ff52a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

util/util.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ func IsWSL() (bool, error) {
2828
return false, fmt.Errorf("Unable to read /proc/1/cgroup: %w", err)
2929
}
3030

31+
mountinfoData, err := ioutil.ReadFile("/proc/1/mountinfo")
32+
if err != nil {
33+
return false, fmt.Errorf("Unable to read /proc/1/mountinfo: %w", err)
34+
}
35+
36+
isContainer := strings.Contains(strings.ToLower(string(mountinfoData)), "/containers/")
3137
isDocker := strings.Contains(strings.ToLower(string(cgroupData)), "/docker/")
3238
isLxc := strings.Contains(strings.ToLower(string(cgroupData)), "/lxc/")
3339
isMsLinux := strings.Contains(strings.ToLower(string(procData)), "microsoft")
3440

35-
return isMsLinux && !(isDocker || isLxc), nil
41+
return isMsLinux && !(isContainer || isDocker || isLxc), nil
3642
}
3743

3844
// OpenURL opens the specified URL in the default browser of the user. Source:

0 commit comments

Comments
 (0)