diff --git a/runtime.go b/runtime.go index 3268892d56..071e94acd8 100644 --- a/runtime.go +++ b/runtime.go @@ -734,18 +734,18 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) { return nil, fmt.Errorf("Could not locate dockerinit: This usually means docker was built incorrectly. See http://docs.docker.io/en/latest/contributing/devenvironment for official build instructions.") } - if !utils.IAMSTATIC { - if err := os.Mkdir(path.Join(config.Root, fmt.Sprintf("init")), 0700); err != nil && !os.IsExist(err) { + if sysInitPath != localCopy { + // When we find a suitable dockerinit binary (even if it's our local binary), we copy it into config.Root at localCopy for future use (so that the original can go away without that being a problem, for example during a package upgrade). + if err := os.Mkdir(path.Dir(localCopy), 0700); err != nil && !os.IsExist(err) { return nil, err } - if _, err := utils.CopyFile(sysInitPath, localCopy); err != nil { return nil, err } - sysInitPath = localCopy - if err := os.Chmod(sysInitPath, 0700); err != nil { + if err := os.Chmod(localCopy, 0700); err != nil { return nil, err } + sysInitPath = localCopy } runtime := &Runtime{ diff --git a/utils/utils.go b/utils/utils.go index 6864dddf82..473302bc97 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -162,14 +162,23 @@ func Trunc(s string, maxlen int) string { return s[:maxlen] } -// Figure out the absolute path of our own binary +// Figure out the absolute path of our own binary (if it's still around). func SelfPath() string { path, err := exec.LookPath(os.Args[0]) if err != nil { + if os.IsNotExist(err) { + return "" + } + if execErr, ok := err.(*exec.Error); ok && os.IsNotExist(execErr.Err) { + return "" + } panic(err) } path, err = filepath.Abs(path) if err != nil { + if os.IsNotExist(err) { + return "" + } panic(err) } return path @@ -190,7 +199,13 @@ func dockerInitSha1(target string) string { } func isValidDockerInitPath(target string, selfPath string) bool { // target and selfPath should be absolute (InitPath and SelfPath already do this) + if target == "" { + return false + } if IAMSTATIC { + if selfPath == "" { + return false + } if target == selfPath { return true } @@ -229,6 +244,9 @@ func DockerInitPath(localCopy string) string { "/usr/local/lib/docker/dockerinit", } for _, dockerInit := range possibleInits { + if dockerInit == "" { + continue + } path, err := exec.LookPath(dockerInit) if err == nil { path, err = filepath.Abs(path)