diff options
author | Quentin Deslandes <qdeslandes@naccy.de> | 2022-07-22 17:18:15 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2022-07-25 10:15:43 +0200 |
commit | e88748c17e58aad6818e64fd3071de011808165e (patch) | |
tree | 0fa58bda1d6993d81d5c1ba837147e1cd68febc3 /test | |
parent | 3657d3a01c7e25ff86d7a4642065b367c4ff7484 (diff) | |
download | systemd-e88748c17e58aad6818e64fd3071de011808165e.tar.gz |
sysctl: add --strict option to fail if sysctl does not exists
systemd-sysctl currently fails silently under any of these conditions:
- Missing permission to write a sysctl.
- Invalid sysctl (path doesn't exists).
- Ignore failure flag ('-' in front of the sysctl name).
Because of this behaviour, configuration issues can go unnoticed as
there is no way to detect those unless going through the logs.
--strict option forces systemd-sysctl to fail if a sysctl is invalid or
if permission are insufficient. Errors on sysctl marked as "ignore
failure" will still be ignored.
Diffstat (limited to 'test')
-rw-r--r-- | test/TEST-76-SYSCTL/Makefile | 6 | ||||
-rwxr-xr-x | test/TEST-76-SYSCTL/test.sh | 10 | ||||
-rw-r--r-- | test/units/testsuite-76.service | 8 | ||||
-rwxr-xr-x | test/units/testsuite-76.sh | 16 |
4 files changed, 40 insertions, 0 deletions
diff --git a/test/TEST-76-SYSCTL/Makefile b/test/TEST-76-SYSCTL/Makefile new file mode 100644 index 0000000000..9f65d4ca4f --- /dev/null +++ b/test/TEST-76-SYSCTL/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +all setup run clean clean-again: + @TEST_BASE_DIR=../ ./test.sh --$@ + +.PHONY: all setup run clean clean-again diff --git a/test/TEST-76-SYSCTL/test.sh b/test/TEST-76-SYSCTL/test.sh new file mode 100755 index 0000000000..11a44afaf5 --- /dev/null +++ b/test/TEST-76-SYSCTL/test.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -e + +TEST_DESCRIPTION="Sysctl-related tests" + +# shellcheck source=test/test-functions +. "${TEST_BASE_DIR:?}/test-functions" + +do_test "$@" diff --git a/test/units/testsuite-76.service b/test/units/testsuite-76.service new file mode 100644 index 0000000000..3c8a9e867f --- /dev/null +++ b/test/units/testsuite-76.service @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[Unit] +Description=TEST-76-SYSCTL + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/units/testsuite-76.sh b/test/units/testsuite-76.sh new file mode 100755 index 0000000000..6ebdbc6a54 --- /dev/null +++ b/test/units/testsuite-76.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +export SYSTEMD_LOG_LEVEL=debug + +echo "foo.bar=42" > /etc/sysctl.d/foo.conf +[[ $(/usr/lib/systemd/systemd-sysctl /etc/sysctl.d/foo.conf)$? -eq 0 ]] +[[ $(/usr/lib/systemd/systemd-sysctl --strict /etc/sysctl.d/foo.conf)$? -ne 0 ]] + +echo "-foo.foo=42" > /etc/sysctl.d/foo.conf +[[ $(/usr/lib/systemd/systemd-sysctl /etc/sysctl.d/foo.conf)$? -eq 0 ]] +[[ $(/usr/lib/systemd/systemd-sysctl --strict /etc/sysctl.d/foo.conf)$? -eq 0 ]] + +touch /testok |