diff --git a/internal/common/common.go b/internal/common/common.go index d46aaeb..57e291b 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -94,6 +94,17 @@ func (i FakeInvoke) CommandWithContext(ctx context.Context, name string, arg ... var ErrNotImplementedError = errors.New("not implemented yet") +// ReadFile reads contents from a file +func ReadFile(filename string) (string, error) { + content, err := ioutil.ReadFile(filename) + + if err != nil { + return "", err + } + + return string(content), nil +} + // ReadLines reads contents from a file and splits them by new lines. // A convenience wrapper to ReadLinesOffsetN(filename, 0, -1). func ReadLines(filename string) ([]string, error) { diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 6d0ef37..0f66f1c 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -194,6 +194,17 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) { } } + if PathExists(filepath.Join(filename, "1", "environ")) { + contents, err := ReadFile(filepath.Join(filename, "1", "environ")) + + if err == nil { + if strings.Contains(contents, "container=lxc") { + system = "lxc" + role = "guest" + } + } + } + if PathExists(filepath.Join(filename, "self", "cgroup")) { contents, err := ReadLines(filepath.Join(filename, "self", "cgroup")) if err == nil {