Windows: Impl pkg\parsers kernel+os
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
eef8989683
commit
b1c7a7da21
5 changed files with 121 additions and 1 deletions
40
parsers/operatingsystem/operatingsystem_linux.go
Normal file
40
parsers/operatingsystem/operatingsystem_linux.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package operatingsystem
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
var (
|
||||
// file to use to detect if the daemon is running in a container
|
||||
proc1Cgroup = "/proc/1/cgroup"
|
||||
|
||||
// file to check to determine Operating System
|
||||
etcOsRelease = "/etc/os-release"
|
||||
)
|
||||
|
||||
func GetOperatingSystem() (string, error) {
|
||||
b, err := ioutil.ReadFile(etcOsRelease)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if i := bytes.Index(b, []byte("PRETTY_NAME")); i >= 0 {
|
||||
b = b[i+13:]
|
||||
return string(b[:bytes.IndexByte(b, '"')]), nil
|
||||
}
|
||||
return "", errors.New("PRETTY_NAME not found")
|
||||
}
|
||||
|
||||
func IsContainerized() (bool, error) {
|
||||
b, err := ioutil.ReadFile(proc1Cgroup)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, line := range bytes.Split(b, []byte{'\n'}) {
|
||||
if len(line) > 0 && !bytes.HasSuffix(line, []byte{'/'}) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue