Skip to content

Commit

Permalink
Merge pull request #2316 from weaveworks/2315-empty-proc-cmdline
Browse files Browse the repository at this point in the history
fall back to /proc/<pid>/comm for process name

Fixes #2315
  • Loading branch information
rade authored Mar 9, 2017
2 parents 1d18ba6 + 245c2e9 commit 456ac0b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions probe/process/walker_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (w *walker) Walk(f func(Process, Process)) error {
continue
}

cmdline, name := "", "(unknown)"
cmdline, name := "", ""
if cmdlineBuf, err := cachedReadFile(path.Join(w.procRoot, filename, "cmdline")); err == nil {
// like proc, treat name as the first element of command line
i := bytes.IndexByte(cmdlineBuf, '\000')
Expand All @@ -123,7 +123,13 @@ func (w *walker) Walk(f func(Process, Process)) error {
cmdlineBuf = bytes.Replace(cmdlineBuf, []byte{'\000'}, []byte{' '}, -1)
cmdline = string(cmdlineBuf)
}

if name == "" {
if commBuf, err := cachedReadFile(path.Join(w.procRoot, filename, "comm")); err == nil {
name = "[" + strings.TrimSpace(string(commBuf)) + "]"
} else {
name = "(unknown)"
}
}
f(Process{
PID: pid,
PPID: ppid,
Expand Down

0 comments on commit 456ac0b

Please sign in to comment.