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 --- pkg/spec/spec.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'pkg') diff --git a/pkg/spec/spec.go b/pkg/spec/spec.go index 97305610a..dec3a05ef 100644 --- a/pkg/spec/spec.go +++ b/pkg/spec/spec.go @@ -74,18 +74,23 @@ func CreateConfigToOCISpec(config *CreateConfig) (*spec.Spec, error) { //nolint g.AddAnnotation(key, val) } g.SetRootReadonly(config.ReadOnlyRootfs) - if config.Hostname == "" { - if config.NetMode.IsHost() { - config.Hostname, err = os.Hostname() - if err != nil { - return nil, errors.Wrap(err, "unable to retrieve hostname") - } + + hostname := config.Hostname + if hostname == "" && (config.NetMode.IsHost() || config.UtsMode.IsHost()) { + hostname, err = os.Hostname() + if err != nil { + return nil, errors.Wrap(err, "unable to retrieve hostname") } } - g.SetHostname(config.Hostname) - if config.Hostname != "" { - g.AddProcessEnv("HOSTNAME", config.Hostname) + g.RemoveHostname() + if config.Hostname != "" || !config.UtsMode.IsHost() { + // Set the hostname in the OCI configuration only + // if specified by the user or if we are creating + // a new UTS namespace. + g.SetHostname(hostname) } + g.AddProcessEnv("HOSTNAME", hostname) + for sysctlKey, sysctlVal := range config.Sysctl { g.AddLinuxSysctl(sysctlKey, sysctlVal) } -- cgit v1.2.3-54-g00ecf