-
Notifications
You must be signed in to change notification settings - Fork 320
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
Support Proc.Cwd() and Proc.RootDir() #109
Conversation
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.
Thank you for your contribution!
Please add some minimal tests. Have a look at the existing test setup and fixtures files. Make sure to use an example from a live sytem (some procfs files include null bytes, other trailing newlines), we might want to format the returned value.
proc.go
Outdated
@@ -156,6 +156,26 @@ func (p Proc) Executable() (string, error) { | |||
return exe, err | |||
} | |||
|
|||
// Cwd returns the absolute path to the current working directory of the process. | |||
func (p Proc) Cwd() (string, error) { | |||
exe, err := os.Readlink(p.path("cwd")) |
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.
Please rename the variable to cwd
or at least a generic v
.
proc.go
Outdated
|
||
// RootDir returns the absolute path to the process's root directory (as set by chroot) | ||
func (p Proc) RootDir() (string, error) { | ||
exe, err := os.Readlink(p.path("root")) |
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.
Please rename the variable to root
or at least a generic v
.
Signed-off-by: Pavel Khlebovich <pas.nteg@gmail.com>
Got it. Nice fixture system, by the way. Since the introduced functions only operate on symlinks, the returned data should be as reliable as the one returned by os.Readlink(). Tests are included for the missing, broken and valid symlinks. |
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.
Thanks! I was missing that these are just symlinks.
Signed-off-by: Pavel Khlebovich <pas.nteg@gmail.com>
Addressing @grobie, as per contributing guidelines for trivial improvement.
The PR implements reading /proc/pid/cwd and /proc/pid/root similar to how /proc/pid/exe is implemented.
Naming is inspired by https://talks.golang.org/2014/names.slide and golang standard library.