2016-10-03 22:20:45 +00:00
|
|
|
package oci
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
2016-12-05 22:15:03 +00:00
|
|
|
|
|
|
|
"github.com/docker/containerd/execution"
|
2016-10-03 22:20:45 +00:00
|
|
|
)
|
|
|
|
|
2016-12-05 23:38:32 +00:00
|
|
|
func newProcess(id string, pid int) (execution.Process, error) {
|
2016-10-03 22:20:45 +00:00
|
|
|
proc, err := os.FindProcess(pid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &process{
|
2016-12-05 23:38:32 +00:00
|
|
|
id: id,
|
2016-10-03 22:20:45 +00:00
|
|
|
proc: proc,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type process struct {
|
2016-12-05 23:38:32 +00:00
|
|
|
id string
|
2016-10-03 22:20:45 +00:00
|
|
|
proc *os.Process
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:38:32 +00:00
|
|
|
func (p *process) ID() string {
|
|
|
|
return p.id
|
|
|
|
}
|
|
|
|
|
2016-10-03 22:20:45 +00:00
|
|
|
func (p *process) Pid() int {
|
|
|
|
return p.proc.Pid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *process) Wait() (uint32, error) {
|
|
|
|
state, err := p.proc.Wait()
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil
|
|
|
|
}
|
2016-12-05 23:38:32 +00:00
|
|
|
// TODO: implement kill-all if we are the init pid
|
2016-10-03 22:20:45 +00:00
|
|
|
return uint32(state.Sys().(syscall.WaitStatus).ExitStatus()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *process) Signal(s os.Signal) error {
|
|
|
|
return p.proc.Signal(s)
|
|
|
|
}
|