Skip to content

Commit

Permalink
refactor init and setns process
Browse files Browse the repository at this point in the history
Introduce a common parent struct `containerProcess`,
let both `initProcess` and `setnsProcess` are inherited
from it.

Signed-off-by: lfbzhm <lifubang@acmcoder.com>
  • Loading branch information
lifubang committed Jun 7, 2024
1 parent 8fc5be4 commit de88a01
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
31 changes: 18 additions & 13 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,16 @@ func (c *Container) newInitProcess(p *Process, cmd *exec.Cmd, comm *processComm)
}

init := &initProcess{
cmd: cmd,
comm: comm,
manager: c.cgroupManager,
containerProcess: containerProcess{
cmd: cmd,
comm: comm,
manager: c.cgroupManager,
config: c.newInitConfig(p),
process: p,
bootstrapData: data,
container: c,
},
intelRdtManager: c.intelRdtManager,
config: c.newInitConfig(p),
container: c,
process: p,
bootstrapData: data,
}
c.initProcess = init
return init, nil
Expand All @@ -679,15 +681,18 @@ func (c *Container) newSetnsProcess(p *Process, cmd *exec.Cmd, comm *processComm
return nil, err
}
proc := &setnsProcess{
cmd: cmd,
containerProcess: containerProcess{
cmd: cmd,
comm: comm,
manager: c.cgroupManager,
config: c.newInitConfig(p),
process: p,
bootstrapData: data,
container: c,
},
cgroupPaths: state.CgroupPaths,
rootlessCgroups: c.config.RootlessCgroups,
intelRdtPath: state.IntelRdtPath,
comm: comm,
manager: c.cgroupManager,
config: c.newInitConfig(p),
process: p,
bootstrapData: data,
initProcessPid: state.InitProcessPid,
}
if len(p.SubCgroupPaths) > 0 {
Expand Down
28 changes: 13 additions & 15 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@ func (c *processComm) closeParent() {
// c.logPipeParent is kept alive for ForwardLogs
}

type containerProcess struct {
cmd *exec.Cmd
comm *processComm
config *initConfig
manager cgroups.Manager
fds []string
process *Process
bootstrapData io.Reader
container *Container
}

type setnsProcess struct {
cmd *exec.Cmd
comm *processComm
containerProcess
cgroupPaths map[string]string
rootlessCgroups bool
manager cgroups.Manager
intelRdtPath string
config *initConfig
fds []string
process *Process
bootstrapData io.Reader
initProcessPid int
}

Expand Down Expand Up @@ -430,15 +435,8 @@ func (p *setnsProcess) forwardChildLogs() chan error {
}

type initProcess struct {
cmd *exec.Cmd
comm *processComm
config *initConfig
manager cgroups.Manager
containerProcess
intelRdtManager *intelrdt.Manager
container *Container
fds []string
process *Process
bootstrapData io.Reader
}

func (p *initProcess) pid() int {
Expand Down
File renamed without changes.

0 comments on commit de88a01

Please sign in to comment.