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.
Upstream-commit: 94821a33534a25fe906f3f66e1c06b1f2c877aac
Component: engine
This commit is contained in:
Josh Poimboeuf
2013-12-19 00:39:12 -06:00
parent b713827b64
commit f633c6e7d1
2 changed files with 16 additions and 14 deletions
-14
View File
@@ -9,7 +9,6 @@ import (
"github.com/dotcloud/docker/utils"
"log"
"os"
"path/filepath"
"strings"
)
@@ -71,19 +70,6 @@ func main() {
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)
if err != nil {
log.Fatal(err)
+16
View File
@@ -6,6 +6,7 @@ import (
"io"
"log"
"os"
"path/filepath"
"runtime"
"strings"
)
@@ -79,9 +80,24 @@ func New(root string) (*Engine, error) {
}
}
}
if err := os.MkdirAll(root, 0700); err != nil && !os.IsExist(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{
root: root,
handlers: make(map[string]Handler),