diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-01-15 11:41:38 +0100 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-01-15 11:41:38 +0100 |
commit | 3c7b7761ceafc24f9fa42e5f08178d8c644d9017 (patch) | |
tree | f98239c83b90587d4de7fb40889107f03a48c1ac /pkg | |
parent | a1ff93bdfedc30d707a1230d5d1cb8d987a7360f (diff) | |
download | podman-3c7b7761ceafc24f9fa42e5f08178d8c644d9017.tar.gz podman-3c7b7761ceafc24f9fa42e5f08178d8c644d9017.tar.bz2 podman-3c7b7761ceafc24f9fa42e5f08178d8c644d9017.zip |
v2: stats: do not ignore errors
We must check all errors and handle them properly. Otherwise, we can run
into nil dereferences ultimately killing the service.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/generic/containers_stats.go | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/pkg/api/handlers/generic/containers_stats.go b/pkg/api/handlers/generic/containers_stats.go index 538fc6f21..eb9cfca4a 100644 --- a/pkg/api/handlers/generic/containers_stats.go +++ b/pkg/api/handlers/generic/containers_stats.go @@ -81,19 +81,44 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) { time.Sleep(DefaultStatsPeriod) } - cgroupPath, _ := ctnr.CGroupPath() - cgroup, _ := cgroups.Load(cgroupPath) + cgroupPath, err := ctnr.CGroupPath() + if err != nil { + utils.InternalServerError(w, err) + return + } + + cgroup, err := cgroups.Load(cgroupPath) + if err != nil { + utils.InternalServerError(w, err) + return + } for ok := true; ok; ok = query.Stream { - state, _ := ctnr.State() + state, err := ctnr.State() + if err != nil { + utils.InternalServerError(w, err) + return + } if state != define.ContainerStateRunning { time.Sleep(10 * time.Second) continue } - stats, _ := ctnr.GetContainerStats(stats) - cgroupStat, _ := cgroup.Stat() - inspect, _ := ctnr.Inspect(false) + stats, err := ctnr.GetContainerStats(stats) + if err != nil { + utils.InternalServerError(w, err) + return + } + cgroupStat, err := cgroup.Stat() + if err != nil { + utils.InternalServerError(w, err) + return + } + inspect, err := ctnr.Inspect(false) + if err != nil { + utils.InternalServerError(w, err) + return + } net := make(map[string]docker.NetworkStats) net[inspect.NetworkSettings.EndpointID] = docker.NetworkStats{ |