From 5f81cf11f648835bd0182d297d265a4da6c469dd Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 15 Nov 2016 17:53:24 +0100 Subject: [PATCH] =?UTF-8?q?Use=20Container.Config.Shell=20instead=20of=20h?= =?UTF-8?q?ardcoded=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … for healthcheck. It make the code a little cleaner and more future/usage proof. Signed-off-by: Vincent Demeester --- daemon/health.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/daemon/health.go b/daemon/health.go index f191472df6..d185904e5f 100644 --- a/daemon/health.go +++ b/daemon/health.go @@ -12,6 +12,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/container" "github.com/docker/docker/daemon/exec" @@ -63,11 +64,7 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, container *container.Cont cmdSlice := strslice.StrSlice(container.Config.Healthcheck.Test)[1:] if p.shell { - if runtime.GOOS != "windows" { - cmdSlice = append([]string{"/bin/sh", "-c"}, cmdSlice...) - } else { - cmdSlice = append([]string{"cmd", "/S", "/C"}, cmdSlice...) - } + cmdSlice = append(getShell(container.Config), cmdSlice...) } entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmdSlice) execConfig := exec.NewConfig() @@ -325,3 +322,13 @@ func min(x, y int) int { } return y } + +func getShell(config *containertypes.Config) []string { + if len(config.Shell) != 0 { + return config.Shell + } + if runtime.GOOS != "windows" { + return []string{"/bin/sh", "-c"} + } + return []string{"cmd", "/S", "/C"} +}