diff options
Diffstat (limited to 'internal/file.go')
| -rw-r--r-- | internal/file.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/file.go b/internal/file.go index 9230afd..efb570b 100644 --- a/internal/file.go +++ b/internal/file.go @@ -1,6 +1,8 @@ package internal import ( + "fmt" + "os" "strconv" "strings" ) @@ -14,6 +16,17 @@ type fdFile struct { name string } +func newFdFile(fd int32, name string) fdFile { + return fdFile{fd, name} +} + +func newFdFileWithPid(fd int32, pid uint32) fdFile { + if linkName, err := os.Readlink(fmt.Sprintf("/proc/%d/fd/%d", pid, fd)); err == nil { + return fdFile{fd, linkName} + } + return fdFile{fd, "?"} +} + func (f fdFile) String() string { var sb strings.Builder |
