mirror of https://github.com/docker/cli.git
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>
This commit is contained in:
parent
5de3b105a8
commit
625263e2c7
|
@ -5,27 +5,40 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdDaemon execs dockerd with the same flags
|
// CmdDaemon execs dockerd with the same flags
|
||||||
// TODO: add a deprecation warning?
|
|
||||||
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
||||||
// Use os.Args[1:] so that "global" args are passed to dockerd
|
// Use os.Args[1:] so that "global" args are passed to dockerd
|
||||||
args = stripDaemonArg(os.Args[1:])
|
args = stripDaemonArg(os.Args[1:])
|
||||||
|
|
||||||
// TODO: check dirname args[0] first
|
binaryPath, err := findDaemonBinary()
|
||||||
binaryAbsPath, err := exec.LookPath(daemonBinary)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return syscall.Exec(
|
return syscall.Exec(
|
||||||
binaryAbsPath,
|
binaryPath,
|
||||||
append([]string{daemonBinary}, args...),
|
append([]string{daemonBinary}, args...),
|
||||||
os.Environ())
|
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
|
// stripDaemonArg removes the `daemon` argument from the list
|
||||||
func stripDaemonArg(args []string) []string {
|
func stripDaemonArg(args []string) []string {
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
|
|
Loading…
Reference in New Issue