Skip to content

Commit 0abb52c

Browse files
committed
add recursive device nodes
Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
1 parent db1a355 commit 0abb52c

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

daemon/execdriver/native/template/default_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func New() *libcontainer.Container {
3535
},
3636
Context: libcontainer.Context{},
3737
RequiredDeviceNodes: nodes.DefaultNodes,
38-
OptionalDeviceNodes: []string{"fuse"},
38+
OptionalDeviceNodes: []string{"/dev/fuse"},
3939
}
4040
if apparmor.IsEnabled() {
4141
container.Context["apparmor_profile"] = "docker-default"

pkg/libcontainer/mount/nodes/nodes.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414

1515
// Default list of device nodes to copy
1616
var DefaultNodes = []string{
17-
"null",
18-
"zero",
19-
"full",
20-
"random",
21-
"urandom",
22-
"tty",
17+
"/dev/null",
18+
"/dev/zero",
19+
"/dev/full",
20+
"/dev/random",
21+
"/dev/urandom",
22+
"/dev/tty",
2323
}
2424

2525
// CopyN copies the device node from the host into the rootfs
@@ -39,7 +39,7 @@ func CopyN(rootfs string, nodesToCopy []string, shouldExist bool) error {
3939
// on the host system does not exist and the boolean flag is passed
4040
// an error will be returned
4141
func Copy(rootfs, node string, shouldExist bool) error {
42-
stat, err := os.Stat(filepath.Join("/dev", node))
42+
stat, err := os.Stat(node)
4343
if err != nil {
4444
if os.IsNotExist(err) && !shouldExist {
4545
return nil
@@ -48,27 +48,41 @@ func Copy(rootfs, node string, shouldExist bool) error {
4848
}
4949

5050
var (
51-
dest = filepath.Join(rootfs, "dev", node)
52-
st = stat.Sys().(*syscall.Stat_t)
51+
dest = filepath.Join(rootfs, node)
52+
st = stat.Sys().(*syscall.Stat_t)
53+
parent = filepath.Dir(dest)
5354
)
5455

56+
if err := os.MkdirAll(parent, 0755); err != nil {
57+
return err
58+
}
59+
5560
if err := system.Mknod(dest, st.Mode, int(st.Rdev)); err != nil && !os.IsExist(err) {
5661
return fmt.Errorf("mknod %s %s", node, err)
5762
}
5863
return nil
5964
}
6065

61-
func GetHostDeviceNodes() ([]string, error) {
62-
files, err := ioutil.ReadDir("/dev")
66+
func getNodes(path string) ([]string, error) {
67+
out := []string{}
68+
files, err := ioutil.ReadDir(path)
6369
if err != nil {
6470
return nil, err
6571
}
66-
67-
out := []string{}
6872
for _, f := range files {
69-
if f.Mode()&os.ModeDevice == os.ModeDevice {
70-
out = append(out, f.Name())
73+
if f.IsDir() && f.Name() != "pts" && f.Name() != "shm" {
74+
sub, err := getNodes(filepath.Join(path, f.Name()))
75+
if err != nil {
76+
return nil, err
77+
}
78+
out = append(out, sub...)
79+
} else if f.Mode()&os.ModeDevice == os.ModeDevice {
80+
out = append(out, filepath.Join(path, f.Name()))
7181
}
7282
}
7383
return out, nil
7484
}
85+
86+
func GetHostDeviceNodes() ([]string, error) {
87+
return getNodes("/dev")
88+
}

0 commit comments

Comments
 (0)