4019: Initial support for queries on jsonb subproperties.
[arvados.git] / services / crunch-run / cgroup.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "bytes"
9         "io/ioutil"
10         "log"
11 )
12
13 // Return the current process's cgroup for the given subsystem.
14 func findCgroup(subsystem string) string {
15         subsys := []byte(subsystem)
16         cgroups, err := ioutil.ReadFile("/proc/self/cgroup")
17         if err != nil {
18                 log.Fatal(err)
19         }
20         for _, line := range bytes.Split(cgroups, []byte("\n")) {
21                 toks := bytes.SplitN(line, []byte(":"), 4)
22                 if len(toks) < 3 {
23                         continue
24                 }
25                 for _, s := range bytes.Split(toks[1], []byte(",")) {
26                         if bytes.Compare(s, subsys) == 0 {
27                                 return string(toks[2])
28                         }
29                 }
30         }
31         log.Fatalf("subsystem %q not found in /proc/self/cgroup", subsystem)
32         return ""
33 }