From f8dad9989d9a6e55ac3fa4a37b856857b5286d86 Mon Sep 17 00:00:00 2001 From: Andrew Savinykh <658865+AndrewSav@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:46:25 +0000 Subject: [PATCH] Report why the mail.err cron test fails when it does "cron job stderr goes to mail.err" fails now and then in CI. In run 44396969569 the job succeeded and printed nothing, but its error never reached syslog at all: not in mail.err after 10 s, and not in the mail.log stream either. So it is not rsyslog writing late. The test now runs the job with a logger in front of the real one that keeps a copy of what it is given. On failure it writes, as TAP comments, the job's start time and status, the container's cron line, the owner of current-dbs.txt just before and after the job, any update already running, and everything the job handed to logger. Passing runs print nothing extra. --- test/default.bats | 77 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/test/default.bats b/test/default.bats index b206f88..f81feea 100644 --- a/test/default.bats +++ b/test/default.bats @@ -1054,14 +1054,81 @@ wait_for_log() { # Last on purpose: these make the clamav-unofficial-sigs cron job fail, which # writes to mail.log, mail.warn and mail.err, all checked clean above. +# +# The next test fails now and then in CI: the job succeeds and prints nothing, +# but its error never reaches syslog at all (not even mail.log), so it is not +# rsyslog being late. To tell the possible causes apart, it runs the job with +# a logger in front of the real one that keeps a copy of what it is given, +# and on failure writes these to the test output (TAP comments): +# +# - the owner of current-dbs.txt just before and after the job, in case it +# was not root-owned when the job wrote it +# - what the job handed to logger, at each priority, in case logger or +# rsyslog lost it +# - the cron line (its minute) and any update running when the job started, +# in case the container's own hourly job overlapped the test + +SIGS_DIAG=/tmp/sigs-diag +SIGS_DBS=/var/lib/clamav-unofficial-sigs/configs/current-dbs.txt + +# Install the copying logger in $SIGS_DIAG. Each call keeps its arguments and +# input in a file of its own. +sigs_diag_setup() { + docker exec mailserver_default /bin/sh -c "rm -rf $SIGS_DIAG && mkdir -m 1777 $SIGS_DIAG" + docker exec -i mailserver_default /bin/sh -c "cat > $SIGS_DIAG/logger && chmod 755 $SIGS_DIAG/logger" <<'EOF' +#!/bin/sh +f=$(mktemp /tmp/sigs-diag/logger.XXXXXX) +echo "logger $*" > "$f" +tee -a "$f" | /usr/bin/logger "$@" +EOF +} + +# sigs_cron_job, with the copying logger first on the PATH +sigs_cron_job_diag() { + docker exec mailserver_default /bin/sh -c "grep -q '^enable_random=\"no\"' /etc/clamav-unofficial-sigs/user.conf || echo 'enable_random=\"no\"' >> /etc/clamav-unofficial-sigs/user.conf" + docker exec mailserver_default /bin/sh -c "grep -v '^#' /etc/cron.d/clamav-unofficial-sigs | grep . | { read -r m h dom mon dow user cmd; su -s /bin/sh \"\$user\" -c \"PATH=$SIGS_DIAG:\\\$PATH; export PATH; \$cmd\"; }" +} + +sigs_owner() { + docker exec mailserver_default stat -c '%U (inode %i, modified %y)' $SIGS_DBS 2>&1 +} + +sigs_running() { + docker exec mailserver_default /bin/sh -c "ps -eo pid,user,lstart,args | grep '[c]lamav-unofficial-sigs[-a-z]*\.sh' || echo '(none)'" + docker exec mailserver_default ls -l /var/lib/clamav-unofficial-sigs/pid/ 2>&1 || true +} + +# Write lines to the test output as TAP comments +sigs_diag_note() { + sed 's/^/# /' >&3 +} + @test "checking clamav-unofficial-sigs: cron job stderr goes to mail.err" { - docker exec mailserver_default chown root /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt - run sigs_cron_job - docker exec mailserver_default chown clamav /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt - assert_success - assert_output '' + sigs_diag_setup + docker exec mailserver_default chown root $SIGS_DBS + before=$(sigs_owner) + running=$(sigs_running) + started=$(date -u +%T.%N) + run sigs_cron_job_diag + job_status=$status job_output=$output + after=$(sigs_owner) + docker exec mailserver_default chown clamav $SIGS_DBS run wait_for_log 'clamav-unofficial-sigs.*current-dbs.txt: Permission denied' /var/log/mail.err + if [ "$status" -ne 0 ]; then + { + echo "diagnostics: job started at $started UTC, exit status $job_status" + echo "cron line: $(docker exec mailserver_default grep -v '^#' /etc/cron.d/clamav-unofficial-sigs | grep .)" + echo "current-dbs.txt before the job: $before" + echo "current-dbs.txt after the job: $after" + echo "updates running when the job started, and the pid directory:" + echo "$running" + echo "what the job handed to logger:" + docker exec mailserver_default /bin/sh -c "for f in $SIGS_DIAG/logger.*; do [ -e \"\$f\" ] || { echo '(logger was not called)'; break; }; echo \"--- \$f\"; cat \"\$f\"; done" + } | sigs_diag_note + fi assert_success + assert_equal "$job_status" 0 + assert_equal "$job_output" '' } @test "checking clamav-unofficial-sigs: cron job stdout goes to mail.warning" {