1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Always copy dockerinit locally, regardless of whether our docker binary is static, because even it might get deleted or moved/renamed

This commit is contained in:
Tianon Gravi 2013-12-05 02:10:41 -07:00
parent 124da338fd
commit 2035af44aa
2 changed files with 24 additions and 6 deletions

View file

@ -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{

View file

@ -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)