diff --git a/daemon/procmon/details.go b/daemon/procmon/details.go index 7ad7fc9c6a..9769de51e1 100644 --- a/daemon/procmon/details.go +++ b/daemon/procmon/details.go @@ -304,10 +304,10 @@ func (p *Process) readDescriptors() { } } -func (p *Process) readIOStats() { +func (p *Process) readIOStats() (err error) { f, err := os.Open(p.pathIO) if err != nil { - return + return err } defer f.Close() @@ -318,19 +318,21 @@ func (p *Process) readIOStats() { s := strings.Split(scanner.Text(), " ") switch s[0] { case "rchar:": - p.IOStats.RChar, _ = strconv.ParseInt(s[1], 10, 64) + p.IOStats.RChar, err = strconv.ParseInt(s[1], 10, 64) case "wchar:": - p.IOStats.WChar, _ = strconv.ParseInt(s[1], 10, 64) + p.IOStats.WChar, err = strconv.ParseInt(s[1], 10, 64) case "syscr:": - p.IOStats.SyscallRead, _ = strconv.ParseInt(s[1], 10, 64) + p.IOStats.SyscallRead, err = strconv.ParseInt(s[1], 10, 64) case "syscw:": - p.IOStats.SyscallWrite, _ = strconv.ParseInt(s[1], 10, 64) + p.IOStats.SyscallWrite, err = strconv.ParseInt(s[1], 10, 64) case "read_bytes:": - p.IOStats.ReadBytes, _ = strconv.ParseInt(s[1], 10, 64) + p.IOStats.ReadBytes, err = strconv.ParseInt(s[1], 10, 64) case "write_bytes:": - p.IOStats.WriteBytes, _ = strconv.ParseInt(s[1], 10, 64) + p.IOStats.WriteBytes, err = strconv.ParseInt(s[1], 10, 64) } } + + return err } func (p *Process) readStatus() { diff --git a/daemon/procmon/process_test.go b/daemon/procmon/process_test.go index 2528e564b3..bbf5479361 100644 --- a/daemon/procmon/process_test.go +++ b/daemon/procmon/process_test.go @@ -61,26 +61,11 @@ func TestProcEnv(t *testing.T) { } func TestProcIOStats(t *testing.T) { - proc.readIOStats() + err := proc.readIOStats() - if proc.IOStats.RChar == 0 { - t.Error("Proc.IOStats.RChar should not be 0:", proc.IOStats) + if err != nil { + t.Error("error reading proc IOStats:", err) } - if proc.IOStats.WChar == 0 { - t.Error("Proc.IOStats.WChar should not be 0:", proc.IOStats) - } - if proc.IOStats.SyscallRead == 0 { - t.Error("Proc.IOStats.SyscallRead should not be 0:", proc.IOStats) - } - if proc.IOStats.SyscallWrite == 0 { - t.Error("Proc.IOStats.SyscallWrite should not be 0:", proc.IOStats) - } - /*if proc.IOStats.ReadBytes == 0 { - t.Error("Proc.IOStats.ReadBytes should not be 0:", proc.IOStats) - } - if proc.IOStats.WriteBytes == 0 { - t.Error("Proc.IOStats.WriteBytes should not be 0:", proc.IOStats) - }*/ } func TestProcStatus(t *testing.T) {