GNOME Bugzilla – Bug 536915
Add dbus API to know if it's possible to shutdown
Last modified: 2009-01-15 15:32:28 UTC
Talked about this with Lucas on IRC, but I need to track the bug so I can remember to fix the panel side... The panel needs to know if shutdown/reboot is possible to know if it should display the menu item. Since the panel doesn't know about gdm anymore and gnome-session does this work now, we should probably add an API for this. Or maybe it makes sense to just tell people to use consolekit?
Stepping back for a moment, it sounds quite strange to ask gnome-session whether you can shutdown/restart the computer. Directly using consolekit seems to be the right way then. On the other hand, gnome-session has code to fallback to directly communication with gdm in case consolekit is not available which could be useful to reuse. This is about old GDM though so that doesn't really matter I guess.
(In reply to comment #1) > Stepping back for a moment, it sounds quite strange to ask gnome-session > whether you can shutdown/restart the computer. It's not really "can I shut down the computer", it's "if I call org.gnome.SessionManager.Shutdown(), is it going to work?", which is a reasonable thing to ask gnome-session. Eg, gnome-session won't let you initiate a shutdown until it has finished starting up the session, so it would return FALSE if you asked too soon, regardless of what ConsoleKit thought.
Yeah, makes sense. Added CanShutdown method to session manager D-Bus API. 2008-06-25 Lucas Rocha <lucasr@gnome.org> Provide a CanShutdown D-Bus method so that other apps (such as gnome-panel) are able to query session manager if it's a Shutdown D-Bus call is possible. #536915, Vincent Untz. * gnome-session/org.gnome.SessionManagement.xml, gnome-session/dbus.c (gsm_dbus_server_can_shutdown): added CanShutdown method to session manager D-Bus API. * gnome-session/logout.[ch] (gsm_logout_can_shutdown, gsm_logout_can_reboot): renamed logout-dialog.[ch] to logout.[ch] for consistency (and updated related files accordingly). Made gsm_logout_can_shutdown() and gsm_logout_can_reboot() public methods.
I don't see new D-Bus API for "CanShutdown" in version 2.23.92. At that same time,gnome-panel doesn't use any "CanShutdown" either.
Created attachment 120303 [details] [review] CanShutdown api I don't know what happened to the code Lucas wrote, but I just wrote this patch and built it into rawhide
Created attachment 120304 [details] [review] the corresponding panel patch I also built this patch into rawhide to use the api. A relevant downstream bug report is here: https://bugzilla.redhat.com/show_bug.cgi?id=444552
Created attachment 120335 [details] [review] Don't pass NULL for error variables to polkit functions This patch replaces attachment 120303 [details] [review] which had a bug where it was passing NULL to some functions where NULL wasn't allowed.
So I apparently didn't test this patch very well. The gsm_consolekit_can_do_action function is pretty broken. Marking needs-work.
Created attachment 120360 [details] [review] A better patch this one seems to work a lot better
Created attachment 120365 [details] [review] better patch yet! So after the first two false starts, I figured I better get some review on attachment 120360 [details] [review]. I asked davidz to take a look at the PolicyKit bits. David pointed out nicer apis to use, so I've rewritten the patch to take advantage of them.
Created attachment 120653 [details] [review] address race condition at startup Some rawhide users have reported the shutdown menu item disappearing with this patch. It looks like it's because of the manager->priv->phase != GSM_MANAGER_PHASE_RUNNING check (the panel is started in a phase before PHASE_RUNNING). That check was dubious to begin with, so i've removed it.
Should we get this committed now ? We are shipping this patch in F10, and it works...
Feel free to commit. My patch probably got lost after the dbus_based branch was replaced trunk.
commited. Vincent, okay with the panel patch?
Moving to gnome-panel for proper scrutiny.
Closing on request of vuntz.