File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -5,27 +5,40 @@ package main
55import (
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?
1313func (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
3043func stripDaemonArg (args []string ) []string {
3144 for i , arg := range args {
You can’t perform that action at this time.
0 commit comments