Fix panic in CgroupCPU

If an invalid container ID is passed to CgroupCPU,
a panic can result.
pull/36/head
Jason Wilder 11 years ago
parent 812b04d363
commit 90c6c3ef3e

@ -71,7 +71,10 @@ func CgroupCPU(containerid string, base string) (*cpu.CPUTimesStat, error) {
}
path := path.Join(base, containerid, "cpuacct.stat")
lines, _ := common.ReadLines(path)
lines, err := common.ReadLines(path)
if err != nil {
return nil, err
}
// empty containerid means all cgroup
if len(containerid) == 0 {
containerid = "all"

@ -31,6 +31,13 @@ func TestCgroupCPU(t *testing.T) {
}
}
func TestCgroupCPUInvalidId(t *testing.T) {
_, err := CgroupCPUDocker("bad id")
if err == nil {
t.Error("Expected path does not exist error")
}
}
func TestCgroupMem(t *testing.T) {
v, _ := GetDockerIDList()
for _, id := range v {

Loading…
Cancel
Save