mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Simplify chroot wait, address code review issues
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
8a38ead219
commit
f3f2456b04
4 changed files with 17 additions and 23 deletions
|
@ -708,7 +708,7 @@ func (container *Container) Start() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
waitLock := make(chan struct{})
|
waitLock := make(chan struct{})
|
||||||
f := func(process *execdriver.Process) {
|
callback := func(process *execdriver.Process) {
|
||||||
container.State.SetRunning(process.Pid())
|
container.State.SetRunning(process.Pid())
|
||||||
if process.Tty {
|
if process.Tty {
|
||||||
// The callback is called after the process Start()
|
// The callback is called after the process Start()
|
||||||
|
@ -724,7 +724,9 @@ func (container *Container) Start() (err error) {
|
||||||
close(waitLock)
|
close(waitLock)
|
||||||
}
|
}
|
||||||
|
|
||||||
go container.monitor(f)
|
// We use a callback here instead of a goroutine and an chan for
|
||||||
|
// syncronization purposes
|
||||||
|
go container.monitor(callback)
|
||||||
|
|
||||||
// Start should not return until the process is actually running
|
// Start should not return until the process is actually running
|
||||||
<-waitLock
|
<-waitLock
|
||||||
|
|
|
@ -9,11 +9,11 @@ import (
|
||||||
type driver struct {
|
type driver struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDriver() (execdriver.Driver, error) {
|
func NewDriver() (*driver, error) {
|
||||||
return &driver{}, nil
|
return &driver{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) String() string {
|
func (d *driver) Name() string {
|
||||||
return "chroot"
|
return "chroot"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba
|
||||||
c.Rootfs,
|
c.Rootfs,
|
||||||
"/.dockerinit",
|
"/.dockerinit",
|
||||||
"-driver",
|
"-driver",
|
||||||
d.String(),
|
d.Name(),
|
||||||
}
|
}
|
||||||
params = append(params, c.Entrypoint)
|
params = append(params, c.Entrypoint)
|
||||||
params = append(params, c.Arguments...)
|
params = append(params, c.Arguments...)
|
||||||
|
@ -43,24 +43,12 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
waitErr error
|
|
||||||
waitLock = make(chan struct{})
|
|
||||||
)
|
|
||||||
go func() {
|
|
||||||
if err := c.Wait(); err != nil {
|
|
||||||
waitErr = err
|
|
||||||
}
|
|
||||||
close(waitLock)
|
|
||||||
}()
|
|
||||||
|
|
||||||
if startCallback != nil {
|
if startCallback != nil {
|
||||||
startCallback(c)
|
startCallback(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
<-waitLock
|
err = c.Wait()
|
||||||
|
return c.GetExitCode(), err
|
||||||
return c.GetExitCode(), waitErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) Kill(p *execdriver.Process, sig int) error {
|
func (d *driver) Kill(p *execdriver.Process, sig int) error {
|
||||||
|
|
|
@ -14,7 +14,7 @@ type Driver interface {
|
||||||
// TODO: @crosbymichael @creack wait should probably return the exit code
|
// TODO: @crosbymichael @creack wait should probably return the exit code
|
||||||
Wait(id string, duration time.Duration) error // Wait on an out of process...process - lxc ghosts
|
Wait(id string, duration time.Duration) error // Wait on an out of process...process - lxc ghosts
|
||||||
Version() string
|
Version() string
|
||||||
String() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network settings of the container
|
// Network settings of the container
|
||||||
|
@ -43,6 +43,9 @@ type Process struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Process) Pid() int {
|
func (c *Process) Pid() int {
|
||||||
|
if c.Process == nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
return c.Process.Pid
|
return c.Process.Pid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ type driver struct {
|
||||||
sharedRoot bool
|
sharedRoot bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDriver(root string, apparmor bool) (execdriver.Driver, error) {
|
func NewDriver(root string, apparmor bool) (*driver, error) {
|
||||||
// setup unconfined symlink
|
// setup unconfined symlink
|
||||||
if err := linkLxcStart(root); err != nil {
|
if err := linkLxcStart(root); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -41,7 +41,7 @@ func NewDriver(root string, apparmor bool) (execdriver.Driver, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) String() string {
|
func (d *driver) Name() string {
|
||||||
return "lxc"
|
return "lxc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba
|
||||||
"--",
|
"--",
|
||||||
c.InitPath,
|
c.InitPath,
|
||||||
"-driver",
|
"-driver",
|
||||||
d.String(),
|
d.Name(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Network != nil {
|
if c.Network != nil {
|
||||||
|
@ -195,6 +195,7 @@ func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) err
|
||||||
select {
|
select {
|
||||||
case <-waitLock:
|
case <-waitLock:
|
||||||
// If the process dies while waiting for it, just return
|
// If the process dies while waiting for it, just return
|
||||||
|
return nil
|
||||||
if c.ProcessState != nil && c.ProcessState.Exited() {
|
if c.ProcessState != nil && c.ProcessState.Exited() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue