36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
39 lines
652 B
Go
39 lines
652 B
Go
//go:build linux
|
|
|
|
package proc
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func socketsForPID(pid int) []string {
|
|
var inodes []string
|
|
seen := make(map[string]bool)
|
|
fdPath := "/proc/" + strconv.Itoa(pid) + "/fd"
|
|
|
|
entries, err := os.ReadDir(fdPath)
|
|
if err != nil {
|
|
return inodes
|
|
}
|
|
|
|
for _, e := range entries {
|
|
link, err := os.Readlink(filepath.Join(fdPath, e.Name()))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
if strings.HasPrefix(link, "socket:[") {
|
|
inode := strings.TrimSuffix(strings.TrimPrefix(link, "socket:["), "]")
|
|
if !seen[inode] {
|
|
seen[inode] = true
|
|
inodes = append(inodes, inode)
|
|
}
|
|
}
|
|
}
|
|
|
|
return inodes
|
|
}
|