summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorCraig Small <csmall@dropbear.xyz>2021-09-13 22:07:37 +1000
committerCraig Small <csmall@dropbear.xyz>2021-09-15 20:07:32 +1000
commit6389deca5bf667f5fab5912acde78ba8e0febbc7 (patch)
treedb253db3f3b6549664ac44c415f350a5f684b640 /testsuite
parent8c23dfdcd4d2abeb4ca8f5a20cae043c3c4ae60e (diff)
downloadprocps-ng-6389deca5bf667f5fab5912acde78ba8e0febbc7.tar.gz
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>
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/config/unix.exp9
-rw-r--r--testsuite/sysctl.test/sysctl_write.exp29
-rw-r--r--testsuite/sysctl_glob_test.conf6
3 files changed, 44 insertions, 0 deletions
diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp
index 4156c3b..ecdc0bf 100644
--- a/testsuite/config/unix.exp
+++ b/testsuite/config/unix.exp
@@ -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
diff --git a/testsuite/sysctl.test/sysctl_write.exp b/testsuite/sysctl.test/sysctl_write.exp
new file mode 100644
index 0000000..5a74dec
--- /dev/null
+++ b/testsuite/sysctl.test/sysctl_write.exp
@@ -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"
+}
diff --git a/testsuite/sysctl_glob_test.conf b/testsuite/sysctl_glob_test.conf
new file mode 100644
index 0000000..45ae904
--- /dev/null
+++ b/testsuite/sysctl_glob_test.conf
@@ -0,0 +1,6 @@
+#
+# Test configuration for for glob in sysctl
+#
+fs.protected_* = 2
+fs.protected_hardlinks = 1
+-fs.protected_regular