11693: Add test that error capturing output results in cancelled container.
[arvados.git] / services / crunch-run / cgroup.go
1 package main
2
3 import (
4         "bytes"
5         "io/ioutil"
6         "log"
7 )
8
9 // Return the current process's cgroup for the given subsystem.
10 func findCgroup(subsystem string) string {
11         subsys := []byte(subsystem)
12         cgroups, err := ioutil.ReadFile("/proc/self/cgroup")
13         if err != nil {
14                 log.Fatal(err)
15         }
16         for _, line := range bytes.Split(cgroups, []byte("\n")) {
17                 toks := bytes.SplitN(line, []byte(":"), 4)
18                 if len(toks) < 3 {
19                         continue
20                 }
21                 for _, s := range bytes.Split(toks[1], []byte(",")) {
22                         if bytes.Compare(s, subsys) == 0 {
23                                 return string(toks[2])
24                         }
25                 }
26         }
27         log.Fatalf("subsystem %q not found in /proc/self/cgroup", subsystem)
28         return ""
29 }