Improve process addition and removal
Signed-off-by: Michael Crosby <crosbymichael@gmail.com> implement pause and resume Add godeps Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Add readme Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
17d9c10e2d
commit
f9ad7970d2
397 changed files with 48104 additions and 22 deletions
|
@ -184,12 +184,36 @@ func (p *libcontainerProcess) Signal(s os.Signal) error {
|
|||
type libcontainerContainer struct {
|
||||
c libcontainer.Container
|
||||
initProcess *libcontainerProcess
|
||||
additionalProcesses []*libcontainerProcess
|
||||
additionalProcesses map[int]*libcontainerProcess
|
||||
exitStatus int
|
||||
exited bool
|
||||
path string
|
||||
}
|
||||
|
||||
func (c *libcontainerContainer) Resume() error {
|
||||
return c.c.Resume()
|
||||
}
|
||||
|
||||
func (c *libcontainerContainer) Pause() error {
|
||||
return c.c.Pause()
|
||||
}
|
||||
|
||||
func (c *libcontainerContainer) State() State {
|
||||
s := State{}
|
||||
// TODO: what to do with error
|
||||
state, err := c.c.Status()
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
switch state {
|
||||
case libcontainer.Paused, libcontainer.Pausing:
|
||||
s.Status = Paused
|
||||
default:
|
||||
s.Status = Running
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (c *libcontainerContainer) ID() string {
|
||||
return c.c.ID()
|
||||
}
|
||||
|
@ -226,6 +250,14 @@ func (c *libcontainerContainer) Processes() ([]Process, error) {
|
|||
return procs, nil
|
||||
}
|
||||
|
||||
func (c *libcontainerContainer) RemoveProcess(pid int) error {
|
||||
if _, ok := c.additionalProcesses[pid]; !ok {
|
||||
return errNotChildProcess
|
||||
}
|
||||
delete(c.additionalProcesses, pid)
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewRuntime(stateDir string) (Runtime, error) {
|
||||
f, err := libcontainer.New(stateDir, libcontainer.Cgroupfs, func(l *libcontainer.LinuxFactory) error {
|
||||
//l.CriuPath = context.GlobalString("criu")
|
||||
|
@ -237,7 +269,6 @@ func NewRuntime(stateDir string) (Runtime, error) {
|
|||
return &libcontainerRuntime{
|
||||
factory: f,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
type libcontainerRuntime struct {
|
||||
|
@ -262,7 +293,8 @@ func (r *libcontainerRuntime) Create(id, bundlePath string) (Container, error) {
|
|||
}
|
||||
process := r.newProcess(spec.Process)
|
||||
c := &libcontainerContainer{
|
||||
c: container,
|
||||
c: container,
|
||||
additionalProcesses: make(map[int]*libcontainerProcess),
|
||||
initProcess: &libcontainerProcess{
|
||||
process: process,
|
||||
spec: spec.Process,
|
||||
|
@ -285,7 +317,11 @@ func (r *libcontainerRuntime) StartProcess(ci Container, p specs.Process) (Proce
|
|||
process: process,
|
||||
spec: p,
|
||||
}
|
||||
c.additionalProcesses = append(c.additionalProcesses, lp)
|
||||
pid, err := process.Pid()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.additionalProcesses[pid] = lp
|
||||
return lp, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue