python/hypothesis: update to 6.121.0
[oi-userland.git] / components / library / ConsoleKit / patches / 22-suspend-hibernate-2.patch
blob8f58996909b888bcf26713feeda3840ac4d095fd
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.
10 ---
11 configure.ac | 3 +-
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,
30 gboolean
31 -ck_manager_can_suspend (CkManager *manager,
32 - DBusGMethodInvocation *context)
33 +ck_manager_auth_suspend (CkManager *manager,
34 + DBusGMethodInvocation *context)
37 const char *action;
38 @@ -1377,6 +1377,20 @@ ck_manager_can_suspend (CkManager *manager,
39 return TRUE;
42 +gboolean
43 +ck_manager_can_suspend (CkManager *manager,
44 + DBusGMethodInvocation *context)
47 + if (ck_system_can_suspend ()) {
48 + dbus_g_method_return (context, TRUE);
49 + } else {
50 + dbus_g_method_return (context, FALSE);
51 + }
53 + return TRUE;
56 static void
57 do_hibernate (CkManager *manager,
58 DBusGMethodInvocation *context,
59 @@ -1442,8 +1456,8 @@ ck_manager_hibernate (CkManager *manager,
62 gboolean
63 -ck_manager_can_hibernate (CkManager *manager,
64 - DBusGMethodInvocation *context)
65 +ck_manager_auth_hibernate (CkManager *manager,
66 + DBusGMethodInvocation *context)
69 const char *action;
70 @@ -1464,6 +1478,30 @@ ck_manager_can_hibernate (CkManager *manager,
71 return TRUE;
74 +gboolean
75 +ck_manager_can_hibernate (CkManager *manager,
76 + DBusGMethodInvocation *context)
79 + if (ck_system_can_hibernate ()) {
80 + dbus_g_method_return (context, TRUE);
81 + } else {
82 + dbus_g_method_return (context, FALSE);
83 + }
85 + return TRUE;
88 +gboolean
89 +ck_manager_inhibit (CkManager *manager,
90 + gchar *what,
91 + gchar *who,
92 + gchar *why,
93 + DBusGMethodInvocation *context)
95 + return TRUE;
98 static void
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,
114 + gchar *what,
115 + gchar *who,
116 + gchar *why,
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,
128 return ret;
131 +gboolean
132 +ck_system_can_suspend (void)
134 + /* TODO: not implemented */
135 + return FALSE;
138 +gboolean
139 +ck_system_can_hibernate (void)
141 + /* TODO: not implemented */
142 + return FALSE;
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
148 @@ -54,6 +54,9 @@
149 uid_t *uid,
150 GError **error);
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
162 @@ -16,6 +16,11 @@
163 <method name="CanRestart">
164 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
165 <arg name="can_restart" type="b" direction="out"/>
166 + <doc:doc>
167 + <doc:description>
168 + <doc:para>This method returns whether the user is authorized to restart the computer system.</doc:para>
169 + </doc:description>
170 + </doc:doc>
171 </method>
173 <method name="Stop">
174 @@ -30,6 +35,11 @@
175 <method name="CanStop">
176 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
177 <arg name="can_stop" type="b" direction="out"/>
178 + <doc:doc>
179 + <doc:description>
180 + <doc:para>This method returns whether the user is authorized to shutdown the computer system.</doc:para>
181 + </doc:description>
182 + </doc:doc>
183 </method>
185 <method name="Suspend">
186 @@ -44,6 +54,21 @@
187 <method name="CanSuspend">
188 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
189 <arg name="can_suspend" type="b" direction="out"/>
190 + <doc:doc>
191 + <doc:description>
192 + <doc:para>This method returns whether the computer system is capable of suspending.</doc:para>
193 + </doc:description>
194 + </doc:doc>
195 + </method>
197 + <method name="AuthSuspend">
198 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
199 + <arg name="auth_suspend" type="b" direction="out"/>
200 + <doc:doc>
201 + <doc:description>
202 + <doc:para>This method returns whether the user is authorized to suspend the computer system.</doc:para>
203 + </doc:description>
204 + </doc:doc>
205 </method>
207 <method name="Hibernate">
208 @@ -58,6 +83,103 @@
209 <method name="CanHibernate">
210 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
211 <arg name="can_hibernate" type="b" direction="out"/>
212 + <doc:doc>
213 + <doc:description>
214 + <doc:para>This method returns whether the computer system is capable of hibernating.</doc:para>
215 + </doc:description>
216 + </doc:doc>
217 + </method>
219 + <method name="AuthHibernate">
220 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
221 + <arg name="auth_hibernate" type="b" direction="out"/>
222 + <doc:doc>
223 + <doc:description>
224 + <doc:para>This method returns whether the user is authorized to hibernate the computer system.</doc:para>
225 + </doc:description>
226 + </doc:doc>
227 + </method>
229 + <method name="Inhibit">
230 + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
231 + <arg name="what" type="s" direction="in">
232 + <doc:doc>
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>
234 + </doc:doc>
235 + </arg>
236 + <arg name="who" type="s" direction="in">
237 + <doc:doc>
238 + <doc:summary>Who is a human-readable, descriptive string of who is taking the lock. Example: "Xfburn"</doc:summary>
239 + </doc:doc>
240 + </arg>
241 + <arg name="why" type="s" direction="in">
242 + <doc:doc>
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>
244 + </doc:doc>
245 + </arg>
246 + <arg name="fd" type="h" direction="out">
247 + <doc:doc>
248 + <doc:description>
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>
250 + </doc:description>
251 + </doc:doc>
252 + </arg>
253 + <doc:doc>
254 + <doc:description>
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;
259 + DBusError error;
260 + gint fd = -1;
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",
268 + "Inhibit");
270 + if (!message)
272 + g_warning ("Unable to call Inhibit()");
273 + return fd;
276 + if (!dbus_message_append_args (message,
277 + DBUS_TYPE_STRING, &amp;what,
278 + DBUS_TYPE_STRING, &amp;who,
279 + DBUS_TYPE_STRING, &amp;why,
280 + DBUS_TYPE_INVALID))
282 + g_warning ("Unable to call Inhibit()");
283 + dbus_message_unref (message);
284 + return fd;
287 + reply = dbus_connection_send_with_reply_and_block (bus_connection, message, -1, &amp;error);
288 + if (!reply)
290 + g_warning ("Unable to inhibit: %s", error.message);
291 + dbus_message_unref (message);
292 + return fd;
295 + if (!dbus_message_get_args (reply, &amp;error,
296 + DBUS_TYPE_UNIX_FD, &amp;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 (&amp;error);
305 + return fd;
306 + </doc:code></doc:example></doc:para>
307 + </doc:description>
308 + </doc:doc>
309 </method>
311 <method name="OpenSession">