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:
parent
124da338fd
commit
2035af44aa
2 changed files with 24 additions and 6 deletions
10
runtime.go
10
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.")
|
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 sysInitPath != localCopy {
|
||||||
if err := os.Mkdir(path.Join(config.Root, fmt.Sprintf("init")), 0700); err != nil && !os.IsExist(err) {
|
// 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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := utils.CopyFile(sysInitPath, localCopy); err != nil {
|
if _, err := utils.CopyFile(sysInitPath, localCopy); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sysInitPath = localCopy
|
if err := os.Chmod(localCopy, 0700); err != nil {
|
||||||
if err := os.Chmod(sysInitPath, 0700); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
sysInitPath = localCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime := &Runtime{
|
runtime := &Runtime{
|
||||||
|
|
|
@ -162,14 +162,23 @@ func Trunc(s string, maxlen int) string {
|
||||||
return s[:maxlen]
|
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 {
|
func SelfPath() string {
|
||||||
path, err := exec.LookPath(os.Args[0])
|
path, err := exec.LookPath(os.Args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if execErr, ok := err.(*exec.Error); ok && os.IsNotExist(execErr.Err) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
path, err = filepath.Abs(path)
|
path, err = filepath.Abs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return path
|
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)
|
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 IAMSTATIC {
|
||||||
|
if selfPath == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if target == selfPath {
|
if target == selfPath {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -229,6 +244,9 @@ func DockerInitPath(localCopy string) string {
|
||||||
"/usr/local/lib/docker/dockerinit",
|
"/usr/local/lib/docker/dockerinit",
|
||||||
}
|
}
|
||||||
for _, dockerInit := range possibleInits {
|
for _, dockerInit := range possibleInits {
|
||||||
|
if dockerInit == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
path, err := exec.LookPath(dockerInit)
|
path, err := exec.LookPath(dockerInit)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
path, err = filepath.Abs(path)
|
path, err = filepath.Abs(path)
|
||||||
|
|
Loading…
Reference in a new issue