Skip to content

Commit 9db86a3

Browse files
committed
When exec'ing dockerd, look for it in the same directory as the docker binary first, before checking path.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
1 parent 2a6980c commit 9db86a3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

cmd/docker/daemon_unix.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,40 @@ package main
55
import (
66
"os"
77
"os/exec"
8+
"path/filepath"
89
"syscall"
910
)
1011

1112
// CmdDaemon execs dockerd with the same flags
12-
// TODO: add a deprecation warning?
1313
func (p DaemonProxy) CmdDaemon(args ...string) error {
1414
// Use os.Args[1:] so that "global" args are passed to dockerd
1515
args = stripDaemonArg(os.Args[1:])
1616

17-
// TODO: check dirname args[0] first
18-
binaryAbsPath, err := exec.LookPath(daemonBinary)
17+
binaryPath, err := findDaemonBinary()
1918
if err != nil {
2019
return err
2120
}
2221

2322
return syscall.Exec(
24-
binaryAbsPath,
23+
binaryPath,
2524
append([]string{daemonBinary}, args...),
2625
os.Environ())
2726
}
2827

28+
// findDaemonBinary looks for the path to the dockerd binary starting with
29+
// the directory of the current executable (if one exists) and followed by $PATH
30+
func findDaemonBinary() (string, error) {
31+
execDirname := filepath.Dir(os.Args[0])
32+
if execDirname != "" {
33+
binaryPath := filepath.Join(execDirname, daemonBinary)
34+
if _, err := os.Stat(binaryPath); err == nil {
35+
return binaryPath, nil
36+
}
37+
}
38+
39+
return exec.LookPath(daemonBinary)
40+
}
41+
2942
// stripDaemonArg removes the `daemon` argument from the list
3043
func stripDaemonArg(args []string) []string {
3144
for i, arg := range args {

0 commit comments

Comments
 (0)