Add exec APIs
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
cccf5d3723
commit
7715ddcefa
19 changed files with 759 additions and 126 deletions
|
@ -139,3 +139,7 @@ func (e *execProcess) Resize(ws console.WinSize) error {
|
|||
}
|
||||
return e.console.Resize(ws)
|
||||
}
|
||||
|
||||
func (e *execProcess) Signal(sig int) error {
|
||||
return syscall.Kill(e.pid, syscall.Signal(sig))
|
||||
}
|
||||
|
|
|
@ -169,3 +169,7 @@ func (p *initProcess) killAll(context context.Context) error {
|
|||
All: true,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *initProcess) Signal(sig int) error {
|
||||
return syscall.Kill(p.pid, syscall.Signal(sig))
|
||||
}
|
||||
|
|
|
@ -15,5 +15,8 @@ type process interface {
|
|||
Exited(status int)
|
||||
// Status returns the exit status
|
||||
Status() int
|
||||
// Delete delets the process and its resourcess
|
||||
Delete(context.Context) error
|
||||
// Signal directly signals the process
|
||||
Signal(int) error
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package shim
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
@ -219,7 +220,17 @@ func (s *Service) Exit(ctx context.Context, r *shimapi.ExitRequest) (*google_pro
|
|||
}
|
||||
|
||||
func (s *Service) Kill(ctx context.Context, r *shimapi.KillRequest) (*google_protobuf.Empty, error) {
|
||||
if err := s.initProcess.Kill(ctx, r.Signal, r.All); err != nil {
|
||||
if r.Pid == 0 {
|
||||
if err := s.initProcess.Kill(ctx, r.Signal, r.All); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return empty, nil
|
||||
}
|
||||
proc, ok := s.processes[int(r.Pid)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("process does not exist %d", r.Pid)
|
||||
}
|
||||
if err := proc.Signal(int(r.Signal)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return empty, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue