diff options
author | Quentin Deslandes <qde@naccy.de> | 2023-01-26 19:44:10 +0100 |
---|---|---|
committer | Quentin Deslandes <qde@naccy.de> | 2023-02-08 16:52:51 +0100 |
commit | 41b7fcc5e8a66709ad5d6c7cdba1375539f7693d (patch) | |
tree | 6ebd54234139c497b121fddb16a2e91e11af5a60 /test | |
parent | core: add cg_path_get_unit_path() (diff) | |
download | systemd-41b7fcc5e8a66709ad5d6c7cdba1375539f7693d.tar.xz systemd-41b7fcc5e8a66709ad5d6c7cdba1375539f7693d.zip |
journald: fix ignored filtering patterns for delegated cgroups
If a service defines Delegate=yes, its subcgroup won't inherit the
LogFilterPatterns= option, because the option is stored on the unit's
cgroup attributes, not on the subcgroup.
Fixed by using the unit's cgroup attributes instead.
Diffstat (limited to 'test')
-rw-r--r-- | test/testsuite-04.units/delegated-cgroup-filtering.service | 8 | ||||
-rwxr-xr-x | test/units/delegated_cgroup_filtering_payload.sh | 12 | ||||
-rwxr-xr-x | test/units/delegated_cgroup_filtering_payload_child.sh | 11 | ||||
-rwxr-xr-x | test/units/testsuite-04.sh | 11 |
4 files changed, 40 insertions, 2 deletions
diff --git a/test/testsuite-04.units/delegated-cgroup-filtering.service b/test/testsuite-04.units/delegated-cgroup-filtering.service new file mode 100644 index 0000000000..2c4201a27b --- /dev/null +++ b/test/testsuite-04.units/delegated-cgroup-filtering.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test service for delegated logs filtering + +[Service] +Type=simple +ExecStart=/usr/lib/systemd/tests/testdata/units/delegated_cgroup_filtering_payload.sh +Delegate=yes +SyslogLevel=notice diff --git a/test/units/delegated_cgroup_filtering_payload.sh b/test/units/delegated_cgroup_filtering_payload.sh new file mode 100755 index 0000000000..50d01a5d4a --- /dev/null +++ b/test/units/delegated_cgroup_filtering_payload.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: LGPL-2.1-or-later + +mkdir /sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child +/bin/sh /usr/lib/systemd/tests/testdata/units/delegated_cgroup_filtering_payload_child.sh & + +while true +do + echo "parent_process: hello, world!" + echo "parent_process: hello, people!" + sleep .15 +done diff --git a/test/units/delegated_cgroup_filtering_payload_child.sh b/test/units/delegated_cgroup_filtering_payload_child.sh new file mode 100755 index 0000000000..b5635b58e5 --- /dev/null +++ b/test/units/delegated_cgroup_filtering_payload_child.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# SPDX-License-Identifier: LGPL-2.1-or-later + +echo $$ >/sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child/cgroup.procs + +while true +do + echo "child_process: hello, world!" + echo "child_process: hello, people!" + sleep .15 +done diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index d10a9afbf7..bab2bdc24e 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -185,8 +185,8 @@ function add_logs_filtering_override() { LOG_FILTER=${3:-""} mkdir -p /etc/systemd/system/"$UNIT".d/ - echo "[Service]" >/etc/systemd/system/logs-filtering.service.d/"${OVERRIDE_NAME}".conf - echo "LogFilterPatterns=$LOG_FILTER" >>/etc/systemd/system/logs-filtering.service.d/"${OVERRIDE_NAME}".conf + echo "[Service]" >/etc/systemd/system/"$UNIT".d/"${OVERRIDE_NAME}".conf + echo "LogFilterPatterns=$LOG_FILTER" >>/etc/systemd/system/"$UNIT".d/"${OVERRIDE_NAME}".conf systemctl daemon-reload } @@ -256,7 +256,14 @@ if is_xattr_supported; then add_logs_filtering_override "logs-filtering.service" "10-allow-with-escape-char" "\x7emore~" [[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] + add_logs_filtering_override "delegated-cgroup-filtering.service" "00-allow-all" ".*" + [[ -n $(run_service_and_fetch_logs "delegated-cgroup-filtering.service") ]] + + add_logs_filtering_override "delegated-cgroup-filtering.service" "01-discard-hello" "~hello" + [[ -z $(run_service_and_fetch_logs "delegated-cgroup-filtering.service") ]] + rm -rf /etc/systemd/system/logs-filtering.service.d + rm -rf /etc/systemd/system/delegated-cgroup-filtering.service.d fi touch /testok |