From c0acfccc7be6c49bf243821e535dfe1122ff5a52 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 22 Apr 2016 12:37:48 -0400 Subject: [PATCH] Cleanup from CR. Signed-off-by: Daniel Nephin --- client/daemon.go | 32 ------------------------------ client/daemon_unix.go | 37 +++++++++++++++++++++++++++++++++++ client/daemon_windows.go | 11 +++++++++++ client/daemon_windows_test.go | 18 +++++++++++++++++ client/docker.go | 5 ----- hack/Jenkins/W2L/setup.sh | 4 ++-- hack/make/binary | 2 +- 7 files changed, 69 insertions(+), 40 deletions(-) create mode 100644 client/daemon_unix.go create mode 100644 client/daemon_windows.go create mode 100644 client/daemon_windows_test.go diff --git a/client/daemon.go b/client/daemon.go index 48064b4cf6..15dffbaefb 100644 --- a/client/daemon.go +++ b/client/daemon.go @@ -1,11 +1,5 @@ package main -import ( - "os" - "os/exec" - "syscall" -) - const daemonBinary = "dockerd" // DaemonProxy acts as a cli.Handler to proxy calls to the daemon binary @@ -15,29 +9,3 @@ type DaemonProxy struct{} func NewDaemonProxy() DaemonProxy { return DaemonProxy{} } - -// CmdDaemon execs dockerd with the same flags -// TODO: add a deprecation warning? -func (p DaemonProxy) CmdDaemon(args ...string) error { - args = stripDaemonArg(os.Args[1:]) - - binaryAbsPath, err := exec.LookPath(daemonBinary) - if err != nil { - return err - } - - return syscall.Exec( - binaryAbsPath, - append([]string{daemonBinary}, args...), - os.Environ()) -} - -// stripDaemonArg removes the `daemon` argument from the list -func stripDaemonArg(args []string) []string { - for i, arg := range args { - if arg == "daemon" { - return append(args[:i], args[i+1:]...) - } - } - return args -} diff --git a/client/daemon_unix.go b/client/daemon_unix.go new file mode 100644 index 0000000000..abe9ebfc51 --- /dev/null +++ b/client/daemon_unix.go @@ -0,0 +1,37 @@ +// +build !windows + +package main + +import ( + "os" + "os/exec" + "syscall" +) + +// CmdDaemon execs dockerd with the same flags +// TODO: add a deprecation warning? +func (p DaemonProxy) CmdDaemon(args ...string) error { + // Use os.Args[1:] so that "global" args are passed to dockerd + args = stripDaemonArg(os.Args[1:]) + + // TODO: check dirname args[0] first + binaryAbsPath, err := exec.LookPath(daemonBinary) + if err != nil { + return err + } + + return syscall.Exec( + binaryAbsPath, + append([]string{daemonBinary}, args...), + os.Environ()) +} + +// stripDaemonArg removes the `daemon` argument from the list +func stripDaemonArg(args []string) []string { + for i, arg := range args { + if arg == "daemon" { + return append(args[:i], args[i+1:]...) + } + } + return args +} diff --git a/client/daemon_windows.go b/client/daemon_windows.go new file mode 100644 index 0000000000..41c0133b67 --- /dev/null +++ b/client/daemon_windows.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" +) + +// CmdDaemon reports on an error on windows, because there is no exec +func (p DaemonProxy) CmdDaemon(args ...string) error { + return fmt.Errorf( + "`docker daemon` does not exist on windows. Please run `dockerd` directly") +} diff --git a/client/daemon_windows_test.go b/client/daemon_windows_test.go new file mode 100644 index 0000000000..3da4e5d7cc --- /dev/null +++ b/client/daemon_windows_test.go @@ -0,0 +1,18 @@ +package main + +import ( + "strings" + "testing" +) + +func TestCmdDaemon(t *testing.T) { + proxy := NewDaemonProxy() + err := proxy.CmdDaemon("--help") + if err == nil { + t.Fatal("Expected CmdDaemon to fail in Windows.") + } + + if !strings.Contains(err.Error(), "Please run `dockerd`") { + t.Fatalf("Expected an error about running dockerd, got %s", err) + } +} diff --git a/client/docker.go b/client/docker.go index 5641f12b12..838602164d 100644 --- a/client/docker.go +++ b/client/docker.go @@ -9,16 +9,11 @@ import ( "github.com/docker/docker/cli" "github.com/docker/docker/dockerversion" flag "github.com/docker/docker/pkg/mflag" - "github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/term" "github.com/docker/docker/utils" ) func main() { - if reexec.Init() { - return - } - // Set terminal emulation based on platform as required. stdin, stdout, stderr := term.StdStreams() diff --git a/hack/Jenkins/W2L/setup.sh b/hack/Jenkins/W2L/setup.sh index 1a080c54a1..91fa3423b0 100644 --- a/hack/Jenkins/W2L/setup.sh +++ b/hack/Jenkins/W2L/setup.sh @@ -188,7 +188,7 @@ if [ $ec -eq 0 ]; then ec=$? set +x if [ 0 -ne $ec ]; then - echo "ERROR: Failed to compile and start the linux daemon" + echo "ERROR: Failed to compile and start the linux daemon" fi fi @@ -199,7 +199,7 @@ if [ $ec -eq 0 ]; then export TIMEOUT="5m" export DOCKER_HOST="tcp://$ip:$port_inner" export DOCKER_TEST_HOST="tcp://$ip:$port_inner" - unset DOCKER_CLIENTONLY + unset DOCKER_CLIENTONLY export DOCKER_REMOTE_DAEMON=1 hack/make.sh binary ec=$? diff --git a/hack/make/binary b/hack/make/binary index 47db575855..53190fbcbd 100644 --- a/hack/make/binary +++ b/hack/make/binary @@ -1,7 +1,7 @@ #!/bin/bash set -e -# This script exists as backwards compatiblity for CI +# This script exists as backwards compatibility for CI ( DEST="${DEST}-client" ABS_DEST="${ABS_DEST}-client"