//go:build linux package host import ( "github.com/carlosframework/platform/internal/hostbox" "golang.org/x/sys/unix" "path/filepath" "strings" ) var claimContainmentAgentRoot = agentUnitCgroup var claimContainmentInspect = inspectClaimContainment func inspectClaimContainment(relative string) (hostbox.LaunchGroup, error) { if !filepath.IsLocal(relative) || filepath.Clean(relative) != relative || relative == "." { return hostbox.LaunchGroup{}, ErrClaimStopInventory } fd, err := unix.Open("/sys/fs/cgroup", unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0) if err != nil { return hostbox.LaunchGroup{}, err } for _, part := range strings.Split(relative, "/") { next, e := unix.Openat(fd, part, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0) unix.Close(fd) if e != nil { return hostbox.LaunchGroup{}, e } fd = next } defer unix.Close(fd) var st unix.Stat_t if err = unix.Fstat(fd, &st); err != nil { return hostbox.LaunchGroup{}, err } return hostbox.LaunchGroup{RelativePath: relative, Device: uint64(st.Dev), Inode: st.Ino}, nil }