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 536915 - Add dbus API to know if it's possible to shutdown
Add dbus API to know if it's possible to shutdown
Status: RESOLVED FIXED
Product: gnome-panel
Classification: Other
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Panel Maintainers
Panel Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-06-06 00:29 UTC by Vincent Untz
Modified: 2009-01-15 15:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
CanShutdown api (8.97 KB, patch)
2008-10-09 19:56 UTC, Ray Strode [halfline]
none Details | Review
the corresponding panel patch (2.90 KB, patch)
2008-10-09 19:58 UTC, Ray Strode [halfline]
none Details | Review
Don't pass NULL for error variables to polkit functions (9.92 KB, patch)
2008-10-10 13:36 UTC, Ray Strode [halfline]
needs-work Details | Review
A better patch (8.54 KB, patch)
2008-10-10 20:54 UTC, Ray Strode [halfline]
none Details | Review
better patch yet! (7.17 KB, patch)
2008-10-10 21:53 UTC, Ray Strode [halfline]
none Details | Review
address race condition at startup (7.03 KB, patch)
2008-10-15 15:43 UTC, Ray Strode [halfline]
committed Details | Review

Description Vincent Untz 2008-06-06 00:29:10 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?
Comment 1 Lucas Rocha 2008-06-12 23:23:34 UTC
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. 
Comment 2 Dan Winship 2008-06-13 13:02:32 UTC
(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.
Comment 3 Lucas Rocha 2008-06-25 18:03:52 UTC
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.
Comment 4 Xiurong Simon Zheng 2008-09-19 16:28:05 UTC
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.
Comment 5 Ray Strode [halfline] 2008-10-09 19:56:44 UTC
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
Comment 6 Ray Strode [halfline] 2008-10-09 19:58:39 UTC
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
Comment 7 Ray Strode [halfline] 2008-10-10 13:36:55 UTC
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.
Comment 8 Ray Strode [halfline] 2008-10-10 20:24:52 UTC
So I apparently didn't test this patch very well. The gsm_consolekit_can_do_action function is pretty broken.  Marking needs-work.
Comment 9 Ray Strode [halfline] 2008-10-10 20:54:27 UTC
Created attachment 120360 [details] [review]
A better patch

this one seems to work a lot better
Comment 10 Ray Strode [halfline] 2008-10-10 21:53:15 UTC
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.
Comment 11 Ray Strode [halfline] 2008-10-15 15:43:23 UTC
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.
Comment 12 Matthias Clasen 2008-11-08 03:06:30 UTC
Should we get this committed now ? 
We are shipping this patch in F10, and it works...
Comment 13 Lucas Rocha 2008-11-11 12:15:31 UTC
Feel free to commit. My patch probably got lost after the dbus_based branch was replaced trunk.
Comment 14 Ray Strode [halfline] 2008-11-11 15:38:44 UTC
commited.  Vincent, okay with the panel patch?
Comment 15 Matthias Clasen 2009-01-15 15:25:34 UTC
Moving to gnome-panel for proper scrutiny.
Comment 16 Matthias Clasen 2009-01-15 15:32:28 UTC
Closing on request of vuntz.