1 From b65cb6f48bfa768acafdb7b6dcee32f600925688 Mon Sep 17 00:00:00 2001
2 From: Eric Koegel <eric.koegel@gmail.com>
3 Date: Mon, 13 Oct 2014 10:00:22 +0300
4 Subject: [PATCH] More Suspend DBUS API work
6 We need a Can/Auth split for suspend/hibernate because the user
7 may be authorized but the system is unable to perform those
8 actions. Additionally start working the inhibit calls. We also
9 need to actually add the suspend/hibernate tools.
12 src/ck-manager.c | 46 ++++++++++-
13 src/ck-manager.h | 10 +++
14 src/ck-sysdeps-freebsd.c | 67 +++++++++++++++-
15 src/ck-sysdeps-gnu.c | 14 ++++
16 src/ck-sysdeps-linux.c | 37 +++++++++
17 src/ck-sysdeps-openbsd.c | 12 +++
18 src/ck-sysdeps-solaris.c | 14 ++++
19 src/ck-sysdeps.h | 3 +
20 src/org.freedesktop.ConsoleKit.Manager.xml | 122 +++++++++++++++++++++++++++++
21 10 files changed, 322 insertions(+), 6 deletions(-)
23 diff --git a/src/ck-manager.c b/src/ck-manager.c
24 index eff383c..6d80304 100644
25 --- a/src/ck-manager.c
26 +++ b/src/ck-manager.c
27 @@ -1355,8 +1355,8 @@ ck_manager_suspend (CkManager *manager,
31 -ck_manager_can_suspend (CkManager *manager,
32 - DBusGMethodInvocation *context)
33 +ck_manager_auth_suspend (CkManager *manager,
34 + DBusGMethodInvocation *context)
38 @@ -1377,6 +1377,20 @@ ck_manager_can_suspend (CkManager *manager,
43 +ck_manager_can_suspend (CkManager *manager,
44 + DBusGMethodInvocation *context)
47 + if (ck_system_can_suspend ()) {
48 + dbus_g_method_return (context, TRUE);
50 + dbus_g_method_return (context, FALSE);
57 do_hibernate (CkManager *manager,
58 DBusGMethodInvocation *context,
59 @@ -1442,8 +1456,8 @@ ck_manager_hibernate (CkManager *manager,
63 -ck_manager_can_hibernate (CkManager *manager,
64 - DBusGMethodInvocation *context)
65 +ck_manager_auth_hibernate (CkManager *manager,
66 + DBusGMethodInvocation *context)
70 @@ -1464,6 +1478,30 @@ ck_manager_can_hibernate (CkManager *manager,
75 +ck_manager_can_hibernate (CkManager *manager,
76 + DBusGMethodInvocation *context)
79 + if (ck_system_can_hibernate ()) {
80 + dbus_g_method_return (context, TRUE);
82 + dbus_g_method_return (context, FALSE);
89 +ck_manager_inhibit (CkManager *manager,
93 + DBusGMethodInvocation *context)
99 on_seat_active_session_changed_full (CkSeat *seat,
100 CkSession *old_session,
101 diff --git a/src/ck-manager.h b/src/ck-manager.h
102 index bfa2c01..d464056 100644
103 --- a/src/ck-manager.h
104 +++ b/src/ck-manager.h
105 @@ -97,6 +97,16 @@ gboolean ck_manager_can_suspend (CkManager *manage
106 DBusGMethodInvocation *context);
107 gboolean ck_manager_can_hibernate (CkManager *manager,
108 DBusGMethodInvocation *context);
109 +gboolean ck_manager_auth_suspend (CkManager *manager,
110 + DBusGMethodInvocation *context);
111 +gboolean ck_manager_auth_hibernate (CkManager *manager,
112 + DBusGMethodInvocation *context);
113 +gboolean ck_manager_inhibit (CkManager *manager,
117 + DBusGMethodInvocation *context);
119 /* Authoritative properties */
120 gboolean ck_manager_open_session (CkManager *manager,
121 DBusGMethodInvocation *context);
122 diff --git a/src/ck-sysdeps-solaris.c b/src/ck-sysdeps-solaris.c
123 index bb37e1e..63cb6e0 100644
124 --- a/src/ck-sysdeps-solaris.c
125 +++ b/src/ck-sysdeps-solaris.c
126 @@ -529,3 +529,17 @@ ck_get_active_console_num (int console_fd,
132 +ck_system_can_suspend (void)
134 + /* TODO: not implemented */
139 +ck_system_can_hibernate (void)
141 + /* TODO: not implemented */
144 diff --git a/src/ck-sysdeps.h b/src/ck-sysdeps.h
145 index 644d053..73c2608 100644
146 --- a/src/ck-sysdeps.h
147 +++ b/src/ck-sysdeps.h
152 +gboolean ck_system_can_suspend (void);
153 +gboolean ck_system_can_hibernate (void);
155 int ck_get_a_console_fd (void);
157 gboolean ck_fd_is_a_console (int fd);
158 diff --git a/src/org.freedesktop.ConsoleKit.Manager.xml b/src/org.freedesktop.ConsoleKit.Manager.xml
159 index ae6a90c..7070225 100644
160 --- a/src/org.freedesktop.ConsoleKit.Manager.xml
161 +++ b/src/org.freedesktop.ConsoleKit.Manager.xml
163 <method name="CanRestart">
164 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
165 <arg name="can_restart" type="b" direction="out"/>
168 + <doc:para>This method returns whether the user is authorized to restart the computer system.</doc:para>
175 <method name="CanStop">
176 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
177 <arg name="can_stop" type="b" direction="out"/>
180 + <doc:para>This method returns whether the user is authorized to shutdown the computer system.</doc:para>
185 <method name="Suspend">
187 <method name="CanSuspend">
188 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
189 <arg name="can_suspend" type="b" direction="out"/>
192 + <doc:para>This method returns whether the computer system is capable of suspending.</doc:para>
197 + <method name="AuthSuspend">
198 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
199 + <arg name="auth_suspend" type="b" direction="out"/>
202 + <doc:para>This method returns whether the user is authorized to suspend the computer system.</doc:para>
207 <method name="Hibernate">
209 <method name="CanHibernate">
210 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
211 <arg name="can_hibernate" type="b" direction="out"/>
214 + <doc:para>This method returns whether the computer system is capable of hibernating.</doc:para>
219 + <method name="AuthHibernate">
220 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
221 + <arg name="auth_hibernate" type="b" direction="out"/>
224 + <doc:para>This method returns whether the user is authorized to hibernate the computer system.</doc:para>
229 + <method name="Inhibit">
230 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
231 + <arg name="what" type="s" direction="in">
233 + <doc:summary>What is a colon-separated list of lock types. The list of lock types are: shutdown, sleep, idle, handle-power-key, handle-suspend-key, handle-hibernate-key. Example: "shutdown:idle"</doc:summary>
236 + <arg name="who" type="s" direction="in">
238 + <doc:summary>Who is a human-readable, descriptive string of who is taking the lock. Example: "Xfburn"</doc:summary>
241 + <arg name="why" type="s" direction="in">
243 + <doc:summary>Why is a human-readable, descriptive string of why the program is taking the lock. Example: "Burning a DVD, interrupting now will ruin the DVD."</doc:summary>
246 + <arg name="fd" type="h" direction="out">
249 + <doc:para>Returns a file descriptor that encapsulates the lock, or -1 on failure. As soon as the file descriptor is closed (and all its duplicates) the lock is automatically released. If the client dies while the lock is taken it is automatically closed and the lock is automatically released.</doc:para>
255 + <doc:para>See this simple example:
256 + <doc:example language="c" title="simple example"><doc:code>
257 + DBusConnection *bus_connection;
258 + DBusMessage *message = NULL, *reply = NULL;
261 + const char *what = "shutdown:sleep";
262 + const char *who = "Xfburn";
263 + const char *why = "Burning a DVD, interrupting now will ruin the DVD.";
265 + message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit",
266 + "/org/freedesktop/ConsoleKit/Manager",
267 + "org.freedesktop.ConsoleKit.Manager",
272 + g_warning ("Unable to call Inhibit()");
276 + if (!dbus_message_append_args (message,
277 + DBUS_TYPE_STRING, &what,
278 + DBUS_TYPE_STRING, &who,
279 + DBUS_TYPE_STRING, &why,
280 + DBUS_TYPE_INVALID))
282 + g_warning ("Unable to call Inhibit()");
283 + dbus_message_unref (message);
287 + reply = dbus_connection_send_with_reply_and_block (bus_connection, message, -1, &error);
290 + g_warning ("Unable to inhibit: %s", error.message);
291 + dbus_message_unref (message);
295 + if (!dbus_message_get_args (reply, &error,
296 + DBUS_TYPE_UNIX_FD, &fd,
297 + DBUS_TYPE_INVALID))
299 + g_warning ("Inhibit() reply parsing failed: %s", error.message);
302 + dbus_message_unref (message);
303 + dbus_message_unref (reply);
304 + dbus_error_free (&error);
306 + </doc:code></doc:example></doc:para>
311 <method name="OpenSession">