GNOME Bugzilla – Bug 575880
Should provide DBus API for shutting down/rebooting/suspending the machine
Last modified: 2012-11-21 20:33:55 UTC
Ubuntu does not use the session dialog as the primary method of terminating sessions. Instead, it uses a patched fast-user-switch applet to do this. The patched FUSA currently directly uses the Stop and Reboot ConsoleKit methods to shutdown or reboot the machine. Whilst this works, it is not ideal as it does not benefit from any session saving or inhibit capabilities from gnome-session (but allows us to have PolicyKit integration in the FUSA for these actions). There is currently appears to be no way for an external application to benefit from all of gnome-session's capabilities (session saving, inhibit, policykit support...), without adding extra DBus methods to gnome-session to allow an application to stop or restart the machine directly without calling the session dialog. Such a method already exists for logout, but not for shutdown or reboot.
Created attachment 130924 [details] [review] dbus_shutdown_now.patch Here is a patch that adds ShutdownNow and RebootNow methods, which call request_shutdown() and request_reboot() directly without calling the session dialog.
Likewise, the shell needs a "suspend now" API (bug 636680)
(In reply to comment #1) > Created an attachment (id=130924) [details] [review] > dbus_shutdown_now.patch > > Here is a patch that adds ShutdownNow and RebootNow methods, which call > request_shutdown() and request_reboot() directly without calling the session > dialog. I don't think the "Now" stuff is correct. We should probably change the Shutdown method to be like the Logout one, and take an argument to know whether interaction should be done or not. (In reply to comment #2) > Likewise, the shell needs a "suspend now" API (bug 636680) So are we giving up on letting upower/g-p-m do that?
(In reply to comment #3) > > Likewise, the shell needs a "suspend now" API (bug 636680) > > So are we giving up on letting upower/g-p-m do that? as with the shutdown/reboot, gnome-session has a "value-added" suspend method. eg, it makes sure to start gnome-screensaver before suspending, so that it's already locked when you resume (instead of resuming to an unlocked desktop that then immediately suspends) if those smarts got moved into upower/g-p-m/wherever I'd be happy to use that API instead.
(In reply to comment #4) > already locked when you resume (instead of resuming to an unlocked desktop that > then immediately suspends) s/immediately suspends/immediately locks/
(In reply to comment #4) > (In reply to comment #3) > > > Likewise, the shell needs a "suspend now" API (bug 636680) > > > > So are we giving up on letting upower/g-p-m do that? > > as with the shutdown/reboot, gnome-session has a "value-added" suspend method. > eg, it makes sure to start gnome-screensaver before suspending, so that it's > already locked when you resume (instead of resuming to an unlocked desktop that > then immediately suspends) Right. But my understanding is that we added them to gnome-session as a temporary workaround, to get things working. See the quick discussion in bug 598118. The main issue is that as long as we get a dbus API in upower to suspend the machine, some people will use the upower API. And it won't do all the smart things. So that's really what we should fix, imho. And since the setting is probably in GSettings now, upower-glib can probably read the setting and do the right thing if running in a GNOME session. cc'ing Richard, to get his input.
Any progress on this one? For Sugar we'd like to use the upstream version of gnome-session instead of bundling our own custom (and ancient) copy of it. Since #633276 has been merged this is possible in general (thanks!), but we're still lacking a way to wire up the Shutdown and Reboot menu options. Those options trigger a shutdown resp. reboot of the machine without further confirmation (and if there were a confirmation, it would be custom UI, not the standard gnome-session dialog). Right now there isn't even a way to trigger a reboot at all, let alone without popping up a gnome-session dialog.
Created attachment 213677 [details] [review] [PATCH] Provide D-Bus API for shutting down and rebooting the machine Several downstream projects (e.g. Sugar, Ubuntu) use gnome-session (patched and / or ancient version), but have custom UI for triggering shutdown, reboot and suspend. In order to use the upstream version of gnome-session, those projects need to be able to trigger those actions without gnome-session showing additional UI. Logging out without prompting the user is already supported by the Logout() method with the GSM_MANAGER_LOGOUT_MODE_NO_CONFIRMATION parameter. Because Shutdown() is already defined (it causes gnome-session to show a dialog where the user can choose what to do), the two new methods for shutting down resp. rebooting without user interaction are called ShutdownNow() and RebootNow(). This is inconsistent with the naming of the existing Logout() method, but as the Shutdown() action may be in use by other downstream projects backwards compatibility was deemed more important. Tested using a patched version of Sugar on Debian Wheezy: - Logout(GSM_MANAGER_LOGOUT_MODE_NO_CONFIRMATION), ShutdownNow() and RebootNow() all: - don't ask the user for confirmation - cause the state of applications to be saved - do what they're advertised to do (i.e. log out the user, shutdown or reboot the machine) Operation with Gnome was not tested as only additional functions are provided and no any existing code is altered.
I've cleaned up the patch (white space fixes, added description) and tested it successfully with Sugar. With this patch, we're almost ready to use upstream gnome-session instead of our ancient bundled copy. What else is needed to get this landed? AFAICT even with systemd gnome-session is the component used by Gnome to allow the user to shut down or reboot the machine. And I don't really expect this to change in the future as no other component has the ability to save the state of open applications. It will always be gnome-session that handles the end of session sequencing, interacting with other components (e.g. systemd) to handle the low-level details.
Thanks for working on this. See comment 3 for some comments Vincent made on the previous patch that are still applicable I think.
Thanks for the reply, Ray. I addressed those comments in my patch description: Because Shutdown() is already defined (it causes gnome-session to show a dialog where the user can choose what to do), the two new methods for shutting down resp. rebooting without user interaction are called ShutdownNow() and RebootNow(). This is inconsistent with the naming of the existing Logout() method, but as the Shutdown() action may be in use by other downstream projects backwards compatibility was deemed more important. But if the gnome-session maintainers consider API consistency to be more important than backwards compatibility in this case, I can change the patch accordingly. Is there some documentation of how to handle backwards-incompatible API changes for gnome-session (something like http://0pointer.de/blog/projects/versioning-dbus.html)? I don't want other downstreams to be stuck with choosing between _either_ the old version of gnome-session (which some distros will not ship anymore) _or_ the new one (which some other distros may not ship yet). Choosing between the two API versions must be possible to do automatically and easily at run-time.
The API is now provided by systemd's logind: http://www.freedesktop.org/wiki/Software/systemd/logind If you want to support system that do not use systemd, some maintainers have chosen to still support a mixture of upower and ConsoleKit.