This commit is contained in:
spiritlhl
2024-08-14 09:22:19 +00:00
parent 6031bf81cf
commit 8ab56c9969

View File

@@ -1,6 +1,7 @@
package system package system
import ( import (
"bufio"
"context" "context"
"fmt" "fmt"
"os" "os"
@@ -125,6 +126,16 @@ func getHostInfo() (string, string, string, string, string, string, string, stri
if os.IsExist(err) { if os.IsExist(err) {
VmType = "Docker" VmType = "Docker"
} }
cgroupFile, err := os.Open("/proc/1/cgroup")
defer cgroupFile.Close()
if err == nil {
scanner := bufio.NewScanner(cgroupFile)
for scanner.Scan() {
if strings.Contains(scanner.Text(), "docker") {
VmType = "Docker"
}
}
}
_, err = os.Stat("/dev/lxss") _, err = os.Stat("/dev/lxss")
if os.IsExist(err) { if os.IsExist(err) {
VmType = "Windows Subsystem for Linux" VmType = "Windows Subsystem for Linux"