mirror of
https://github.com/opencontainers/runc.git
synced 2026-04-22 23:17:17 +08:00
libct: move exec sub-cgroup handling down the line
Remove cgroupPaths field from struct setnsProcess, because: - we can get base cgroup paths from p.manager.GetPaths(); - we can get sub-cgroup paths from p.process.SubCgroupPaths. But mostly because we are going to need separate cgroup paths when adopting cgroups.AddPid. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -655,40 +654,10 @@ func (c *Container) newSetnsProcess(p *Process, cmd *exec.Cmd, comm *processComm
|
||||
bootstrapData: data,
|
||||
container: c,
|
||||
},
|
||||
cgroupPaths: state.CgroupPaths,
|
||||
rootlessCgroups: c.config.RootlessCgroups,
|
||||
intelRdtPath: state.IntelRdtPath,
|
||||
initProcessPid: state.InitProcessPid,
|
||||
}
|
||||
if len(p.SubCgroupPaths) > 0 {
|
||||
if add, ok := p.SubCgroupPaths[""]; ok {
|
||||
// cgroup v1: using the same path for all controllers.
|
||||
// cgroup v2: the only possible way.
|
||||
for k := range proc.cgroupPaths {
|
||||
subPath := path.Join(proc.cgroupPaths[k], add)
|
||||
if !strings.HasPrefix(subPath, proc.cgroupPaths[k]) {
|
||||
return nil, fmt.Errorf("%s is not a sub cgroup path", add)
|
||||
}
|
||||
proc.cgroupPaths[k] = subPath
|
||||
}
|
||||
// cgroup v2: do not try to join init process's cgroup
|
||||
// as a fallback (see (*setnsProcess).start).
|
||||
proc.initProcessPid = 0
|
||||
} else {
|
||||
// Per-controller paths.
|
||||
for ctrl, add := range p.SubCgroupPaths {
|
||||
if val, ok := proc.cgroupPaths[ctrl]; ok {
|
||||
subPath := path.Join(val, add)
|
||||
if !strings.HasPrefix(subPath, val) {
|
||||
return nil, fmt.Errorf("%s is not a sub cgroup path", add)
|
||||
}
|
||||
proc.cgroupPaths[ctrl] = subPath
|
||||
} else {
|
||||
return nil, fmt.Errorf("unknown controller %s in SubCgroupPaths", ctrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return proc, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user