func GetCgroupMounts() ([]Mount, error) { mounts, err := mount.GetMounts() if err != nil { return nil, err } all, err := GetAllSubsystems() if err != nil { return nil, err } allMap := make(map[string]bool) for _, s := range all { allMap[s] = true } res := []Mount{} for _, mount := range mounts { if mount.Fstype == "cgroup" { m := Mount{Mountpoint: mount.Mountpoint} for _, opt := range strings.Split(mount.VfsOpts, ",") { if strings.HasPrefix(opt, "name=") { m.Subsystems = append(m.Subsystems, opt) } if allMap[opt] { m.Subsystems = append(m.Subsystems, opt) } } res = append(res, m) } } return res, nil }
func getSelinuxMountPoint() string { if selinuxfs != "unknown" { return selinuxfs } selinuxfs = "" mounts, err := mount.GetMounts() if err != nil { return selinuxfs } for _, mount := range mounts { if mount.Fstype == "selinuxfs" { selinuxfs = mount.Mountpoint break } } if selinuxfs != "" { var buf syscall.Statfs_t syscall.Statfs(selinuxfs, &buf) if (buf.Flags & stRdOnly) == 1 { selinuxfs = "" } } return selinuxfs }
// https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt func FindCgroupMountpoint(subsystem string) (string, error) { mounts, err := mount.GetMounts() if err != nil { return "", err } for _, mount := range mounts { if mount.Fstype == "cgroup" { for _, opt := range strings.Split(mount.VfsOpts, ",") { if opt == subsystem { return mount.Mountpoint, nil } } } } return "", NewNotFoundError(subsystem) }