From 026d8e906516f9d6f596f0490b5b45b76a3893f8 Mon Sep 17 00:00:00 2001 From: Alvaro Saurin Date: Thu, 10 Sep 2015 21:42:50 +0200 Subject: [PATCH] Minor: refactored readerLinux/readIntoBuffer() for removing a parameter --- probe/proc/reader_linux.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/probe/proc/reader_linux.go b/probe/proc/reader_linux.go index 8a27ec946..52dcba7bb 100644 --- a/probe/proc/reader_linux.go +++ b/probe/proc/reader_linux.go @@ -91,19 +91,20 @@ func (w *reader) Processes(f func(Process)) error { } buf := bytes.NewBuffer(make([]byte, 0, 5000)) - readIntoBuffer := func(filename string) error { - buf.Reset() - res := w.handles.ReadInto(filename, buf) - return res - } - for _, filename := range dirEntries { - pid, err := strconv.Atoi(filename) + for _, subdir := range dirEntries { + readIntoBuffer := func(filename string) error { + buf.Reset() + res := w.handles.ReadInto(path.Join(subdir, filename), buf) + return res + } + + pid, err := strconv.Atoi(subdir) if err != nil { continue } - if readIntoBuffer(path.Join(filename, "stat")) != nil { + if readIntoBuffer("stat") != nil { continue } splits := strings.Fields(buf.String()) @@ -118,13 +119,13 @@ func (w *reader) Processes(f func(Process)) error { } cmdline := "" - if readIntoBuffer(path.Join(filename, "cmdline")) == nil { + if readIntoBuffer("cmdline") == nil { cmdlineBuf := bytes.Replace(buf.Bytes(), []byte{'\000'}, []byte{' '}, -1) cmdline = string(cmdlineBuf) } comm := "(unknown)" - if readIntoBuffer(path.Join(filename, "comm")) == nil { + if readIntoBuffer("comm") == nil { comm = strings.TrimSpace(buf.String()) }