mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Fix race setting process opts
When starting and quering for pids a container can start and exit before this is set. So set the opts after the process is started and while libcontainer still has the container's process blocking on the pipe. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -179,7 +179,6 @@ func (c *linuxContainer) Start(process *Process) error {
|
||||
}
|
||||
return newSystemError(err)
|
||||
}
|
||||
process.ops = parent
|
||||
if doInit {
|
||||
c.updateState(parent)
|
||||
}
|
||||
@@ -254,6 +253,7 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
|
||||
manager: c.cgroupManager,
|
||||
config: c.newInitConfig(p),
|
||||
container: c,
|
||||
process: p,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -272,6 +272,7 @@ func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe,
|
||||
childPipe: childPipe,
|
||||
parentPipe: parentPipe,
|
||||
config: c.newInitConfig(p),
|
||||
process: p,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ type setnsProcess struct {
|
||||
cgroupPaths map[string]string
|
||||
config *initConfig
|
||||
fds []string
|
||||
process *Process
|
||||
}
|
||||
|
||||
func (p *setnsProcess) startTime() (string, error) {
|
||||
@@ -87,7 +88,6 @@ func (p *setnsProcess) start() (err error) {
|
||||
p.wait()
|
||||
return newSystemError(ierr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -115,13 +115,12 @@ func (p *setnsProcess) execSetns() error {
|
||||
p.cmd.Wait()
|
||||
return newSystemError(err)
|
||||
}
|
||||
|
||||
process, err := os.FindProcess(pid.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.cmd.Process = process
|
||||
p.process.ops = p
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -165,6 +164,7 @@ type initProcess struct {
|
||||
manager cgroups.Manager
|
||||
container *linuxContainer
|
||||
fds []string
|
||||
process *Process
|
||||
}
|
||||
|
||||
func (p *initProcess) pid() int {
|
||||
@@ -178,8 +178,10 @@ func (p *initProcess) externalDescriptors() []string {
|
||||
func (p *initProcess) start() (err error) {
|
||||
defer p.parentPipe.Close()
|
||||
err = p.cmd.Start()
|
||||
p.process.ops = p
|
||||
p.childPipe.Close()
|
||||
if err != nil {
|
||||
p.process.ops = nil
|
||||
return newSystemError(err)
|
||||
}
|
||||
// Save the standard descriptor names before the container process
|
||||
|
||||
Reference in New Issue
Block a user