Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
| ... | ... |
@@ -708,7 +708,7 @@ func (container *Container) Start() (err error) {
|
| 708 | 708 |
} |
| 709 | 709 |
|
| 710 | 710 |
waitLock := make(chan struct{})
|
| 711 |
- f := func(process *execdriver.Process) {
|
|
| 711 |
+ callback := func(process *execdriver.Process) {
|
|
| 712 | 712 |
container.State.SetRunning(process.Pid()) |
| 713 | 713 |
if process.Tty {
|
| 714 | 714 |
// The callback is called after the process Start() |
| ... | ... |
@@ -724,7 +724,9 @@ func (container *Container) Start() (err error) {
|
| 724 | 724 |
close(waitLock) |
| 725 | 725 |
} |
| 726 | 726 |
|
| 727 |
- go container.monitor(f) |
|
| 727 |
+ // We use a callback here instead of a goroutine and an chan for |
|
| 728 |
+ // syncronization purposes |
|
| 729 |
+ go container.monitor(callback) |
|
| 728 | 730 |
|
| 729 | 731 |
// Start should not return until the process is actually running |
| 730 | 732 |
<-waitLock |
| ... | ... |
@@ -9,11 +9,11 @@ import ( |
| 9 | 9 |
type driver struct {
|
| 10 | 10 |
} |
| 11 | 11 |
|
| 12 |
-func NewDriver() (execdriver.Driver, error) {
|
|
| 12 |
+func NewDriver() (*driver, error) {
|
|
| 13 | 13 |
return &driver{}, nil
|
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 |
-func (d *driver) String() string {
|
|
| 16 |
+func (d *driver) Name() string {
|
|
| 17 | 17 |
return "chroot" |
| 18 | 18 |
} |
| 19 | 19 |
|
| ... | ... |
@@ -23,7 +23,7 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba |
| 23 | 23 |
c.Rootfs, |
| 24 | 24 |
"/.dockerinit", |
| 25 | 25 |
"-driver", |
| 26 |
- d.String(), |
|
| 26 |
+ d.Name(), |
|
| 27 | 27 |
} |
| 28 | 28 |
params = append(params, c.Entrypoint) |
| 29 | 29 |
params = append(params, c.Arguments...) |
| ... | ... |
@@ -43,24 +43,12 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba |
| 43 | 43 |
return -1, err |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
- var ( |
|
| 47 |
- waitErr error |
|
| 48 |
- waitLock = make(chan struct{})
|
|
| 49 |
- ) |
|
| 50 |
- go func() {
|
|
| 51 |
- if err := c.Wait(); err != nil {
|
|
| 52 |
- waitErr = err |
|
| 53 |
- } |
|
| 54 |
- close(waitLock) |
|
| 55 |
- }() |
|
| 56 |
- |
|
| 57 | 46 |
if startCallback != nil {
|
| 58 | 47 |
startCallback(c) |
| 59 | 48 |
} |
| 60 | 49 |
|
| 61 |
- <-waitLock |
|
| 62 |
- |
|
| 63 |
- return c.GetExitCode(), waitErr |
|
| 50 |
+ err = c.Wait() |
|
| 51 |
+ return c.GetExitCode(), err |
|
| 64 | 52 |
} |
| 65 | 53 |
|
| 66 | 54 |
func (d *driver) Kill(p *execdriver.Process, sig int) error {
|
| ... | ... |
@@ -14,7 +14,7 @@ type Driver interface {
|
| 14 | 14 |
// TODO: @crosbymichael @creack wait should probably return the exit code |
| 15 | 15 |
Wait(id string, duration time.Duration) error // Wait on an out of process...process - lxc ghosts |
| 16 | 16 |
Version() string |
| 17 |
- String() string |
|
| 17 |
+ Name() string |
|
| 18 | 18 |
} |
| 19 | 19 |
|
| 20 | 20 |
// Network settings of the container |
| ... | ... |
@@ -43,6 +43,9 @@ type Process struct {
|
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
func (c *Process) Pid() int {
|
| 46 |
+ if c.Process == nil {
|
|
| 47 |
+ return -1 |
|
| 48 |
+ } |
|
| 46 | 49 |
return c.Process.Pid |
| 47 | 50 |
} |
| 48 | 51 |
|
| ... | ... |
@@ -29,7 +29,7 @@ type driver struct {
|
| 29 | 29 |
sharedRoot bool |
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 |
-func NewDriver(root string, apparmor bool) (execdriver.Driver, error) {
|
|
| 32 |
+func NewDriver(root string, apparmor bool) (*driver, error) {
|
|
| 33 | 33 |
// setup unconfined symlink |
| 34 | 34 |
if err := linkLxcStart(root); err != nil {
|
| 35 | 35 |
return nil, err |
| ... | ... |
@@ -41,7 +41,7 @@ func NewDriver(root string, apparmor bool) (execdriver.Driver, error) {
|
| 41 | 41 |
}, nil |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
-func (d *driver) String() string {
|
|
| 44 |
+func (d *driver) Name() string {
|
|
| 45 | 45 |
return "lxc" |
| 46 | 46 |
} |
| 47 | 47 |
|
| ... | ... |
@@ -53,7 +53,7 @@ func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallba |
| 53 | 53 |
"--", |
| 54 | 54 |
c.InitPath, |
| 55 | 55 |
"-driver", |
| 56 |
- d.String(), |
|
| 56 |
+ d.Name(), |
|
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
if c.Network != nil {
|
| ... | ... |
@@ -195,6 +195,7 @@ func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) err
|
| 195 | 195 |
select {
|
| 196 | 196 |
case <-waitLock: |
| 197 | 197 |
// If the process dies while waiting for it, just return |
| 198 |
+ return nil |
|
| 198 | 199 |
if c.ProcessState != nil && c.ProcessState.Exited() {
|
| 199 | 200 |
return nil |
| 200 | 201 |
} |