From 68991e0d07c3570f593a99611b8df225b73db2e7 Mon Sep 17 00:00:00 2001 From: thediveo Date: Sun, 7 Jan 2024 22:01:01 +0100 Subject: [PATCH] fix: use engine's PPID for container PID translation when engine PID not yet in discovered process tree Signed-off-by: thediveo --- discover/discovery_containers.go | 16 ++++++++++++++++ model/containerengine.go | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/discover/discovery_containers.go b/discover/discovery_containers.go index ed9a6e03..61ac7618 100644 --- a/discover/discovery_containers.go +++ b/discover/discovery_containers.go @@ -60,6 +60,22 @@ func discoverContainers(result *Result) { if !ok { if engineProc, ok := result.Processes[container.Engine.PID]; ok { enginePIDns = engineProc.Namespaces[model.PIDNS] + } else if container.Engine.PPIDHint != 0 { + // This is a newly socket-activated engine that isn't yet + // included in the process tree – that process tree that + // ironically lead to the detection of the socket activator and + // then activation of that container engine. As we cannot change + // the past discovery some kind soul – a turtle, perchance? – + // might have passed us a hint about the engine's parent process + // PID. This parent process's PID namespace should be the same + // as the container engine, so it should be good for container + // PID translation. + // + // This deserves a badge: [COMMENTOR] ... rhymes with + // "tormentor" *snicker* + if parentProc, ok := result.Processes[container.Engine.PPIDHint]; ok { + enginePIDns = parentProc.Namespaces[model.PIDNS] + } } // Cache even unsuckcessful engine PID namespace lookups. enginesPIDns[container.Engine] = enginePIDns diff --git a/model/containerengine.go b/model/containerengine.go index 77d446a7..4ff94aff 100644 --- a/model/containerengine.go +++ b/model/containerengine.go @@ -32,6 +32,13 @@ type ContainerEngine struct { // Containers discovered from this container engine. Containers []*Container `json:"-"` + + // Not for general use: engine process parent's PID to allow correctly + // translating container PIDs for newly socket-activated container engines – + // these would otherwise not be translatable as the newly socket-activated + // engine process information isn't (yet) part of the process tree scan + // before the engine activation. + PPIDHint PIDType `json:"-"` } // AddContainer adds a container to the list of discovered containers belonging