Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
validation: check for read-only block, char devices, fifo
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Dongsu Park committed Jun 12, 2018
1 parent e60cd06 commit 303ae30
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions validation/linux_readonly_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/opencontainers/runtime-tools/validation/util"
"golang.org/x/sys/unix"
)

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

func checkReadonlyDeviceNodes(mode uint32) error {
g, err := util.GetDefaultGenerator()
if err != nil {
return err
}

readonlyDevice := "/readonly-device"

g.AddLinuxReadonlyPaths(readonlyDevice)
return util.RuntimeInsideValidate(g, func(path string) error {
testFile := filepath.Join(path, readonlyDevice)

if err := unix.Mknod(testFile, mode, 0); err != nil {
return err
}

if _, err := os.Stat(testFile); err != nil && os.IsNotExist(err) {
return err
}

return nil
})
}

func main() {
if err := checkReadonlyPaths(); err != nil {
util.Fatal(err)
Expand All @@ -133,4 +158,17 @@ func main() {
util.Fatal(err)
}

// test creation of different type of devices, i.e. block device,
// character device, and FIFO.
modes := []uint32{
unix.S_IFBLK | 0666,
unix.S_IFCHR | 0666,
unix.S_IFIFO | 0666,
}

for _, m := range modes {
if err := checkReadonlyDeviceNodes(m); err != nil {
util.Fatal(err)
}
}
}

0 comments on commit 303ae30

Please sign in to comment.