Streamline events (#287)

* Sync process.State() with the matching events

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

* Allow requesting events for a specific container

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

* Sync container state retrieval with other events

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

* Let containerd take care of calling runtime delete on exit

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

* Take care of possible race in TestBusyboxTopExecTopKillInit

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickaël Laventure 2016-07-13 11:01:07 -07:00 committed by Michael Crosby
parent 6dd2f1c422
commit 90f827ca10
11 changed files with 342 additions and 212 deletions

View file

@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
"sync"
"syscall"
"github.com/docker/containerd/specs"
@ -68,6 +69,7 @@ func newProcess(config *processConfig) (*process, error) {
spec: config.processSpec,
stdio: config.stdio,
cmdDoneCh: make(chan struct{}),
state: Running,
}
uid, gid, err := getRootIDs(config.spec)
if err != nil {
@ -121,6 +123,7 @@ func loadProcess(root, id string, c *container, s *ProcessState) (*process, erro
Stdout: s.Stdout,
Stderr: s.Stderr,
},
state: Stopped,
}
if _, err := p.getPidFromFile(); err != nil {
return nil, err
@ -139,6 +142,7 @@ func loadProcess(root, id string, c *container, s *ProcessState) (*process, erro
}
p.controlPipe = control
p.state = Running
return p, nil
}
return nil, err
@ -158,6 +162,8 @@ type process struct {
cmd *exec.Cmd
cmdSuccess bool
cmdDoneCh chan struct{}
state State
stateLock sync.Mutex
}
func (p *process) ID() string {
@ -198,6 +204,9 @@ func (p *process) ExitStatus() (int, error) {
if len(data) == 0 {
return -1, ErrProcessNotExited
}
p.stateLock.Lock()
p.state = Stopped
p.stateLock.Unlock()
return strconv.Atoi(string(data))
}
@ -219,14 +228,9 @@ func (p *process) Close() error {
}
func (p *process) State() State {
if p.pid == 0 {
return Stopped
}
err := syscall.Kill(p.pid, 0)
if err != nil && err == syscall.ESRCH {
return Stopped
}
return Running
p.stateLock.Lock()
defer p.stateLock.Unlock()
return p.state
}
func (p *process) getPidFromFile() (int, error) {