Skip to content

Commit de88a01

Browse files
committed
refactor init and setns process
Introduce a common parent struct `containerProcess`, let both `initProcess` and `setnsProcess` are inherited from it. Signed-off-by: lfbzhm <[email protected]>
1 parent 8fc5be4 commit de88a01

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

libcontainer/container_linux.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,16 @@ func (c *Container) newInitProcess(p *Process, cmd *exec.Cmd, comm *processComm)
653653
}
654654

655655
init := &initProcess{
656-
cmd: cmd,
657-
comm: comm,
658-
manager: c.cgroupManager,
656+
containerProcess: containerProcess{
657+
cmd: cmd,
658+
comm: comm,
659+
manager: c.cgroupManager,
660+
config: c.newInitConfig(p),
661+
process: p,
662+
bootstrapData: data,
663+
container: c,
664+
},
659665
intelRdtManager: c.intelRdtManager,
660-
config: c.newInitConfig(p),
661-
container: c,
662-
process: p,
663-
bootstrapData: data,
664666
}
665667
c.initProcess = init
666668
return init, nil
@@ -679,15 +681,18 @@ func (c *Container) newSetnsProcess(p *Process, cmd *exec.Cmd, comm *processComm
679681
return nil, err
680682
}
681683
proc := &setnsProcess{
682-
cmd: cmd,
684+
containerProcess: containerProcess{
685+
cmd: cmd,
686+
comm: comm,
687+
manager: c.cgroupManager,
688+
config: c.newInitConfig(p),
689+
process: p,
690+
bootstrapData: data,
691+
container: c,
692+
},
683693
cgroupPaths: state.CgroupPaths,
684694
rootlessCgroups: c.config.RootlessCgroups,
685695
intelRdtPath: state.IntelRdtPath,
686-
comm: comm,
687-
manager: c.cgroupManager,
688-
config: c.newInitConfig(p),
689-
process: p,
690-
bootstrapData: data,
691696
initProcessPid: state.InitProcessPid,
692697
}
693698
if len(p.SubCgroupPaths) > 0 {

libcontainer/process_linux.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,22 @@ func (c *processComm) closeParent() {
9999
// c.logPipeParent is kept alive for ForwardLogs
100100
}
101101

102+
type containerProcess struct {
103+
cmd *exec.Cmd
104+
comm *processComm
105+
config *initConfig
106+
manager cgroups.Manager
107+
fds []string
108+
process *Process
109+
bootstrapData io.Reader
110+
container *Container
111+
}
112+
102113
type setnsProcess struct {
103-
cmd *exec.Cmd
104-
comm *processComm
114+
containerProcess
105115
cgroupPaths map[string]string
106116
rootlessCgroups bool
107-
manager cgroups.Manager
108117
intelRdtPath string
109-
config *initConfig
110-
fds []string
111-
process *Process
112-
bootstrapData io.Reader
113118
initProcessPid int
114119
}
115120

@@ -430,15 +435,8 @@ func (p *setnsProcess) forwardChildLogs() chan error {
430435
}
431436

432437
type initProcess struct {
433-
cmd *exec.Cmd
434-
comm *processComm
435-
config *initConfig
436-
manager cgroups.Manager
438+
containerProcess
437439
intelRdtManager *intelrdt.Manager
438-
container *Container
439-
fds []string
440-
process *Process
441-
bootstrapData io.Reader
442440
}
443441

444442
func (p *initProcess) pid() int {

0 commit comments

Comments
 (0)