Add ctr exec
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
7715ddcefa
commit
47225c130c
7 changed files with 159 additions and 19 deletions
|
@ -15,7 +15,7 @@ type process interface {
|
|||
Exited(status int)
|
||||
// Status returns the exit status
|
||||
Status() int
|
||||
// Delete delets the process and its resourcess
|
||||
// Delete deletes the process and its resourcess
|
||||
Delete(context.Context) error
|
||||
// Signal directly signals the process
|
||||
Signal(int) error
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
shimapi "github.com/containerd/containerd/api/services/shim"
|
||||
"github.com/containerd/containerd/api/types/container"
|
||||
"github.com/containerd/containerd/reaper"
|
||||
|
@ -54,19 +53,7 @@ func (s *Service) Create(ctx context.Context, r *shimapi.CreateRequest) (*shimap
|
|||
ExitCh: make(chan int, 1),
|
||||
}
|
||||
reaper.Default.Register(pid, cmd)
|
||||
go func() {
|
||||
status, err := reaper.Default.WaitPid(pid)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("waitpid")
|
||||
}
|
||||
process.Exited(status)
|
||||
s.events <- &container.Event{
|
||||
Type: container.Event_EXIT,
|
||||
ID: s.id,
|
||||
Pid: uint32(pid),
|
||||
ExitStatus: uint32(status),
|
||||
}
|
||||
}()
|
||||
go s.waitExit(process, pid, cmd)
|
||||
s.events <- &container.Event{
|
||||
Type: container.Event_CREATE,
|
||||
ID: r.ID,
|
||||
|
@ -111,12 +98,20 @@ func (s *Service) Exec(ctx context.Context, r *shimapi.ExecRequest) (*shimapi.Ex
|
|||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.execID++
|
||||
reaper.Default.Lock()
|
||||
process, err := newExecProcess(ctx, s.path, r, s.initProcess, s.execID)
|
||||
if err != nil {
|
||||
reaper.Default.Unlock()
|
||||
return nil, err
|
||||
}
|
||||
pid := process.Pid()
|
||||
s.processes[pid] = process
|
||||
cmd := &reaper.Cmd{
|
||||
ExitCh: make(chan int, 1),
|
||||
}
|
||||
reaper.Default.RegisterNL(pid, cmd)
|
||||
reaper.Default.Unlock()
|
||||
go s.waitExit(process, pid, cmd)
|
||||
s.events <- &container.Event{
|
||||
Type: container.Event_EXEC_ADDED,
|
||||
ID: s.id,
|
||||
|
@ -235,3 +230,14 @@ func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_pro
|
|||
}
|
||||
return empty, nil
|
||||
}
|
||||
|
||||
func (s *Service) waitExit(p process, pid int, cmd *reaper.Cmd) {
|
||||
status := <-cmd.ExitCh
|
||||
p.Exited(status)
|
||||
s.events <- &container.Event{
|
||||
Type: container.Event_EXIT,
|
||||
ID: s.id,
|
||||
Pid: uint32(pid),
|
||||
ExitStatus: uint32(status),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue