Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data/systemd: allow notifications for all snapd subprocesses #13797

Merged

Conversation

alfonsosanchezbeato
Copy link
Member

Allow all service's control group processes to send notifications via sd_notify. This is necesssary to prevent log flooding with systemd warnings like:

Apr 05 14:36:55 qemuname systemd[1]: snapd.service: Got notification message from PID 1002, but reception only permitted for main PID 917

These warnings are happening due to a change in systemd 254 that makes all systemd programs (systemctl, udevadm, systemd-detect-virt, etc.) send EXIT_STATUS notifications when exiting.

Fixes LP#2060310.

Allow all service's control group processes to send notifications via
sd_notify. This is necesssary to prevent log flooding with systemd
warnings like:

Apr 05 14:36:55 qemuname systemd[1]: snapd.service: Got notification
message from PID 1002, but reception only permitted for main PID 917

This warnings are happening due to a change in systemd 254 that makes
all systemd programs (systemctl, udevadm, systemd-detect-virt, etc.)
send EXIT_STATUS notifications when exiting.

Fixes LP#2060310.
@alfonsosanchezbeato alfonsosanchezbeato added the Simple 😃 A small PR which can be reviewed quickly label Apr 6, 2024
@alfonsosanchezbeato alfonsosanchezbeato added this to the 2.63 milestone Apr 6, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.86%. Comparing base (ab996a0) to head (3756a70).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13797      +/-   ##
==========================================
- Coverage   78.86%   78.86%   -0.01%     
==========================================
  Files        1043     1043              
  Lines      134595   134595              
==========================================
- Hits       106144   106143       -1     
  Misses      21837    21837              
- Partials     6614     6615       +1     
Flag Coverage Δ
unittests 78.86% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -20,6 +20,7 @@ EnvironmentFile=-@SNAPD_ENVIRONMENT_FILE@
Restart=always
WatchdogSec=5m
Type=notify
NotifyAccess=all
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is ok in principle. There's a separate question what this means whenever systemd receives event with EXIT_STATUS=xx from a PID that isn't the main one of the service, supposedly it's only informational.

Anyhow, if it's informational than maybe we should also report EXIT_STATUS in our tools we invoke from snapd, eg. snap-fde-keymgr, maybe snap-update-ns

There's even a funnier question, what if the process exits with non-0, but sends EXIT_STATUS=0 ? if we extend s-u-n then this could happen when s-u-n exits after finishing mount setup.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tbh I'm not sure of the use case of things like systemctl reportring EXIT_STATUS. https://github.com/systemd/systemd/blob/v254/NEWS#L649-L655 talks about containers, to collect info when the system shuts down, but still it is not clear to me how these notifications help. Maybe the last returned value is used in some cases as exit value of systemd, or that is the intention in the future.

Another option here is to unset the NOTIFY_SOCKET env var before calling the subprocesses to avoid these notifications.

Copy link
Member

Choose a reason for hiding this comment

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

I think this looks fine, according to systemd docs around NotifyAccess

This option should be set to open access to the notification socket when using Type=notify/Type=notify-reload or WatchdogSec= (see above). If those options are used but NotifyAccess= is not configured, it will be implicitly set to main.

So it sounds like changing this to all when Type=notify sounds sensible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of unsetting NOTIFY_SOCKET when calling commands, like systemctl or udevadm. I feel it should really not be defined.

Copy link
Member

@Meulengracht Meulengracht left a comment

Choose a reason for hiding this comment

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

Thank you, +1 based on my comment

@ernestl ernestl merged commit 5fdec02 into snapcore:master Apr 10, 2024
39 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simple 😃 A small PR which can be reviewed quickly
Projects
None yet
6 participants