Skip to content

Commit

Permalink
fix: use engine's PPID for container PID translation when engine PID …
Browse files Browse the repository at this point in the history
…not yet in discovered process tree

Signed-off-by: thediveo <[email protected]>
  • Loading branch information
thediveo committed Jan 7, 2024
1 parent 9ccce92 commit 68991e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions discover/discovery_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions model/containerengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68991e0

Please sign in to comment.