libcontainer: fix the file mode of the device

Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
Iceber Gu
2021-02-10 18:47:15 +08:00
parent f245a1d1ed
commit fa52df9493
3 changed files with 3 additions and 12 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
Permissions: Permissions(permissions),
},
Path: path,
FileMode: os.FileMode(mode),
FileMode: os.FileMode(mode &^ unix.S_IFMT),
Uid: stat.Uid,
Gid: stat.Gid,
}, nil
+1 -10
View File
@@ -82,22 +82,13 @@ func TestHostDevicesAllValid(t *testing.T) {
if device.Major == 0 {
t.Errorf("device entry %+v has zero major number", device)
}
// Devices should only have file modes that correspond to their type.
var expectedType os.FileMode
switch device.Type {
case BlockDevice:
expectedType = unix.S_IFBLK
case CharDevice:
expectedType = unix.S_IFCHR
case BlockDevice, CharDevice:
case FifoDevice:
t.Logf("fifo devices shouldn't show up from HostDevices")
fallthrough
default:
t.Errorf("device entry %+v has unexpected type %v", device, device.Type)
}
gotType := device.FileMode & unix.S_IFMT
if expectedType != gotType {
t.Errorf("device entry %+v has mismatched types (expected %#x, got %#x)", device, expectedType, gotType)
}
}
}