diff --git a/discover/discovery_containers.go b/discover/discovery_containers.go index ed9a6e0..61ac761 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 77d446a..4ff94af 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