diff --git a/pkg/sentry/control/proc.go b/pkg/sentry/control/proc.go index 7fd4ffaf0..fbc025233 100644 --- a/pkg/sentry/control/proc.go +++ b/pkg/sentry/control/proc.go @@ -266,9 +266,8 @@ func (proc *Proc) execAsync(args *ExecArgs) (*kernel.ThreadGroup, kernel.ThreadI initArgs.Filename = resolved } - // TODO(gvisor.dev/issue/1956): Container name is not really needed because - // exec processes are not restored, but add it for completeness. - ttyFile, err := fdimport.Import(ctx, fdTable, args.StdioIsPty, args.KUID, args.KGID, fdMap, "") + containerName := proc.Kernel.ContainerNameGivenID(args.ContainerID) + ttyFile, err := fdimport.Import(ctx, fdTable, args.StdioIsPty, args.KUID, args.KGID, fdMap, containerName) if err != nil { return nil, 0, nil, err } diff --git a/pkg/sentry/kernel/kernel.go b/pkg/sentry/kernel/kernel.go index 73237adb7..6aa6a21f6 100644 --- a/pkg/sentry/kernel/kernel.go +++ b/pkg/sentry/kernel/kernel.go @@ -348,6 +348,9 @@ type Kernel struct { // devGofers maps container ID to its device gofer client. devGofers map[string]*devutil.GoferClient `state:"nosave"` devGofersMu sync.Mutex `state:"nosave"` + + // cid -> name. + containerNames map[string]string } // InitKernelArgs holds arguments to Init. @@ -454,6 +457,7 @@ func (k *Kernel) Init(args InitKernelArgs) error { args.MaxFDLimit = MaxFdLimit } k.MaxFDLimit.Store(args.MaxFDLimit) + k.containerNames = make(map[string]string) ctx := k.SupervisorContext() if err := k.vfs.Init(ctx); err != nil { @@ -1956,3 +1960,13 @@ func (k *Kernel) cleaupDevGofers() { } k.devGofers = nil } + +// RegisterContainerName registers a container name for a given container ID. +func (k *Kernel) RegisterContainerName(cid, containerName string) { + k.containerNames[cid] = containerName +} + +// ContainerNameGivenID returns the container name for a given container ID. +func (k *Kernel) ContainerNameGivenID(cid string) string { + return k.containerNames[cid] +} diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go index a9c214e41..3edbcb157 100644 --- a/runsc/boot/loader.go +++ b/runsc/boot/loader.go @@ -543,6 +543,7 @@ func New(args Args) (*Loader, error) { } } + k.RegisterContainerName(args.ID, info.containerName) eid := execID{cid: args.ID} l := &Loader{ k: k, @@ -954,6 +955,7 @@ func (l *Loader) startSubcontainer(spec *specs.Spec, conf *config.Config, cid st }) } + l.k.RegisterContainerName(cid, info.containerName) l.k.StartProcess(ep.tg) // No more failures from this point on. cu.Release()