Refactor process.go for platform specific
Signed-off-by: John Howard <jhoward@microsoft.com> Move process sorter to new file Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Sort containers by id This will not be the most accurate sorting but atleast the list will be consistent inbetween calls. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Allow runtime to be configurable via daemon start This allows people to pass an alternate name or location to the runtime binary to start containers. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Fix state output for containers Return the proper state/status for a container by checking if the pid is still alive. Also fix the cleanup handling in the shim to make sure containers are not left behind. Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Properly wait for container start Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
committed by
Michael Crosby
parent
0ad7654f80
commit
b044ff0f29
@@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Process interface {
|
||||
@@ -95,7 +94,7 @@ func loadProcess(root, id string, c *container, s *ProcessState) (*process, erro
|
||||
Stderr: s.Stderr,
|
||||
},
|
||||
}
|
||||
if _, err := p.getPid(); err != nil {
|
||||
if _, err := p.getPidFromFile(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := p.ExitStatus(); err != nil {
|
||||
@@ -177,22 +176,15 @@ func (p *process) Close() error {
|
||||
return p.exitPipe.Close()
|
||||
}
|
||||
|
||||
func (p *process) getPid() (int, error) {
|
||||
for i := 0; i < 20; i++ {
|
||||
data, err := ioutil.ReadFile(filepath.Join(p.root, "pid"))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
return -1, err
|
||||
}
|
||||
i, err := strconv.Atoi(string(data))
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
p.pid = i
|
||||
return i, nil
|
||||
func (p *process) getPidFromFile() (int, error) {
|
||||
data, err := ioutil.ReadFile(filepath.Join(p.root, "pid"))
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return -1, fmt.Errorf("containerd: cannot read pid file")
|
||||
i, err := strconv.Atoi(string(data))
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
p.pid = i
|
||||
return i, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user