2016-04-27 13:08:20 -04:00
|
|
|
// +build daemon
|
2016-04-22 12:37:48 -04:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2016-04-27 12:11:32 -04:00
|
|
|
"path/filepath"
|
2016-04-22 12:37:48 -04:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdDaemon execs dockerd with the same flags
|
|
|
|
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
|
|
|
// Use os.Args[1:] so that "global" args are passed to dockerd
|
|
|
|
args = stripDaemonArg(os.Args[1:])
|
|
|
|
|
2016-04-27 12:11:32 -04:00
|
|
|
binaryPath, err := findDaemonBinary()
|
2016-04-22 12:37:48 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return syscall.Exec(
|
2016-04-27 12:11:32 -04:00
|
|
|
binaryPath,
|
2016-04-22 12:37:48 -04:00
|
|
|
append([]string{daemonBinary}, args...),
|
|
|
|
os.Environ())
|
|
|
|
}
|
|
|
|
|
2016-04-27 12:11:32 -04:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2016-04-22 12:37:48 -04:00
|
|
|
// 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
|
|
|
|
}
|