Skip to content

Commit ef90082

Browse files
committed
merge #4930 into opencontainers/runc:main
Kir Kolyshkin (2): libct: refactor setnsProcess.start libct: close child fds on prepareCgroupFD error LGTMs: lifubang cyphar
2 parents f023e1c + 871052b commit ef90082

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

libcontainer/process_linux.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,31 +352,38 @@ func (p *setnsProcess) prepareCgroupFD() (*os.File, error) {
352352
return fd, nil
353353
}
354354

355-
func (p *setnsProcess) start() (retErr error) {
356-
defer p.comm.closeParent()
355+
// startWithCgroupFD starts a process via clone3 with CLONE_INTO_CGROUP,
356+
// with a fallback if it fails (e.g. not available).
357+
func (p *setnsProcess) startWithCgroupFD() error {
358+
// Close the child side of the pipes.
359+
defer p.comm.closeChild()
357360

358361
fd, err := p.prepareCgroupFD()
359362
if err != nil {
360363
return err
361364
}
362-
363-
// Get the "before" value of oom kill count.
364-
oom, _ := p.manager.OOMKillCount()
365-
366-
err = p.startWithCPUAffinity()
367365
if fd != nil {
368-
fd.Close()
366+
defer fd.Close()
369367
}
368+
369+
err = p.startWithCPUAffinity()
370370
if err != nil && p.cmd.SysProcAttr.UseCgroupFD {
371371
logrus.Debugf("exec with CLONE_INTO_CGROUP failed: %v; retrying without", err)
372372
// SysProcAttr.CgroupFD is never used when UseCgroupFD is unset.
373373
p.cmd.SysProcAttr.UseCgroupFD = false
374374
err = p.startWithCPUAffinity()
375375
}
376376

377-
// Close the child-side of the pipes (controlled by child).
378-
p.comm.closeChild()
379-
if err != nil {
377+
return err
378+
}
379+
380+
func (p *setnsProcess) start() (retErr error) {
381+
defer p.comm.closeParent()
382+
383+
// Get the "before" value of oom kill count.
384+
oom, _ := p.manager.OOMKillCount()
385+
386+
if err := p.startWithCgroupFD(); err != nil {
380387
return fmt.Errorf("error starting setns process: %w", err)
381388
}
382389

0 commit comments

Comments
 (0)