libc8d/local: set task id to container id

ContainerD unconditionally sets the ID of a task to its container's ID.
Emulate this behaviour in the libcontainerd local_windows implementation
so that the daemon can use ProcessID == ContainerID (in libcontainerd
terminology) to identify that an exit event is for the container's task
and not for another process (i.e. an exec) in the same container.

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2023-01-30 13:26:26 -05:00
parent b39c255d8c
commit 719b08313f

View file

@ -461,7 +461,7 @@ func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachS
} }
}() }()
t := &task{process: process{ t := &task{process: process{
id: libcontainerdtypes.InitProcessName, id: ctr.id,
ctr: ctr, ctr: ctr,
hcsProcess: newProcess, hcsProcess: newProcess,
waitCh: make(chan struct{}), waitCh: make(chan struct{}),
@ -495,7 +495,7 @@ func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachS
ctr.client.eventQ.Append(ctr.id, func() { ctr.client.eventQ.Append(ctr.id, func() {
ei := libcontainerdtypes.EventInfo{ ei := libcontainerdtypes.EventInfo{
ContainerID: ctr.id, ContainerID: ctr.id,
ProcessID: libcontainerdtypes.InitProcessName, ProcessID: t.id,
Pid: pid, Pid: pid,
} }
ctr.client.logger.WithFields(logrus.Fields{ ctr.client.logger.WithFields(logrus.Fields{
@ -793,7 +793,7 @@ func (t *task) Pause(_ context.Context) error {
t.ctr.client.eventQ.Append(t.ctr.id, func() { t.ctr.client.eventQ.Append(t.ctr.id, func() {
err := t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventPaused, libcontainerdtypes.EventInfo{ err := t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventPaused, libcontainerdtypes.EventInfo{
ContainerID: t.ctr.id, ContainerID: t.ctr.id,
ProcessID: libcontainerdtypes.InitProcessName, ProcessID: t.id,
}) })
t.ctr.client.logger.WithFields(logrus.Fields{ t.ctr.client.logger.WithFields(logrus.Fields{
"container": t.ctr.id, "container": t.ctr.id,
@ -834,7 +834,7 @@ func (t *task) Resume(ctx context.Context) error {
t.ctr.client.eventQ.Append(t.ctr.id, func() { t.ctr.client.eventQ.Append(t.ctr.id, func() {
err := t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventResumed, libcontainerdtypes.EventInfo{ err := t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventResumed, libcontainerdtypes.EventInfo{
ContainerID: t.ctr.id, ContainerID: t.ctr.id,
ProcessID: libcontainerdtypes.InitProcessName, ProcessID: t.id,
}) })
t.ctr.client.logger.WithFields(logrus.Fields{ t.ctr.client.logger.WithFields(logrus.Fields{
"container": t.ctr.id, "container": t.ctr.id,