From 50afe5b031a6b63f9eca3937a2dd104bf23d4828 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 15 Aug 2018 17:27:26 +0200 Subject: podman: fix --uts=host Do not set any hostname value in the OCI configuration when --uts=host is used and the user didn't specify any value. This prevents an error from the OCI runtime as it cannot set the hostname without a new UTS namespace. Differently, the HOSTNAME environment variable is always set. When --uts=host is used, HOSTNAME gets the value from the host. Signed-off-by: Giuseppe Scrivano Closes: #1280 Approved by: baude --- libpod/container_internal_linux.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'libpod/container_internal_linux.go') diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 2aba1abde..ba02c9f5a 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -215,8 +215,14 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) { g.AddAnnotation(crioAnnotations.Created, c.config.CreatedTime.Format(time.RFC3339Nano)) g.AddAnnotation("org.opencontainers.image.stopSignal", fmt.Sprintf("%d", c.config.StopSignal)) - g.SetHostname(c.Hostname()) - g.AddProcessEnv("HOSTNAME", g.Config.Hostname) + for _, i := range c.config.Spec.Linux.Namespaces { + if string(i.Type) == spec.UTSNamespace { + hostname := c.Hostname() + g.SetHostname(hostname) + g.AddProcessEnv("HOSTNAME", hostname) + break + } + } // Only add container environment variable if not already present foundContainerEnv := false -- cgit v1.2.3-54-g00ecf