mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
create a copy of dockerinit
This commit is contained in:
parent
2586c042ae
commit
110c4f2043
2 changed files with 45 additions and 7 deletions
29
runtime.go
29
runtime.go
|
@ -38,6 +38,7 @@ type Capabilities struct {
|
||||||
|
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
repository string
|
repository string
|
||||||
|
sysInitPath string
|
||||||
containers *list.List
|
containers *list.List
|
||||||
networkManager *NetworkManager
|
networkManager *NetworkManager
|
||||||
graph *Graph
|
graph *Graph
|
||||||
|
@ -404,11 +405,6 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
|
||||||
return nil, nil, fmt.Errorf("No command specified")
|
return nil, nil, fmt.Errorf("No command specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
sysInitPath := utils.DockerInitPath()
|
|
||||||
if sysInitPath == "" {
|
|
||||||
return nil, 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.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate id
|
// Generate id
|
||||||
id := GenerateID()
|
id := GenerateID()
|
||||||
|
|
||||||
|
@ -459,7 +455,7 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
|
||||||
Image: img.ID, // Always use the resolved image id
|
Image: img.ID, // Always use the resolved image id
|
||||||
NetworkSettings: &NetworkSettings{},
|
NetworkSettings: &NetworkSettings{},
|
||||||
// FIXME: do we need to store this in the container?
|
// FIXME: do we need to store this in the container?
|
||||||
SysInitPath: sysInitPath,
|
SysInitPath: runtime.sysInitPath,
|
||||||
Name: name,
|
Name: name,
|
||||||
Driver: runtime.driver.String(),
|
Driver: runtime.driver.String(),
|
||||||
}
|
}
|
||||||
|
@ -701,6 +697,26 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localCopy := path.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", VERSION))
|
||||||
|
sysInitPath := utils.DockerInitPath(localCopy)
|
||||||
|
if sysInitPath == "" {
|
||||||
|
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) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := utils.CopyFile(sysInitPath, localCopy); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sysInitPath = localCopy
|
||||||
|
if err := os.Chmod(sysInitPath, 0700); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
runtime := &Runtime{
|
runtime := &Runtime{
|
||||||
repository: runtimeRepo,
|
repository: runtimeRepo,
|
||||||
containers: list.New(),
|
containers: list.New(),
|
||||||
|
@ -713,6 +729,7 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) {
|
||||||
config: config,
|
config: config,
|
||||||
containerGraph: graph,
|
containerGraph: graph,
|
||||||
driver: driver,
|
driver: driver,
|
||||||
|
sysInitPath: sysInitPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runtime.restore(); err != nil {
|
if err := runtime.restore(); err != nil {
|
||||||
|
|
|
@ -270,13 +270,14 @@ func isValidDockerInitPath(target string, selfPath string) bool { // target and
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out the path of our dockerinit (which may be SelfPath())
|
// Figure out the path of our dockerinit (which may be SelfPath())
|
||||||
func DockerInitPath() string {
|
func DockerInitPath(localCopy string) string {
|
||||||
selfPath := SelfPath()
|
selfPath := SelfPath()
|
||||||
if isValidDockerInitPath(selfPath, selfPath) {
|
if isValidDockerInitPath(selfPath, selfPath) {
|
||||||
// if we're valid, don't bother checking anything else
|
// if we're valid, don't bother checking anything else
|
||||||
return selfPath
|
return selfPath
|
||||||
}
|
}
|
||||||
var possibleInits = []string{
|
var possibleInits = []string{
|
||||||
|
localCopy,
|
||||||
filepath.Join(filepath.Dir(selfPath), "dockerinit"),
|
filepath.Join(filepath.Dir(selfPath), "dockerinit"),
|
||||||
// "/usr/libexec includes internal binaries that are not intended to be executed directly by users or shell scripts. Applications may use a single subdirectory under /usr/libexec."
|
// "/usr/libexec includes internal binaries that are not intended to be executed directly by users or shell scripts. Applications may use a single subdirectory under /usr/libexec."
|
||||||
"/usr/libexec/docker/dockerinit",
|
"/usr/libexec/docker/dockerinit",
|
||||||
|
@ -1292,3 +1293,23 @@ func GetCallerName(depth int) string {
|
||||||
callerShortName := parts[len(parts)-1]
|
callerShortName := parts[len(parts)-1]
|
||||||
return callerShortName
|
return callerShortName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyFile(src, dst string) (int64, error) {
|
||||||
|
if src == dst {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
sf, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer sf.Close()
|
||||||
|
if err := os.Remove(dst); err != nil && !os.IsNotExist(err) {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
df, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer df.Close()
|
||||||
|
return io.Copy(df, sf)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue