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

Move root symlink check to engine.New

Since commit c91c365, when starting the docker daemon without an
existing /var/lib/docker directory, it fails with:

  2013/12/18 23:39:36 Unable to canonicalize root (%!s(*string=0xc210077c80)): lstat /var/lib/docker: no such file or directory

Move the symlink checking code to engine.New after the root dir has been
created.
This commit is contained in:
Josh Poimboeuf 2013-12-19 00:03:34 -06:00
parent 681b40c801
commit 94821a3353
2 changed files with 16 additions and 14 deletions

View file

@ -9,7 +9,6 @@ import (
"github.com/dotcloud/docker/utils" "github.com/dotcloud/docker/utils"
"log" "log"
"os" "os"
"path/filepath"
"strings" "strings"
) )
@ -71,19 +70,6 @@ func main() {
return return
} }
// Docker makes some assumptions about the "absoluteness" of flRoot
// ... so let's make sure it has no symlinks
if p, err := filepath.Abs(*flRoot); err != nil {
log.Fatalf("Unable to get absolute root (%s): %s", flRoot, err)
} else {
*flRoot = p
}
if p, err := filepath.EvalSymlinks(*flRoot); err != nil {
log.Fatalf("Unable to canonicalize root (%s): %s", flRoot, err)
} else {
*flRoot = p
}
eng, err := engine.New(*flRoot) eng, err := engine.New(*flRoot)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View file

@ -6,6 +6,7 @@ import (
"io" "io"
"log" "log"
"os" "os"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
) )
@ -79,9 +80,24 @@ func New(root string) (*Engine, error) {
} }
} }
} }
if err := os.MkdirAll(root, 0700); err != nil && !os.IsExist(err) { if err := os.MkdirAll(root, 0700); err != nil && !os.IsExist(err) {
return nil, err return nil, err
} }
// Docker makes some assumptions about the "absoluteness" of root
// ... so let's make sure it has no symlinks
if p, err := filepath.Abs(root); err != nil {
log.Fatalf("Unable to get absolute root (%s): %s", root, err)
} else {
root = p
}
if p, err := filepath.EvalSymlinks(root); err != nil {
log.Fatalf("Unable to canonicalize root (%s): %s", root, err)
} else {
root = p
}
eng := &Engine{ eng := &Engine{
root: root, root: root,
handlers: make(map[string]Handler), handlers: make(map[string]Handler),