mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libcontainer: fix the file mode of the device
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user