From 13841ef37da97bfaaed4e14a6c18638a53a62d01 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Tue, 23 Dec 2014 16:09:35 +0300 Subject: [PATCH] new-api: return the Running state only if the init process is alive Signed-off-by: Andrey Vagin --- linux_container.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/linux_container.go b/linux_container.go index bbd0cb1d..ea202df4 100644 --- a/linux_container.go +++ b/linux_container.go @@ -34,7 +34,27 @@ func (c *linuxContainer) Config() *configs.Config { } func (c *linuxContainer) RunState() (configs.RunState, error) { - return configs.Destroyed, nil // FIXME return a real state + if c.state.InitPid <= 0 { + return configs.Destroyed, nil + } + + // return Running if the init process is alive + err := syscall.Kill(c.state.InitPid, 0) + if err != nil { + errn, y := err.(syscall.Errno) + if !y { + return 0, err + } + + if errn == syscall.ESRCH { + return configs.Destroyed, nil + } + return 0, err + } + + //FIXME get a cgroup state to check other states + + return configs.Running, nil } func (c *linuxContainer) Processes() ([]int, error) {