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:
Craig Small
2021-09-13 22:07:37 +10:00
parent 271004bd0d
commit 474847ed35
5 changed files with 389 additions and 175 deletions

View File

@ -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

View 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"
}

View File

@ -0,0 +1,6 @@
#
# Test configuration for for glob in sysctl
#
fs.protected_* = 2
fs.protected_hardlinks = 1
-fs.protected_regular