sysctl: Support systemd glob patterns
systemd-sysctl handles glob patterns along with overrides and exceptions. Now the procps sysctl does it too. The return value for sysctl is consistently either 0 or 1. Added tests to check sysctl functions. References: procps-ng/procps#191 Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
@ -136,6 +136,15 @@ proc expect_table_dsc { test match_header match_item } {
|
||||
#}
|
||||
}
|
||||
|
||||
proc expect_spawn_retval { test retval } {
|
||||
foreach {pid spawnid os_error_flag value} [wait] break
|
||||
|
||||
if {$value == $retval} {
|
||||
return
|
||||
}
|
||||
fail "$test (exit value)"
|
||||
}
|
||||
|
||||
proc make_pipeproc { } {
|
||||
global pipeproc_pid pipeproc_spawnid topdir
|
||||
|
||||
|
29
testsuite/sysctl.test/sysctl_write.exp
Normal file
29
testsuite/sysctl.test/sysctl_write.exp
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
set sysctl ${topdir}sysctl
|
||||
|
||||
set test "sysctl write from command line"
|
||||
spawn $sysctl --dry-run kernel.hostname=procps-test
|
||||
expect_pass "$test" "/proc/sys/kernel/hostname = procps-test"
|
||||
|
||||
set test "sysctl write from configuration file"
|
||||
spawn $sysctl --dry-run -f ${topdir}testsuite/sysctl_glob_test.conf
|
||||
expect_pass "$test" "/proc/sys/fs/protected_fifos = 2\\s+/proc/sys/fs/protected_symlinks = 2\\s+/proc/sys/fs/protected_hardlinks = 1"
|
||||
|
||||
set hostname_file "/proc/sys/kernel/hostname"
|
||||
if {[file exists ${hostname_file}]} {
|
||||
if {[file writable ${hostname_file}]} {
|
||||
unsupported "sysctl write: hostname file is writable"
|
||||
} else {
|
||||
set test "sysctl write unwritable file"
|
||||
spawn $sysctl -q kernel.hostname=procpstest
|
||||
expect_pass "$test" "sysctl: permission denied on key \"kernel.hostname\"\\s*$"
|
||||
expect_spawn_retval "$test" 1
|
||||
|
||||
set test "sysctl write unwritable file ignored"
|
||||
spawn $sysctl -q -- -kernel.hostname=procpstest
|
||||
expect_pass "$test" "sysctl: permission denied on key \"kernel.hostname\", ignoring\\s*$"
|
||||
expect_spawn_retval "$test" 0
|
||||
}
|
||||
} else {
|
||||
unsupported "sysctl write: hostname file doe not exist"
|
||||
}
|
6
testsuite/sysctl_glob_test.conf
Normal file
6
testsuite/sysctl_glob_test.conf
Normal file
@ -0,0 +1,6 @@
|
||||
#
|
||||
# Test configuration for for glob in sysctl
|
||||
#
|
||||
fs.protected_* = 2
|
||||
fs.protected_hardlinks = 1
|
||||
-fs.protected_regular
|
Reference in New Issue
Block a user