Skip to content

fix: quadlet generator emits diagnostics to stderr under systemd-analyze verify#29079

Open
mvanhorn wants to merge 1 commit into
podman-container-tools:mainfrom
mvanhorn:fix-quadlet-verify-stderr-logging
Open

fix: quadlet generator emits diagnostics to stderr under systemd-analyze verify#29079
mvanhorn wants to merge 1 commit into
podman-container-tools:mainfrom
mvanhorn:fix-quadlet-verify-stderr-logging

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Running sudo systemd-analyze --generators verify <unit> against a broken quadlet printed no generator diagnostics, even though the same command without sudo (and podman-system-generator -dryrun) did. The cause is in cmd/quadlet/main.go: Logf wrote each line to /dev/kmsg and only fell back to stderr when that write failed or -dryrun was set. As root the kmsg write succeeds, so nothing was written to stderr, and systemd-analyze verify captures stderr rather than kmsg.

Logf now writes to /dev/kmsg best-effort (preserving the early-boot and journal logging that root services rely on at daemon-reload) and additionally always copies the same quadlet-generator[pid]: ... line to stderr, so systemd-analyze verify and interactive sudo runs surface the diagnostics. Rootless behavior, where kmsg is unavailable, is unchanged.

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all commits. (git commit -s).
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

The quadlet generator now writes its diagnostics to stderr in addition to /dev/kmsg, so errors are visible under `systemd-analyze --generators verify` and other tooling that captures the generator's stderr, including when run as root.

Fixes #28888

Logf wrote to /dev/kmsg and only fell back to stderr when the kmsg
write failed or -dryrun was set. As root the kmsg write succeeds, so
nothing reached stderr and `sudo systemd-analyze --generators verify`
(which captures stderr, not kmsg) showed no diagnostics, while the same
command without sudo did.

Write to /dev/kmsg best-effort for early-boot/journal capture AND always
copy the same line to stderr so verify and interactive sudo runs surface
the messages. Rootless behavior is unchanged.

Fixes: podman-container-tools#28888
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Just one style question.

Comment thread cmd/quadlet/main.go
fmt.Fprintf(os.Stderr, "%s\n", line)
os.Stderr.Sync()
}
logToKmsg(line)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns a bool value; should it be like this?:

Suggested change
logToKmsg(line)
_ :=logToKmsg(line)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No systemd-analyze output using sudo

2 participants