Skip to content

Commit 303ae30

Browse files
author
Dongsu Park
committed
validation: check for read-only block, char devices, fifo
Create read-only block device, char device, and fifo, to check if they are read-only as expected. Signed-off-by: Dongsu Park <[email protected]>
1 parent e60cd06 commit 303ae30

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

validation/linux_readonly_paths.go

+38
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88

99
"github.com/opencontainers/runtime-tools/validation/util"
10+
"golang.org/x/sys/unix"
1011
)
1112

1213
func checkReadonlyPaths() error {
@@ -120,6 +121,30 @@ func checkReadonlySymlinks() error {
120121
return fmt.Errorf("expected: err != nil, actual: err == nil")
121122
}
122123

124+
func checkReadonlyDeviceNodes(mode uint32) error {
125+
g, err := util.GetDefaultGenerator()
126+
if err != nil {
127+
return err
128+
}
129+
130+
readonlyDevice := "/readonly-device"
131+
132+
g.AddLinuxReadonlyPaths(readonlyDevice)
133+
return util.RuntimeInsideValidate(g, func(path string) error {
134+
testFile := filepath.Join(path, readonlyDevice)
135+
136+
if err := unix.Mknod(testFile, mode, 0); err != nil {
137+
return err
138+
}
139+
140+
if _, err := os.Stat(testFile); err != nil && os.IsNotExist(err) {
141+
return err
142+
}
143+
144+
return nil
145+
})
146+
}
147+
123148
func main() {
124149
if err := checkReadonlyPaths(); err != nil {
125150
util.Fatal(err)
@@ -133,4 +158,17 @@ func main() {
133158
util.Fatal(err)
134159
}
135160

161+
// test creation of different type of devices, i.e. block device,
162+
// character device, and FIFO.
163+
modes := []uint32{
164+
unix.S_IFBLK | 0666,
165+
unix.S_IFCHR | 0666,
166+
unix.S_IFIFO | 0666,
167+
}
168+
169+
for _, m := range modes {
170+
if err := checkReadonlyDeviceNodes(m); err != nil {
171+
util.Fatal(err)
172+
}
173+
}
136174
}

0 commit comments

Comments
 (0)