After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 575880 - Should provide DBus API for shutting down/rebooting/suspending the machine
Should provide DBus API for shutting down/rebooting/suspending the machine
Status: RESOLVED OBSOLETE
Product: gnome-session
Classification: Core
Component: gnome-session
2.26.x
Other All
: Normal enhancement
: ---
Assigned To: Session Maintainers
Session Maintainers
Depends on:
Blocks: 636680
 
 
Reported: 2009-03-18 21:26 UTC by Chris Coulson
Modified: 2012-11-21 20:33 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
dbus_shutdown_now.patch (3.61 KB, patch)
2009-03-18 21:39 UTC, Chris Coulson
none Details | Review
[PATCH] Provide D-Bus API for shutting down and rebooting the machine (5.20 KB, patch)
2012-05-08 15:23 UTC, Sascha Silbe
none Details | Review

Description Chris Coulson 2009-03-18 21:26:58 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.
Comment 1 Chris Coulson 2009-03-18 21:39:50 UTC
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.
Comment 2 Dan Winship 2010-12-07 09:02:00 UTC
Likewise, the shell needs a "suspend now" API (bug 636680)
Comment 3 Vincent Untz 2010-12-07 09:23:57 UTC
(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?
Comment 4 Dan Winship 2010-12-07 09:34:51 UTC
(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.
Comment 5 Dan Winship 2010-12-07 09:35:44 UTC
(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/
Comment 6 Vincent Untz 2010-12-07 09:56:46 UTC
(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.
Comment 7 Sascha Silbe 2011-07-30 07:17:48 UTC
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.
Comment 8 Sascha Silbe 2012-05-08 15:23:57 UTC
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.
Comment 9 Sascha Silbe 2012-05-08 15:30:18 UTC
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.
Comment 10 Ray Strode [halfline] 2012-05-08 15:57:28 UTC
Thanks for working on this.  See comment 3 for some comments Vincent made on the previous patch that are still applicable I think.
Comment 11 Sascha Silbe 2012-05-15 06:16:43 UTC
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.
Comment 12 Bastien Nocera 2012-11-21 20:33:55 UTC
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.