csm-systemd: wait for logind's PrepareForShutdown before quitting - #215
leigh123linux wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are confirmed failure-path issues that can crash initialization or leave the session stuck in a non-running phase when shutdown/reboot isn’t confirmed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves cinnamon-session’s shutdown/reboot flow when using logind by taking its own delay inhibitor, dropping conflicting block inhibitors, and waiting for logind’s PrepareForShutdown signal before quitting; it also removes the long-dead MDM display-manager fallback code paths.
Changes:
- Add a
shutdown-preparedsignal andcomplete_shutdown()hook to theCsmSysteminterface, and implement delay-inhibitor handling +PrepareForShutdownlistening in the systemd backend. - Update
CsmManagerto quit only after shutdown is confirmed (and remove the old request-failed → MDM fallback). - Remove
mdm.c/mdm.hand update the build to stop compiling MDM logout-action support.
File summaries
| File | Description |
|---|---|
| cinnamon-session/meson.build | Removes mdm.c from the build sources. |
| cinnamon-session/mdm.h | Deletes legacy MDM logout-action API header. |
| cinnamon-session/mdm.c | Deletes legacy MDM protocol implementation. |
| cinnamon-session/csm-systemd.c | Adds delay inhibitor + waits for PrepareForShutdown, emits shutdown-prepared, implements complete_shutdown(). |
| cinnamon-session/csm-system.h | Extends CsmSystemInterface with complete_shutdown(). |
| cinnamon-session/csm-system.c | Adds shutdown-prepared signal and csm_system_complete_shutdown() wrapper. |
| cinnamon-session/csm-manager.c | Removes MDM fallback and waits for shutdown-prepared before quitting. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| on_shutdown_prepared (CsmSystem *system, | ||
| gboolean success, | ||
| gpointer user_data) | ||
| { | ||
| g_warning ("Using an MDM logout action to shutdown/reboot the system."); | ||
| MdmLogoutAction fallback_action = GPOINTER_TO_INT (user_data); | ||
| mdm_set_logout_action (fallback_action); | ||
| csm_quit (); | ||
| g_signal_handlers_disconnect_by_func (system, on_shutdown_prepared, user_data); |
| } else { | ||
| g_signal_connect (manager->priv->sd_proxy, "g-signal", | ||
| G_CALLBACK (sd_proxy_signal_cb), manager); | ||
| } | ||
|
|
0718144 to
6886fee
Compare
| csm_quit (); | ||
| } else { | ||
| g_warning ("Shutdown/restart was not confirmed by logind; staying in session."); | ||
| csm_system_complete_shutdown (system); |
There was a problem hiding this comment.
Don't we still need to csm_quit() regardless? csd_manager_quit() is called from CSM_MANAGER_PHASE_EXIT - everything has already terminated, the session is done. There's no point in leaving a blank/broken desktop either way.
There was a problem hiding this comment.
I don't know if we need csm_system_complete_shutdown() either - we could just csm_quit() on this callback and print an error if !success.
csm_system_complete_shutdown() would release the inhibitor here, while cinnamon-session is still running. If you just csm_quit() the process exits and the inhibitor gets dropped automatically (fd closes).
You could remove the whole complete_shutdown vfunc in csm-system.*, etc... and just rename it to a static function in csm-systemd.c:
static void
drop_shutdown_inhibitor (CsmSystemd *manager)
{
if (manager->priv->shutdown_inhibit_fd != -1) {
g_debug ("Dropping shutdown inhibitor");
close (manager->priv->shutdown_inhibit_fd);
manager->priv->shutdown_inhibit_fd = -1;
}
}
so it can still be called by reboot_or_poweroff_done() there.
6886fee to
cacad1c
Compare
cacad1c to
d615cfe
Compare
cinnamon-session quit immediately after requesting PowerOff/Reboot via
logind, without confirming logind had actually accepted the request. If
another process held a delay inhibitor, cinnamon-session would tear
down and hand back to the display manager greeter well before the
machine actually powered off, leaving the session in a misleading
half-terminated state for the duration of the delay.
Take our own delay inhibitor before requesting shutdown/restart, drop
any held block inhibitor (which would make logind refuse the request
outright), and wait for logind's PrepareForShutdown signal to confirm
shutdown is genuinely proceeding before quitting -- matching
gnome-session's gsm_systemd_prepare_shutdown()/complete_shutdown().
Also remove the MDM display-manager fallback path (quit_request_failed,
mdm_set_logout_action calls, the CSM_MANAGER_LOGOUT_*_MDM enum values,
and mdm.c/mdm.h) since it's dead: Linux Mint dropped MDM for LightDM
years ago, and the fallback was never actually reachable once
csm_manager_quit() started quitting unconditionally after issuing the
shutdown/restart request.
Fixes: #214