diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-10 22:35:52 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-10 22:35:52 +0200 |
| commit | 064d967df9629acd16a5c1cd3a1007e22071f86c (patch) | |
| tree | a9433a5e27cc8c4b777a0b6d4c87d26485bb485d /internal/eventloop.go | |
| parent | 80d8993dca4cf7945c492406489fb9d966e2dc44 (diff) | |
eventloop: avoid fmt.Sprintf in proc comm lookup (task 426)
Diffstat (limited to 'internal/eventloop.go')
| -rw-r--r-- | internal/eventloop.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go index 27b48e7..4b4c0c0 100644 --- a/internal/eventloop.go +++ b/internal/eventloop.go @@ -9,6 +9,7 @@ import ( "path/filepath" "reflect" "sort" + "strconv" "sync" "syscall" "time" @@ -1210,9 +1211,13 @@ func (e *eventLoop) queueCommLookup(tid uint32) { e.commState().queueLookup(tid) } +func procTidPathPrefix(tid uint32) string { + return "/proc/" + strconv.FormatUint(uint64(tid), 10) +} + func resolveCommFromProc(tid uint32) string { - commPath := fmt.Sprintf("/proc/%d/comm", tid) - if data, err := os.ReadFile(commPath); err == nil { + procPath := procTidPathPrefix(tid) + if data, err := os.ReadFile(procPath + "/comm"); err == nil { comm := string(data) if len(comm) > 0 && comm[len(comm)-1] == '\n' { comm = comm[:len(comm)-1] @@ -1221,7 +1226,7 @@ func resolveCommFromProc(tid uint32) string { return comm } } - if linkName, err := os.Readlink(fmt.Sprintf("/proc/%d/exe", tid)); err == nil { + if linkName, err := os.Readlink(procPath + "/exe"); err == nil { linkName = filepath.Base(linkName) return linkName } |
