From b438ebd7bc11d23e3cbdffa1935513d02e7b797c Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 8 May 2024 10:20:20 +0200 Subject: [PATCH 1/5] TEST-07-PID1: Fix race in aux-scope subtest Currently test-aux-scope.service can get killed by the test before it's had a chance to setup its signal handler. Make it Type=notify to fix the race. Fixes #32670 (hopefully) --- src/test/test-aux-scope.c | 5 +++++ test/units/testsuite-07.aux-scope.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/test-aux-scope.c b/src/test/test-aux-scope.c index 175757b1c18..c6a1d292730 100644 --- a/src/test/test-aux-scope.c +++ b/src/test/test-aux-scope.c @@ -10,6 +10,7 @@ #include "bus-error.h" #include "bus-message.h" #include "bus-wait-for-jobs.h" +#include "daemon-util.h" #include "fd-util.h" #include "log.h" #include "missing_syscall.h" @@ -152,6 +153,10 @@ int main(int argc, char *argv[]) { pids[i] = TAKE_PIDREF(pidref); } + r = sd_notify(false, NOTIFY_READY); + if (r < 0) + return log_error_errno(r, "Failed to send readiness notification: %m"); + r = sd_event_loop(event); if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); diff --git a/test/units/testsuite-07.aux-scope.sh b/test/units/testsuite-07.aux-scope.sh index 41c0617d4db..8e2a99ce027 100755 --- a/test/units/testsuite-07.aux-scope.sh +++ b/test/units/testsuite-07.aux-scope.sh @@ -11,7 +11,7 @@ if ! grep -q pidfd_open /proc/kallsyms; then fi systemd-run --unit test-aux-scope.service \ - -p Slice=aux.slice -p Type=exec -p TasksMax=99 -p CPUWeight=199 -p IPAccounting=yes \ + --service-type notify -p Slice=aux.slice -p TasksMax=99 -p CPUWeight=199 -p IPAccounting=yes \ /usr/lib/systemd/tests/unit-tests/manual/test-aux-scope kill -s USR1 "$(systemctl show --value --property MainPID test-aux-scope.service)" From a35edc9ad458c0ca3fa4f5435c4ceb2865a9de30 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 8 May 2024 11:21:42 +0200 Subject: [PATCH 2/5] TEST-74-AUX-UTILS: Make more robust Let's run mkfs on the file we create instead of the loop device and let's use udevadm wait --settle to wait for udev to settle before doing anything with the loop device Fixes #32680 (hopefully) --- test/units/testsuite-74.mount.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/units/testsuite-74.mount.sh b/test/units/testsuite-74.mount.sh index 594c123e1ba..57b06bb005b 100755 --- a/test/units/testsuite-74.mount.sh +++ b/test/units/testsuite-74.mount.sh @@ -32,8 +32,9 @@ systemd-mount --list --quiet # Set up a simple block device for further tests dd if=/dev/zero of="$WORK_DIR/simple.img" bs=1M count=16 +mkfs.ext4 -L sd-mount-test "$WORK_DIR/simple.img" LOOP="$(losetup --show --find "$WORK_DIR/simple.img")" -mkfs.ext4 -L sd-mount-test "$LOOP" +udevadm wait --timeout 60 --settle "$LOOP" mkdir "$WORK_DIR/mnt" mount "$LOOP" "$WORK_DIR/mnt" touch "$WORK_DIR/mnt/foo.bar" @@ -130,8 +131,9 @@ systemd-umount "$WORK_DIR/simple.img" # Create a vfat image, as ext4 doesn't support uid=/gid= fixating for all # files/directories dd if=/dev/zero of="$WORK_DIR/owner-vfat.img" bs=1M count=16 +mkfs.vfat -n owner-vfat "$WORK_DIR/owner-vfat.img" LOOP="$(losetup --show --find "$WORK_DIR/owner-vfat.img")" -mkfs.vfat -n owner-vfat "$LOOP" +udevadm wait --timeout 60 --settle "$LOOP" # Mount it and check the UID/GID [[ "$(stat -c "%U:%G" "$WORK_DIR/mnt")" == "root:root" ]] systemd-mount --owner=testuser "$LOOP" "$WORK_DIR/mnt" From 677430b3c7fcd1b352eb66f19b8746741459b91a Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 8 May 2024 11:35:21 +0200 Subject: [PATCH 3/5] tmpfiles: Don't fail if file does not exist in item_do() If the file was removed by some other program, we should just go to the next one without failing. item_do() is only used for recursive globs instead of fixed paths so skipping on missing files makes sense (unlike if the path was fixed where we should probably fail). Fixes #32691 (hopefully) --- src/tmpfiles/tmpfiles.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index ec6d8dcfa16..722dff100a1 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -2512,7 +2512,7 @@ static int item_do( fdaction_t action) { struct stat st; - int r = 0, q; + int r = 0, q = 0; assert(c); assert(i); @@ -2547,9 +2547,10 @@ static int item_do( continue; de_fd = openat(fd, de->d_name, O_NOFOLLOW|O_CLOEXEC|O_PATH); - if (de_fd < 0) - q = log_error_errno(errno, "Failed to open() file '%s': %m", de->d_name); - else { + if (de_fd < 0) { + if (errno != -ENOENT) + q = log_error_errno(errno, "Failed to open file '%s': %m", de->d_name); + } else { _cleanup_free_ char *de_path = NULL; de_path = path_join(path, de->d_name); From 65690de6f994b383e2f060df855e151a45356264 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 8 May 2024 11:41:04 +0200 Subject: [PATCH 4/5] TEST-81-GENERATORS: Do a lazy unmounts Otherwise we might fail if PID 1 is currently accessing these files. Fixes #32692 (hopefully) --- test/units/generator-utils.sh | 2 +- test/units/testsuite-81.getty-generator.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/units/generator-utils.sh b/test/units/generator-utils.sh index fb62747fa1f..97a63d80431 100755 --- a/test/units/generator-utils.sh +++ b/test/units/generator-utils.sh @@ -72,7 +72,7 @@ run_and_list() { ls -lR "$out_dir" if [[ -n "${environ:-}" ]]; then - umount /proc/1/environ + umount /proc/1/environ --lazy rm -f "$environ" fi } diff --git a/test/units/testsuite-81.getty-generator.sh b/test/units/testsuite-81.getty-generator.sh index 103e9661913..d1dd22c18ec 100755 --- a/test/units/testsuite-81.getty-generator.sh +++ b/test/units/testsuite-81.getty-generator.sh @@ -85,5 +85,5 @@ PID1_ENVIRON="SYSTEMD_GETTY_AUTO=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR" [[ "$(find "$OUT_DIR" ! -type d | wc -l)" -eq 0 ]] # Cleanup -umount /sys/class/tty/console/active +umount /sys/class/tty/console/active --lazy rm -f "${DUMMY_CONSOLES[@]/#//dev/}" /dev/notatty99 From 904b8ae47a975199b1282920ef612c688cc77638 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 8 May 2024 11:44:28 +0200 Subject: [PATCH 5/5] TEST-04-JOURNAL: Sleep more in delegated cgroup filtering script We already changed logs-filtering.service to sleep 2 seconds before exiting to combat flakyness, let's do the same for the delegated cgroup filtering payload. Fixes #32696 (hopefully) --- test/units/delegated_cgroup_filtering_payload.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/delegated_cgroup_filtering_payload.sh b/test/units/delegated_cgroup_filtering_payload.sh index 7ad486bcadd..1181fbb9108 100755 --- a/test/units/delegated_cgroup_filtering_payload.sh +++ b/test/units/delegated_cgroup_filtering_payload.sh @@ -6,4 +6,4 @@ mkdir /sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child echo "parent_process: hello, world!" echo "parent_process: hello, people!" -sleep .15 +sleep 2