Files
nomad/client/lib/cgroupslib/mount.go
Seth Hoenig e3c8700ded deps: upgrade to go-set/v2 (#18638)
No functional changes, just cleaning up deprecated usages that are
removed in v2 and replace one call of .Slice with .ForEach to avoid
making the intermediate copy.
2023-10-05 11:56:17 -05:00

48 lines
691 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build linux
package cgroupslib
import (
"bufio"
"io"
"os"
"strings"
"github.com/hashicorp/go-set/v2"
)
func detect() Mode {
if os.Geteuid() > 0 {
return OFF
}
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
return OFF
}
defer func() {
_ = f.Close()
}()
return scan(f)
}
func scan(in io.Reader) Mode {
scanner := bufio.NewScanner(in)
for scanner.Scan() {
tokens := set.From(strings.Fields(scanner.Text()))
if tokens.Contains("/sys/fs/cgroup") {
if tokens.Contains("tmpfs") {
return CG1
}
if tokens.Contains("cgroup2") {
return CG2
}
}
}
return OFF
}