github.com/mizzy/docker@v1.5.0/pkg/parsers/operatingsystem/operatingsystem.go (about) 1 package operatingsystem 2 3 import ( 4 "bytes" 5 "errors" 6 "io/ioutil" 7 ) 8 9 var ( 10 // file to use to detect if the daemon is running in a container 11 proc1Cgroup = "/proc/1/cgroup" 12 13 // file to check to determine Operating System 14 etcOsRelease = "/etc/os-release" 15 ) 16 17 func GetOperatingSystem() (string, error) { 18 b, err := ioutil.ReadFile(etcOsRelease) 19 if err != nil { 20 return "", err 21 } 22 if i := bytes.Index(b, []byte("PRETTY_NAME")); i >= 0 { 23 b = b[i+13:] 24 return string(b[:bytes.IndexByte(b, '"')]), nil 25 } 26 return "", errors.New("PRETTY_NAME not found") 27 } 28 29 func IsContainerized() (bool, error) { 30 b, err := ioutil.ReadFile(proc1Cgroup) 31 if err != nil { 32 return false, err 33 } 34 for _, line := range bytes.Split(b, []byte{'\n'}) { 35 if len(line) > 0 && !bytes.HasSuffix(line, []byte{'/'}) { 36 return true, nil 37 } 38 } 39 return false, nil 40 }