Skip to content

Commit

Permalink
daemon: identify container exits by ProcessID
Browse files Browse the repository at this point in the history
The Pid field of an exit event cannot be relied upon to differentiate
exits of the container's task from exits of other container processes,
i.e. execs. The Pid is reported by the runtime and is implementation-
defined so there is no guarantee that a task's pid is distinct from the
pids of any other process in the same container. In particular,
kata-containers reports the pid of the hypervisor for all exit events.
Update the daemon to differentiate container exits from exec exits by
inspecting the event's ProcessID.

The local_windows libcontainerd implementation already sets the
ProcessID to InitProcessName on container exit events. Update the remote
libcontainerd implementation to match. ContainerD guarantees that the
process ID of a task (container init process) is set to the
corresponding container ID, so use that invariant to distinguish task
exits from other process exits.

Signed-off-by: Cory Snider <csnider@mirantis.com>
  • Loading branch information
corhere committed Jan 31, 2023
1 parent d7573ab commit 19105c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/monitor.go
Expand Up @@ -148,7 +148,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerdtypes.EventType, ei

daemon.LogContainerEvent(c, "oom")
case libcontainerdtypes.EventExit:
if int(ei.Pid) == c.Pid {
if ei.ProcessID == libcontainerdtypes.InitProcessName {
return daemon.handleContainerExit(c, &ei)
}

Expand Down
3 changes: 3 additions & 0 deletions libcontainerd/remote/client.go
Expand Up @@ -823,6 +823,9 @@ func (c *client) processEventStream(ctx context.Context, ns string) {
ExitCode: t.ExitStatus,
ExitedAt: t.ExitedAt,
}
if t.ID == t.ContainerID {
ei.ProcessID = libcontainerdtypes.InitProcessName
}
case *apievents.TaskOOM:
et = libcontainerdtypes.EventOOM
ei = libcontainerdtypes.EventInfo{
Expand Down

0 comments on commit 19105c7

Please sign in to comment.