diff options
author | Matthew Heon <matthew.heon@pm.me> | 2020-06-09 14:05:45 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-06-09 14:10:10 -0400 |
commit | 817dbdfdf8ee10c524a15f7247a3742cb926f96b (patch) | |
tree | 7f41fdafae0074d5c17e9cf91b1a04ad06284083 | |
parent | fbe09d78e91c9ac5cadc8b00a67c7d7f89d64868 (diff) | |
download | podman-817dbdfdf8ee10c524a15f7247a3742cb926f96b.tar.gz podman-817dbdfdf8ee10c524a15f7247a3742cb926f96b.tar.bz2 podman-817dbdfdf8ee10c524a15f7247a3742cb926f96b.zip |
Ensure signal validation happens first in pod kill
This fixes an error in the system tests, which expect that when
you try and kill a nonexistent pod with an incorrect signal, you
receive an error about the signal, not the pod.
At the same time, fix a missing return statement in the bindings,
which could also have caused us grief.
Fixes #6540
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
-rw-r--r-- | pkg/api/handlers/libpod/pods.go | 3 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/pods.go | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go index c3f8d5d66..d998167d0 100644 --- a/pkg/api/handlers/libpod/pods.go +++ b/pkg/api/handlers/libpod/pods.go @@ -17,6 +17,7 @@ import ( "github.com/containers/libpod/pkg/util" "github.com/gorilla/schema" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) func PodCreate(w http.ResponseWriter, r *http.Request) { @@ -375,6 +376,7 @@ func PodKill(w http.ResponseWriter, r *http.Request) { sig, err := util.ParseSignal(signal) if err != nil { utils.InternalServerError(w, errors.Wrapf(err, "unable to parse signal value")) + return } name := utils.GetName(r) pod, err := runtime.LookupPod(name) @@ -382,6 +384,7 @@ func PodKill(w http.ResponseWriter, r *http.Request) { utils.PodNotFound(w, name, err) return } + logrus.Debugf("Killing pod %s with signal %d", pod.ID(), sig) podStates, err := pod.Status() if err != nil { utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err) diff --git a/pkg/domain/infra/tunnel/pods.go b/pkg/domain/infra/tunnel/pods.go index b93c48aab..1eb1fffd7 100644 --- a/pkg/domain/infra/tunnel/pods.go +++ b/pkg/domain/infra/tunnel/pods.go @@ -7,6 +7,7 @@ import ( "github.com/containers/libpod/pkg/bindings/pods" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/specgen" + "github.com/containers/libpod/pkg/util" "github.com/pkg/errors" ) @@ -19,6 +20,12 @@ func (ic *ContainerEngine) PodKill(ctx context.Context, namesOrIds []string, opt var ( reports []*entities.PodKillReport ) + + _, err := util.ParseSignal(options.Signal) + if err != nil { + return nil, err + } + foundPods, err := getPodsByContext(ic.ClientCxt, options.All, namesOrIds) if err != nil { return nil, err |