Skip to content

quadlet: only log to kmsg when running under systemd#28898

Open
mvanhorn wants to merge 2 commits into
podman-container-tools:mainfrom
mvanhorn:fix/28888-quadlet-generator-kmsg-logging
Open

quadlet: only log to kmsg when running under systemd#28898
mvanhorn wants to merge 2 commits into
podman-container-tools:mainfrom
mvanhorn:fix/28888-quadlet-generator-kmsg-logging

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

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). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • 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 gofmt and go vet (make validatepr needs a containerized environment not available locally; CI runs the full validation)
  • 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 no longer writes warnings to /dev/kmsg when run manually from a terminal; kmsg logging is kept for systemd invocations.

Fixes #28888

Comment thread cmd/quadlet/main.go
line := fmt.Sprintf("quadlet-generator[%d]: %s", os.Getpid(), s)

if !logToKmsg(line) || dryRunFlag {
stderrIsTerminal := term.IsTerminal(int(os.Stderr.Fd()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is wrong though, there is not requirement whatsoever that someone running quadlet to debug things should have a tty on stderr, in fact someone might want to pipe the output to a file

IF we want to check if we run under systemd there seem to be some env vars documented we could check https://www.freedesktop.org/software/systemd/man/latest/systemd.generator.html#Environment

but even then I would guess systemd-analyze --generators verify might set the same so they cannot be used to know that either?
In any case it seems simplest and safest to just log to both.

When the quadlet generator is run manually from a terminal, warnings and
errors were written to /dev/kmsg, polluting the kernel log. Write to
stderr for interactive runs and keep the kmsg path for systemd
invocations (no tty), preserving the existing fallback behavior.

Fixes: podman-container-tools#28888
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@mvanhorn mvanhorn force-pushed the fix/28888-quadlet-generator-kmsg-logging branch from a6f1c31 to 9ec4699 Compare June 10, 2026 11:36
@packit-as-a-service

Copy link
Copy Markdown

tmt tests failed for commit 2ce9b56. @lsm5, @psss, @thrix please check.

Comment thread cmd/quadlet/main.go

if !logToKmsg(line) || dryRunFlag {
stderrIsTerminal := term.IsTerminal(int(os.Stderr.Fd()))
kmsgOK := false

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.

Maybe we should just never log to kmesg if euid != 0.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

/packit retest-failed

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

3 participants