From 0b06e51ea1d6eec4db969064708e1ba997e14f1d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 6 Mar 2025 22:40:41 +0200 Subject: can gather file path from proc fs if unknown --- internal/file.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'internal/file.go') 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 -- cgit v1.2.3