-
Notifications
You must be signed in to change notification settings - Fork 158
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
server: implement wayland socket handover #2018
base: master
Are you sure you want to change the base?
Conversation
8b1a30f
to
ba86e7f
Compare
Thanks for the PR. I am not a big fan of those command line switches. Rather than enforcing all compositors to share some common naming for command line arguments, could we use some env vars which hold the fd number and socket name? Edit: |
Thanks for the quick reply! You're right, the command-line switches are a bit weird. There is precedent for passing FDs by command line switches (e.g. I like the env var idea. Do you have a suggestion for environment variable names? I'm gonna look into this and see how systemd socket activation works and if that is possible to get going with Wayland. |
For now I think I'll maybe add an experimental env var mechanism to |
I have read into systemd socket activation (docs here, C file, C header): Systemd passes three env vars, This looks like it might work for Wayland, except for the lock file that sits next to the socket, which I will have to look into or experiment with. |
I have created a discussion issue for this in wl-restart |
52046db
to
296a149
Compare
I have replaced the implementation in this branch with an environment-based socket handover mechanism (implemented in I have decided against the systemd socket activation mechanism as it does not seem to allow for automatically creating the lock file that is normally used with Wayland sockets, which would make starting a compositor under native systemd socket activation behave differently than starting it with If this or a similar mechanism is acceptable to labwc I will try to bring forward this same mechanism to other compositors such as Sway, Hyprland, and others. EDIT: I know the code style check failed and the documentation is incomplete, though a review on the general concept of the environment variable mechanism would still be much appreciated. |
The approach looks fine to me in general. There are some implementation specific issues like using |
Thanks for the review. I will try to see what the other compositors think of the mechanism then and come back to clean this up once the overall direction is clear. |
UNIX old fart here: perhaps it would be better to use the environment variables for this. |
The new implementation of this uses environment variables. Details are here, though I want to port this to a few other compositors first and wait on their feedback to avoid having diverging implementations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see nothing wrong with this in principle, although it is weird to have fatal conditions arise from unexpected conditions of environment variables. It would be better to warn if the expected conditions are not met, and then proceed to launch with the auto socket as if nothing had been defined at all.
I propose moving the environment handling out of main()
and into src/server.c
where it is actually used, allowing the interface of server_start()
to remain unchanged. A static validator function that accepts a char**
and int *
can check the environment, emit warnings when both variables are not suitably defined (which, if you expand the XOR, can be more targeted and informative than the blanket "not both are correct" phrase used now), and set the passed pointers appropriately.
src/main.c
Outdated
} | ||
|
||
/* Fail if only one of wayland socket and fd are given */ | ||
if (!socket_name ^ (socket_fd == -1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I positively abhor the abuse of bitwise operators to effect a logical Boolean operation. I'd rather see the XOR expanded using proper logical operators, but I'd even accept
(socket_name == NULL) != (socket_fd == -1)
because equality is a meaningful Boolean operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to handle both cases being missing separately in the latest commit.
Thanks for the review @ahesford, your comments absolutely make sense to me. I'll fix them as suggested. |
296a149
to
c4c3442
Compare
Updated to address the review and rebased onto latest master. This PR now only touches |
c4c3442
to
9818eb8
Compare
9818eb8
to
129a00a
Compare
Updated to fix failing checks and updated PR description. |
This PR implements the compositor side of the Wayland socket handover protocol as described in the KDE Wiki, but with passed via the environment variables
WAYLAND_SOCKET_NAME
andWAYLAND_SOCKET_FD
rather than CLI options.labwc now checks for the environment variables
WAYLAND_SOCKET_NAME
andWAYLAND_SOCKET_FD
, which pass the name of the Wayland display socket and the Wayland display socket fd number respectively. If set, labwc will use these instead of finding a free Wayland display socket name and creating it. If either variable is unset or adding the FD fails, labwc falls back to the normal behaviour.This allows for labwc to be used with a helper tool that automatically restarts the compositor on crashes, and allowing clients to reconnect after the compositor restart and survive the crash. The reconnecting clients look like new clients to labwc and perform all the same steps as a fresh Wayland client would. No additional handling is required on the side of labwc.
The helper tool finds and creates the Wayland socket and launches labwc with the new CLI options, restarting it when it exits with a non-zero exit code. Three such helper tools currently exist as far as I know:
kwin_wayland_wrapper
(only for KDE)weston_wrapper
(only for Weston, rejected by upstream)wl-restart
(compositor agnostic, developed by me)This is part of a series of PRs. I've already added the same feature to Sway (unmerged) and Hyprland (merged) in order to get the crash recovery experience of Wayland into a more usable shape regardless of compositor.
This PR description was rewritten to better reflect the PR contents (click to see old PR description)
This PR implements the compositor side of the Wayland socket handover protocol as described in the [KDE Wiki][KDE Wiki]. The CLI options are chosen so that they are compatible with Kwin (and Hyprland):labwc now accepts the CLI options
--socket NAME
and--wayland-fd FD
, which pass the name of the Wayland display socket and the Wayland display socket fd number respectively. If given, labwc will use these instead of finding a free Wayland display socket name and creating it.This allows for labwc to be used with a helper tool that automatically restarts the compositor on crashes, and allowing clients to reconnect after the compositor restart and survive the crash. The reconnecting clients look like new clients to labwc and perform all the same steps as a fresh Wayland client would. No additional handling is required on the side of labwc.
The helper tool finds and creates the Wayland socket and launches labwc with the new CLI options, restarting it when it exits with a non-zero exit code. Two such helper tools currently exist as far as I know:
kwin_wayland_wrapper
(only for KDE)wl-restart
(developed by me)I wasn't quite sure where to add the options in the help output and man pages, so I added them at the end. I didn't want to do them alphabetically, since both options only make sense together, but would be split apart since they have different names. Another option would be to rename
--socket
to--wayland-socket
in the help, but accept both--socket
and--wayland-socket
in practice.This is part of a series of PRs. I've already added the same feature to Sway (unmerged) and Hyprland (merged) in order to get the crash recovery experience of Wayland into a more usable shape regardless of compositor.