execution/oci: use Status type instead of string
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
7dd69a8597
commit
abaa421141
8 changed files with 56 additions and 44 deletions
|
@ -113,7 +113,7 @@ func (r *OCIRuntime) load(runcC *runc.Container) (*execution.Container, error) {
|
|||
execution.StateDir(filepath.Join(r.root, runcC.ID)),
|
||||
runcC.ID,
|
||||
runcC.Bundle,
|
||||
runcC.Status,
|
||||
execution.Status(runcC.Status),
|
||||
int64(runcC.Pid),
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package oci
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
|
@ -8,21 +9,27 @@ import (
|
|||
)
|
||||
|
||||
func newProcess(c *execution.Container, id string, pid int) (execution.Process, error) {
|
||||
proc, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
status := execution.Running
|
||||
if err := syscall.Kill(pid, 0); err != nil {
|
||||
if err == syscall.ESRCH {
|
||||
status = execution.Stopped
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &process{
|
||||
c: c,
|
||||
id: id,
|
||||
proc: proc,
|
||||
c: c,
|
||||
id: id,
|
||||
pid: pid,
|
||||
status: status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type process struct {
|
||||
c *execution.Container
|
||||
id string
|
||||
proc *os.Process
|
||||
c *execution.Container
|
||||
id string
|
||||
pid int
|
||||
status execution.Status
|
||||
}
|
||||
|
||||
func (p *process) Container() *execution.Container {
|
||||
|
@ -34,18 +41,35 @@ func (p *process) ID() string {
|
|||
}
|
||||
|
||||
func (p *process) Pid() int64 {
|
||||
return int64(p.proc.Pid)
|
||||
return int64(p.pid)
|
||||
}
|
||||
|
||||
func (p *process) Wait() (uint32, error) {
|
||||
state, err := p.proc.Wait()
|
||||
if err != nil {
|
||||
return 0, nil
|
||||
if p.status == execution.Running {
|
||||
var wstatus syscall.WaitStatus
|
||||
_, err := syscall.Wait4(p.pid, &wstatus, 0, nil)
|
||||
if err != nil {
|
||||
return 255, nil
|
||||
}
|
||||
// TODO: implement kill-all if we are the init pid
|
||||
p.status = execution.Stopped
|
||||
return uint32(wstatus.ExitStatus()), nil
|
||||
}
|
||||
// TODO: implement kill-all if we are the init pid
|
||||
return uint32(state.Sys().(syscall.WaitStatus).ExitStatus()), nil
|
||||
|
||||
return 255, execution.ErrProcessNotFound
|
||||
}
|
||||
|
||||
func (p *process) Signal(s os.Signal) error {
|
||||
return p.proc.Signal(s)
|
||||
if p.status == execution.Running {
|
||||
sig, ok := s.(syscall.Signal)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid signal %v", s)
|
||||
}
|
||||
return syscall.Kill(p.pid, sig)
|
||||
}
|
||||
return execution.ErrProcessNotFound
|
||||
}
|
||||
|
||||
func (p *process) Status() execution.Status {
|
||||
return p.status
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue