diff options
| author | Paul Buetow <paul@buetow.org> | 2025-03-06 22:40:41 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-03-06 22:40:41 +0200 |
| commit | 0b06e51ea1d6eec4db969064708e1ba997e14f1d (patch) | |
| tree | 41085326d1f90d6635a72ecb3208d94ec8be9a99 /internal/file.go | |
| parent | c9490649f7474c6442637b71c04b235713853ca8 (diff) | |
can gather file path from proc fs if unknown
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 |
