mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
tests/int: add device access test
The test verifies if the device file can be queried using 'access(dev_name, F_OK)' when the permissions are set to 'rw'. The call does not explicitly trigger read or write access but should succeed. Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
This commit is contained in:
@@ -59,7 +59,7 @@ function teardown() {
|
||||
@test "runc run [device cgroup allow rw char device]" {
|
||||
requires root
|
||||
|
||||
update_config ' .linux.resources.devices = [{"allow": false, "access": "rwm"},{"allow": true, "type": "c", "major": 1, "minor": 11, "access": "rwm"}]
|
||||
update_config ' .linux.resources.devices = [{"allow": false, "access": "rwm"},{"allow": true, "type": "c", "major": 1, "minor": 11, "access": "rw"}]
|
||||
| .linux.devices = [{"path": "/dev/kmsg", "type": "c", "major": 1, "minor": 11}]
|
||||
| .process.args |= ["sh"]
|
||||
| .hostname = "myhostname"'
|
||||
@@ -75,6 +75,12 @@ function teardown() {
|
||||
# test read
|
||||
runc exec test_allow_char sh -c 'head -n 1 /dev/kmsg'
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# test access
|
||||
TEST_NAME="dev_access_test"
|
||||
gcc -static -o "rootfs/bin/${TEST_NAME}" "${TESTDATA}/${TEST_NAME}.c"
|
||||
runc exec test_allow_char sh -c "${TEST_NAME} /dev/kmsg"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "runc run [device cgroup allow rm block device]" {
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *dev_name = "/dev/kmsg";
|
||||
|
||||
if (argc > 1)
|
||||
dev_name = argv[1];
|
||||
|
||||
if (access(dev_name, F_OK) < 0) {
|
||||
perror(dev_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user