From 0088e847ef97bcdbb9248e1d1b60175cfd587212 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 20 Jan 2023 17:52:28 +0100 Subject: [PATCH] cmd/nerdctl: withBindMountHostIPC: slight refactor Use a switch so that path.Clean() is not called repeatedly, and unify the implementation for both mount paths. Signed-off-by: Sebastiaan van Stijn --- cmd/nerdctl/run.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/cmd/nerdctl/run.go b/cmd/nerdctl/run.go index aed79cab273..cc376328250 100644 --- a/cmd/nerdctl/run.go +++ b/cmd/nerdctl/run.go @@ -901,23 +901,14 @@ func generateRootfsOpts(ctx context.Context, client *containerd.Client, platform // Required for --ipc=host on rootless. func withBindMountHostIPC(_ context.Context, _ oci.Client, _ *containers.Container, s *oci.Spec) error { for i, m := range s.Mounts { - if path.Clean(m.Destination) == "/dev/shm" { - newM := specs.Mount{ - Destination: "/dev/shm", + switch p := path.Clean(m.Destination); p { + case "/dev/shm", "/dev/mqueue": + s.Mounts[i] = specs.Mount{ + Destination: p, Type: "bind", - Source: "/dev/shm", + Source: p, Options: []string{"rbind", "nosuid", "noexec", "nodev"}, } - s.Mounts[i] = newM - } - if path.Clean(m.Destination) == "/dev/mqueue" { - newM := specs.Mount{ - Destination: "/dev/mqueue", - Type: "bind", - Source: "/dev/mqueue", - Options: []string{"rbind", "nosuid", "noexec", "nodev"}, - } - s.Mounts[i] = newM } } return nil