Fix process wait with monitor
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
90e4f130c8
commit
4641ab4101
2 changed files with 23 additions and 3 deletions
|
@ -200,9 +200,7 @@ func (p *process) FD() int {
|
|||
}
|
||||
|
||||
func (p *process) Wait() (rst uint32, rerr error) {
|
||||
if _, err := ioutil.ReadAll(p.exit); err != nil {
|
||||
return 255, err
|
||||
}
|
||||
<-p.done
|
||||
data, err := ioutil.ReadFile(filepath.Join(p.root, "exitStatus"))
|
||||
defer func() {
|
||||
if rerr != nil {
|
||||
|
|
22
shim/shim.go
22
shim/shim.go
|
@ -12,6 +12,8 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/containerd/monitor"
|
||||
"github.com/docker/containerd/oci"
|
||||
"github.com/docker/containerkit"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
|
@ -62,13 +64,19 @@ func New(opts Opts) (*Shim, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m, err := monitor.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &Shim{
|
||||
root: opts.Root,
|
||||
name: opts.Name,
|
||||
timeout: opts.Timeout,
|
||||
runtime: r,
|
||||
processes: make(map[string]*process),
|
||||
m: m,
|
||||
}
|
||||
go s.startMonitor()
|
||||
f, err := os.Create(filepath.Join(opts.Root, "state.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -131,6 +139,7 @@ type Shim struct {
|
|||
processes map[string]*process
|
||||
bundle string
|
||||
checkpoint string
|
||||
m *monitor.Monitor
|
||||
}
|
||||
|
||||
type state struct {
|
||||
|
@ -198,6 +207,9 @@ func (s *Shim) Create(c *containerkit.Container) (containerkit.ProcessDelegate,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.m.Add(p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.pmu.Lock()
|
||||
s.processes["init"] = p
|
||||
s.pmu.Unlock()
|
||||
|
@ -302,6 +314,16 @@ func (s *Shim) command(args ...string) *exec.Cmd {
|
|||
return exec.Command(s.name, args...)
|
||||
}
|
||||
|
||||
func (s *Shim) startMonitor() {
|
||||
for m := range s.m.Events() {
|
||||
p := m.(*process)
|
||||
close(p.done)
|
||||
if err := s.m.Remove(p); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checkShimNotFound checks the error returned from a exec call to see if the binary
|
||||
// that was called exists on the system and returns true if the shim binary does not exist
|
||||
func checkShimNotFound(err error) bool {
|
||||
|
|
Loading…
Reference in a new issue