17244: Make -cgroup-parent-subsystem=X work in cgroups v2.
[arvados.git] / lib / crunchrun / cgroup.go
index 48ec93b8768c0a117f0af60d8433bb30d8f4467c..34dc8e40f092981157555dc2c525cdabc3265105 100644 (file)
@@ -11,6 +11,9 @@ import (
 )
 
 // Return the current process's cgroup for the given subsystem.
+//
+// If the host has cgroups v2 and not v1 (i.e., unified mode), return
+// the current process's cgroup.
 func findCgroup(subsystem string) (string, error) {
        subsys := []byte(subsystem)
        cgroups, err := ioutil.ReadFile("/proc/self/cgroup")
@@ -22,6 +25,10 @@ func findCgroup(subsystem string) (string, error) {
                if len(toks) < 3 {
                        continue
                }
+               if len(toks[1]) == 0 && string(toks[0]) == "0" {
+                       // cgroups v2: "0::$PATH"
+                       return string(toks[2]), nil
+               }
                for _, s := range bytes.Split(toks[1], []byte(",")) {
                        if bytes.Compare(s, subsys) == 0 {
                                return string(toks[2]), nil