analyze: hint when man is not installed

When "systemd-analyze verify" checks Documentation=man: entries it runs
man(1). If man is not installed, the failure is reported as if the man
page itself could not be shown:

    '(man)' failed with exit status 1.
    foo.service: Can't show systemd(1): Protocol error

This is common on minimal images and containers that leave out man-db,
and the message points at the documentation rather than at the missing
tool.

When showing the page fails, check whether man can be found and, if not,
append a hint to the existing message:

    foo.service: Can't show systemd(1), man may not be installed, pass --man=no to skip: Protocol error

The lookup happens only in the error path, so the successful case is
untouched and execvp(3) still locates man, including through a relative
PATH entry.

verify still fails in this case, since the man pages were not checked.

(cherry picked from commit 5ef99260c0)
This commit is contained in:
Pétur Ingi Egilsson authored and Luca Boccassi committed 2026-11-03 11:05:14 +00:00
1 parent 63da82861a
commit 7fcc2cc67b
2 files changed
+20 -3

No files matched your search

+7 -3
View File
@@ -232,9 +232,13 @@ static int verify_documentation(Unit *u, bool check_man) {
if (check_man && startswith(*p, "man:")) {
k = show_man_page(*p + 4, true);
if (k != 0) {
if (k < 0)
log_unit_error_errno(u, k, "Can't show %s: %m", *p + 4);
else {
if (k < 0) {
const char *hint = "";
if (find_executable("man", /* ret_filename= */ NULL) == -ENOENT)
hint = ", man may not be installed, pass --man=no to skip";
log_unit_error_errno(u, k, "Can't show %s%s: %m", *p + 4, hint);
} else {
log_unit_error(u, "Command 'man %s' failed with code %d", *p + 4, k);
k = -ENOEXEC;
}
+13
View File
@@ -491,6 +491,19 @@ systemd-analyze verify /tmp/multi-exec-start.service
echo 'ExecStart=command-should-not-exist' >>/tmp/multi-exec-start.service
(! systemd-analyze verify /tmp/multi-exec-start.service)
# test that a missing man binary is reported as such, and that --man=no skips the check.
cat <<EOF >/tmp/man-documentation.service
[Unit]
Documentation=man:systemd(1)
[Service]
Type=oneshot
ExecStart=/usr/bin/true
EOF
(! env PATH=/nonexistent "$(command -v systemd-analyze)" verify /tmp/man-documentation.service 2>/tmp/man-documentation.log)
grep "man may not be installed" /tmp/man-documentation.log >/dev/null
env PATH=/nonexistent "$(command -v systemd-analyze)" verify --man=no /tmp/man-documentation.service
# Prevent regression from #20233 where systemd-analyze will return nonzero exit codes on warnings
# Unit file with warning "Unknown key name 'foo' in section 'Unit', ignoring"