|
@@ -4,10 +4,11 @@ package nodes
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
- "github.com/dotcloud/docker/pkg/system"
|
|
|
|
"os"
|
|
"os"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"syscall"
|
|
"syscall"
|
|
|
|
+
|
|
|
|
+ "github.com/dotcloud/docker/pkg/system"
|
|
)
|
|
)
|
|
|
|
|
|
// Default list of device nodes to copy
|
|
// Default list of device nodes to copy
|
|
@@ -20,30 +21,43 @@ var DefaultNodes = []string{
|
|
"tty",
|
|
"tty",
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// AdditionalNodes includes nodes that are not required
|
|
|
|
+var AdditionalNodes = []string{
|
|
|
|
+ "fuse",
|
|
|
|
+}
|
|
|
|
+
|
|
// CopyN copies the device node from the host into the rootfs
|
|
// CopyN copies the device node from the host into the rootfs
|
|
-func CopyN(rootfs string, nodesToCopy []string) error {
|
|
|
|
|
|
+func CopyN(rootfs string, nodesToCopy []string, shouldExist bool) error {
|
|
oldMask := system.Umask(0000)
|
|
oldMask := system.Umask(0000)
|
|
defer system.Umask(oldMask)
|
|
defer system.Umask(oldMask)
|
|
|
|
|
|
for _, node := range nodesToCopy {
|
|
for _, node := range nodesToCopy {
|
|
- if err := Copy(rootfs, node); err != nil {
|
|
|
|
|
|
+ if err := Copy(rootfs, node, shouldExist); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func Copy(rootfs, node string) error {
|
|
|
|
|
|
+// Copy copies the device node into the rootfs. If the node
|
|
|
|
+// on the host system does not exist and the boolean flag is passed
|
|
|
|
+// an error will be returned
|
|
|
|
+func Copy(rootfs, node string, shouldExist bool) error {
|
|
stat, err := os.Stat(filepath.Join("/dev", node))
|
|
stat, err := os.Stat(filepath.Join("/dev", node))
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
+ if os.IsNotExist(err) && !shouldExist {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
var (
|
|
var (
|
|
dest = filepath.Join(rootfs, "dev", node)
|
|
dest = filepath.Join(rootfs, "dev", node)
|
|
st = stat.Sys().(*syscall.Stat_t)
|
|
st = stat.Sys().(*syscall.Stat_t)
|
|
)
|
|
)
|
|
|
|
+
|
|
if err := system.Mknod(dest, st.Mode, int(st.Rdev)); err != nil && !os.IsExist(err) {
|
|
if err := system.Mknod(dest, st.Mode, int(st.Rdev)); err != nil && !os.IsExist(err) {
|
|
- return fmt.Errorf("copy %s %s", node, err)
|
|
|
|
|
|
+ return fmt.Errorf("mknod %s %s", node, err)
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|