diff --git a/pkg/sentry/kernel/task.go b/pkg/sentry/kernel/task.go index 6d53f4f7e..c0c9c0298 100644 --- a/pkg/sentry/kernel/task.go +++ b/pkg/sentry/kernel/task.go @@ -809,6 +809,12 @@ func (t *Task) ContainerID() string { return t.containerID } +// RestoreContainerID sets t's container ID in case the restored container ID +// is different from when it was saved. +func (t *Task) RestoreContainerID(cid string) { + t.containerID = cid +} + // OOMScoreAdj gets the task's thread group's OOM score adjustment. func (t *Task) OOMScoreAdj() int32 { return t.tg.oomScoreAdj.Load() diff --git a/runsc/boot/controller.go b/runsc/boot/controller.go index e8d9297b2..cd80b4bb8 100644 --- a/runsc/boot/controller.go +++ b/runsc/boot/controller.go @@ -553,6 +553,15 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { // restore the state of multiple containers, nor exec processes. cm.l.sandboxID = o.SandboxID cm.l.mu.Lock() + + // Set new container ID if it has changed. + tasks := cm.l.k.TaskSet().Root.Tasks() + if tasks[0].ContainerID() != o.SandboxID { // There must be at least 1 task. + for _, task := range tasks { + task.RestoreContainerID(o.SandboxID) + } + } + eid := execID{cid: o.SandboxID} cm.l.processes = map[execID]*execProcess{ eid: {