Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ProcState parsing for process names with parantheses #86

Merged
merged 2 commits into from Nov 28, 2017

Conversation

andrewkroh
Copy link
Member

  • Refactor the ProcState code that parses /proc/[PID]/stat to allow any characters between the opening and closing parentheses of the comm field.
  • This also improves the error handling in ProcState.Get. Previously errors from strconv.Atio were not checked.
  • Improved the test for ProcState to validate all fields.
  • Fix bug in test code that generates fake /proc/pid/stat data. It skipped "19" causing an off by one issue.

Fixes #81

Refactor the ProcState code that parses /proc/[PID]/stat to allow any characters between the opening and closing parentheses of the comm field.
This also improves the error handling in ProcState.Get. Previously errors from `strconv.Atio` were not checked.
Improved the test for ProcState to validate all fields.
Fix bug in test code that generates fake /proc/pid/stat data. It skipped "19" causing an off by one issue.

Fixes elastic#81
@andrewkroh
Copy link
Member Author

@immon I opened a PR for this myself because I wanted to do some additional refactoring to the code to improve error handling.

Copy link

@immon immon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// Extract the comm value with is surrounded by parentheses.
lIdx := bytes.Index(data, []byte("("))
rIdx := bytes.LastIndex(data, []byte(")"))
if lIdx < 0 || rIdx < 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should return an error also when lIdx >= rIdx || rIdx + 2 >= len(data)
to avoid crashing below.

@andrewkroh
Copy link
Member Author

This has been updated based on the review feedback.

@ruflin ruflin merged commit 52f14dd into elastic:master Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants