summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-04-30 16:25:45 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2020-05-01 13:26:50 -0400
commit8173e830544e74284c5bd4510f52b9e19fe25baa (patch)
tree4e866d45570206df84e28ae3f0f05cf828dbad69 /libpod
parent226e0da6fe12bf8a023f67ce6cebacd54ec65fdc (diff)
downloadpodman-8173e830544e74284c5bd4510f52b9e19fe25baa.tar.gz
podman-8173e830544e74284c5bd4510f52b9e19fe25baa.tar.bz2
podman-8173e830544e74284c5bd4510f52b9e19fe25baa.zip
Fix errors found in coverity scan
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_inspect.go31
-rw-r--r--libpod/oci_conmon_linux.go2
-rw-r--r--libpod/runtime_pod_linux.go2
3 files changed, 19 insertions, 16 deletions
diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go
index 729a00be8..276429b11 100644
--- a/libpod/container_inspect.go
+++ b/libpod/container_inspect.go
@@ -661,7 +661,7 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
if ns.Path != "" {
networkMode = fmt.Sprintf("ns:%s", ns.Path)
} else {
- networkMode = "none"
+ networkMode = "private"
}
break
}
@@ -743,22 +743,23 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
ipcMode := ""
if c.config.IPCNsCtr != "" {
ipcMode = fmt.Sprintf("container:%s", c.config.IPCNsCtr)
- } else {
+ } else if ctrSpec.Linux != nil {
// Locate the spec's IPC namespace.
// If there is none, it's ipc=host.
// If there is one and it has a path, it's "ns:".
// If no path, it's default - the empty string.
- foundIPCNS := false
+
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.IPCNamespace {
- foundIPCNS = true
if ns.Path != "" {
ipcMode = fmt.Sprintf("ns:%s", ns.Path)
+ } else {
+ ipcMode = "private"
}
break
}
}
- if !foundIPCNS {
+ if ipcMode == "" {
ipcMode = "host"
}
}
@@ -781,22 +782,22 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
pidMode := ""
if c.config.PIDNsCtr != "" {
pidMode = fmt.Sprintf("container:%s", c.config.PIDNsCtr)
- } else {
+ } else if ctrSpec.Linux != nil {
// Locate the spec's PID namespace.
// If there is none, it's pid=host.
// If there is one and it has a path, it's "ns:".
// If there is no path, it's default - the empty string.
- foundPIDNS := false
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.PIDNamespace {
- foundPIDNS = true
if ns.Path != "" {
pidMode = fmt.Sprintf("ns:%s", ns.Path)
+ } else {
+ pidMode = "private"
}
break
}
}
- if !foundPIDNS {
+ if pidMode == "" {
pidMode = "host"
}
}
@@ -806,22 +807,23 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
utsMode := ""
if c.config.UTSNsCtr != "" {
utsMode = fmt.Sprintf("container:%s", c.config.UTSNsCtr)
- } else {
+ } else if ctrSpec.Linux != nil {
+
// Locate the spec's UTS namespace.
// If there is none, it's uts=host.
// If there is one and it has a path, it's "ns:".
// If there is no path, it's default - the empty string.
- foundUTSNS := false
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.UTSNamespace {
- foundUTSNS = true
if ns.Path != "" {
utsMode = fmt.Sprintf("ns:%s", ns.Path)
+ } else {
+ utsMode = "private"
}
break
}
}
- if !foundUTSNS {
+ if utsMode == "" {
utsMode = "host"
}
}
@@ -831,11 +833,12 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
usernsMode := ""
if c.config.UserNsCtr != "" {
usernsMode = fmt.Sprintf("container:%s", c.config.UserNsCtr)
- } else {
+ } else if ctrSpec.Linux != nil {
// Locate the spec's user namespace.
// If there is none, it's default - the empty string.
// If there is one, it's "private" if no path, or "ns:" if
// there's a path.
+
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.UserNamespace {
if ns.Path != "" {
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go
index da4b85067..d59ff18ca 100644
--- a/libpod/oci_conmon_linux.go
+++ b/libpod/oci_conmon_linux.go
@@ -731,7 +731,7 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
args = append(args, "-t")
}
- if options.Streams.AttachInput {
+ if options.Streams != nil && options.Streams.AttachInput {
args = append(args, "-i")
}
diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go
index 872e8ea8a..73b6c5d9b 100644
--- a/libpod/runtime_pod_linux.go
+++ b/libpod/runtime_pod_linux.go
@@ -236,7 +236,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
}
if err := r.removeContainer(ctx, ctr, force, false, true); err != nil {
- if removalErr != nil {
+ if removalErr == nil {
removalErr = err
} else {
logrus.Errorf("Error removing container %s from pod %s: %v", ctr.ID(), p.ID(), err)