diff --git a/prog/weavewait/main.go b/prog/weavewait/main.go index 24904f2b..146edc9e 100644 --- a/prog/weavewait/main.go +++ b/prog/weavewait/main.go @@ -3,6 +3,7 @@ package main import ( "bufio" "bytes" + "errors" "fmt" "io/ioutil" "net" @@ -16,24 +17,24 @@ import ( weavenet "github.com/weaveworks/weave/net" ) -func main() { - if len(os.Args) <= 1 { - os.Exit(0) - } +var ( + ErrNoCommandSpecified = errors.New("No command specified") +) +func main() { var ( args = os.Args[1:] notInExec = true rewriteHosts = true ) - if args[0] == "-s" { + if len(args) > 0 && args[0] == "-s" { notInExec = false rewriteHosts = false args = args[1:] } - if args[0] == "-h" { + if len(args) > 0 && args[0] == "-h" { rewriteHosts = false args = args[1:] } @@ -47,6 +48,10 @@ func main() { iface, err := weavenet.EnsureInterface("ethwe", -1) checkErr(err) + if len(args) == 0 { + checkErr(ErrNoCommandSpecified) + } + if rewriteHosts { updateHosts(iface) } diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index 44268bf4..ebb3ab0b 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -3,6 +3,7 @@ package proxy import ( "bytes" "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -17,6 +18,10 @@ import ( const MaxDockerHostname = 64 +var ( + ErrNoCommandSpecified = errors.New("No command specified") +) + type createContainerInterceptor struct{ proxy *Proxy } type createContainerRequestBody struct { @@ -109,6 +114,10 @@ func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Co } } + if len(container.Entrypoint) == 0 && len(container.Cmd) == 0 { + return ErrNoCommandSpecified + } + if len(container.Entrypoint) == 0 || container.Entrypoint[0] != weaveWaitEntrypoint[0] { entrypoint := weaveWaitEntrypoint if i.proxy.NoRewriteHosts { diff --git a/test/610_proxy_wait_for_weave_test.sh b/test/610_proxy_wait_for_weave_test.sh index 79e452bb..39393e14 100755 --- a/test/610_proxy_wait_for_weave_test.sh +++ b/test/610_proxy_wait_for_weave_test.sh @@ -34,4 +34,9 @@ proxy docker_on $HOST1 create --name c4 -v /tmp/1:/srv1 -v /tmp/2:/srv2 -e 'WEAV proxy docker_on $HOST1 start -ai c4 assert "docker_on $HOST1 inspect --format='{{range \$k, \$v := .Volumes}}{{\$k}} {{end}}' c4" "/srv1 /srv2 /w " +# Check errors are returned (when docker returns an error code) +assert_raises "docker -H tcp://$HOST1:12375 run -e 'WEAVE_CIDR=10.2.1.3/24' $SMALL_IMAGE foo 2>&1 | grep 'exec: \"foo\": executable file not found in \$PATH'" +# Check errors still happen when no command is specified +assert_raises "docker -H tcp://$HOST1:12375 run -e 'WEAVE_CIDR=10.2.1.3/24' $SMALL_IMAGE 2>&1 | grep 'Error response from daemon: No command specified'" + end_suite