add --ready-fd to signal readiness #7904
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new commandline option, --ready-fd, to send a notification when sway is ready to run.
This allows a process supervisor to notice sway's startup is complete which allows, for example, the session manager to start Wayland programs in the right order. Without this signal, users have to go through horrible hacks to order services.
For example, I've been using
NotifyAccess=allin thesway.servicefile andexec systemd-notify --readyin my sway config to emulate this. Problem is it's racy and error-prone.A particularly nasty bug triggered by
NotifyAccess=allis whenpodmanstarts and then terminates a container. In that context,conmon(8)ends up notifying systemd it's the session master and takes over theeMainPIDfield in systemd. When it dies, systemd believes the session is over and proceeds to kill the entire session. This is explained in more details in:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1039857
This might not actually be the right place to do this in the sway startup sequence, that said. We call
server_runright after, and maybe somewhere below that would be a better place. Butserver_runonly callswl_display_runand that's part of the core wayland library, so that seems a little too far down. I'm not sure Wayland itself is a place to do this, so for now I'm scratching my own itch and doing this in Sway itself.Note that this approach was taken instead of using the proper
sd_notifylibrary call, as that approach was refused in #7659. The--ready-fdapproach was accepted in swaywm/swaylock#281 so it is hoped it will be seen as acceptable here.An alternative implementation would be to instead check the
NOTIFY_SOCKETenvironment variable and use that, if present. That variable is used by systemd and at least the s6 supervisor to receive readiness notifications, so it might be less disruptive.