-
Notifications
You must be signed in to change notification settings - Fork 76
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
Finish ss example mapping connections to pids #151
base: master
Are you sure you want to change the base?
Conversation
ea41410
to
3893a52
Compare
@elastic/agent |
@fearful-symmetry can you take a look? |
|
||
fds, err := pidDir.Readdirnames(0) | ||
if err != nil { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For errors like this, where there's no expectation that they might fail, we might want to actually fail, or at least comment if we expect them to fail for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could fail if the pid has finished and the dir does not exists any more.
Failing there will generate a lot of useless "warnings" IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case, can we at least add a comment to clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gomacro> import "os"
gomacro> a, err := os.Open("/proc/955374/fd")
gomacro> err
<nil> // error
<--- here I kill process 955374
gomacro> a.Readdirnames(0)
[] // []string
readdirent: no such file or directory // error
gomacro>
It is commented in line 126
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Considering that we can hit errors relating to non-existent PIDs in a few places, can we move that comment block in 126 out of that if
block and move it somewhere, perhaps before the Open
call just to make the comment a little more explicit?
for _, fd := range fds { | ||
link, err := os.Readlink("/proc/" + string(pid) + "/fd/" + fd) | ||
if err != nil { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here.
Implementation similar to ss https://fossies.org/linux/iproute2/misc/ss.c
3893a52
to
c33f375
Compare
Implementation similar to ss
https://fossies.org/linux/iproute2/misc/ss.c