report: make report-files listing and lookup agree on masked entries

The metric list is built with conf_files_list_strv(), but each metric's
value is then looked up again by walking report_files_dirs[] by hand,
and the two disagreed whenever an earlier directory had an entry that is
not a regular file:

 - conf_files_list_strv() skipped such an entry and listed the one from
   a later directory, so the metric was advertised by Describe();
 - file_metric_generate() only moved on to the next directory on
   -ENOENT, so it hit the non-regular entry, logged a warning and
   produced nothing.

The practical case is masking a vendor-supplied entry with a symlink to
/dev/null: the metric kept being described, was never listed, and every
scrape logged "Failed to open ..., skipping: File descriptor in bad
state".

Honour masks in the enumeration via CONF_FILES_FILTER_MASKED_BY_SYMLINK,
as other conf dirs do, and make the lookup skip non-regular entries the
same way the enumeration does. Document the masking in the man page and
cover both cases in TEST-74-AUX-UTILS.report.

(cherry picked from commit 08be8677539642f45c6127085283cf08b6a410b7)
This commit is contained in:
Armaan Sandhu
2026-10-16 11:36:32 +01:00
committed by Luca Boccassi
parent f9b52a6be3
commit f41defc034
3 changed files with 62 additions and 6 deletions
+23
View File
@@ -249,6 +249,9 @@ at_exit() {
systemctl stop fake-report-server fake-report-server-tls
systemctl stop systemd-report.socket systemd-report-files.socket systemd-report-sign-plain.socket
rm -f /run/systemd/report.files/testreportfile /run/systemd/report.files/binaryfile
rm -f /run/systemd/report.files/maskedfile /var/lib/systemd/report.files/maskedfile /var/lib/systemd/report.files/dirshadowed
rm -f /run/systemd/report.files/fifoshadowed /var/lib/systemd/report.files/fifoshadowed
rmdir /run/systemd/report.files/dirshadowed 2>/dev/null
rm -rf "$CERTDIR" "${SIGN_WORK:-}"
}
trap at_exit EXIT
@@ -301,6 +304,26 @@ files_metrics="$(varlinkctl call --more /run/systemd/report/io.systemd.Files io.
[ -z "$(files_value io.systemd.Files.binaryfile)" ]
rm -f /run/systemd/report.files/binaryfile
# An entry in an earlier directory that is a symlink to /dev/null masks the one
# in a later directory: it must be neither listed nor described. An entry that
# isn't a regular file is ignored, so the later one is reported instead.
mkdir -p /var/lib/systemd/report.files
echo masked >/var/lib/systemd/report.files/maskedfile
echo shadowed >/var/lib/systemd/report.files/dirshadowed
ln -s /dev/null /run/systemd/report.files/maskedfile
mkdir /run/systemd/report.files/dirshadowed
echo fifo-shadowed >/var/lib/systemd/report.files/fifoshadowed
mkfifo /run/systemd/report.files/fifoshadowed
files_metrics="$(varlinkctl call --more /run/systemd/report/io.systemd.Files io.systemd.Metrics.List {})"
files_describe="$(varlinkctl call --more /run/systemd/report/io.systemd.Files io.systemd.Metrics.Describe {})"
[ -z "$(files_value io.systemd.Files.maskedfile)" ]
(! echo "$files_describe" | jq --seq -r .name | grep -wx io.systemd.Files.maskedfile >/dev/null)
[ "$(files_value io.systemd.Files.dirshadowed)" = "shadowed" ]
[ "$(files_value io.systemd.Files.fifoshadowed)" = "fifo-shadowed" ]
rm -f /run/systemd/report.files/fifoshadowed /var/lib/systemd/report.files/fifoshadowed
rm -f /run/systemd/report.files/maskedfile /var/lib/systemd/report.files/maskedfile /var/lib/systemd/report.files/dirshadowed
rmdir /run/systemd/report.files/dirshadowed
# -----------------------------------------------------------------------------
# Test report signing through the plain software backend, driven entirely via
# the io.systemd.Report Varlink interface (the GenerateSigned method). The plain