From 625263e2c7ad70ff9ce55e1161e866db83c66b37 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 27 Apr 2016 12:11:32 -0400 Subject: [PATCH] When exec'ing dockerd, look for it in the same directory as the docker binary first, before checking path. Signed-off-by: Daniel Nephin --- daemon_unix.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/daemon_unix.go b/daemon_unix.go index abe9ebfc51..896782b36c 100644 --- a/daemon_unix.go +++ b/daemon_unix.go @@ -5,27 +5,40 @@ package main import ( "os" "os/exec" + "path/filepath" "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) + binaryPath, err := findDaemonBinary() if err != nil { return err } return syscall.Exec( - binaryAbsPath, + binaryPath, append([]string{daemonBinary}, args...), os.Environ()) } +// findDaemonBinary looks for the path to the dockerd binary starting with +// the directory of the current executable (if one exists) and followed by $PATH +func findDaemonBinary() (string, error) { + execDirname := filepath.Dir(os.Args[0]) + if execDirname != "" { + binaryPath := filepath.Join(execDirname, daemonBinary) + if _, err := os.Stat(binaryPath); err == nil { + return binaryPath, nil + } + } + + return exec.LookPath(daemonBinary) +} + // stripDaemonArg removes the `daemon` argument from the list func stripDaemonArg(args []string) []string { for i, arg := range args {