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
25 lines
645 B
Go
25 lines
645 B
Go
//go:build linux
|
|
|
|
package proc
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// PIDBelongsToContainer verifies that the host process at pid actually belongs
|
|
// to the given container by checking its cgroup membership. Guards against
|
|
// the case where docker inspect returns a PID that's namespaced to a Docker
|
|
// VM (macOS, Windows) and happens to coincide with an unrelated host PID.
|
|
func PIDBelongsToContainer(pid int, containerID string) bool {
|
|
if pid <= 0 || containerID == "" {
|
|
return false
|
|
}
|
|
data, err := os.ReadFile(fmt.Sprintf("/proc/%d/cgroup", pid))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return strings.Contains(string(data), containerID)
|
|
}
|