Contents of /trunk/xfce4-session/patches/xfce4-session-4.10.0-systemd-v3.patch
Parent Directory | Revision Log
Revision 2022 -
(show annotations)
(download)
Wed Jan 9 09:43:07 2013 UTC (11 years, 8 months ago) by niro
File size: 14069 byte(s)
Wed Jan 9 09:43:07 2013 UTC (11 years, 8 months ago) by niro
File size: 14069 byte(s)
-fixed patch
1 | diff -Naur xfce4-session-4.10.0/configure.in xfce4-session-4.10.0-magellan/configure.in |
2 | --- xfce4-session-4.10.0/configure.in 2012-04-28 20:43:29.000000000 +0000 |
3 | +++ xfce4-session-4.10.0-magellan/configure.in 2013-01-09 11:44:52.749711440 +0000 |
4 | @@ -101,6 +101,10 @@ |
5 | XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.84]) |
6 | XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.9.0]) |
7 | |
8 | +dnl Check for polkit / systemd integration |
9 | +XDT_CHECK_OPTIONAL_PACKAGE([SYSTEMD], [polkit-gobject-1], [0.100], |
10 | + [systemd], [Systemd support (through polkit)]) |
11 | + |
12 | dnl Check for gnome support |
13 | XDT_CHECK_OPTIONAL_PACKAGE([GNOME_KEYRING], [gnome-keyring-1], [2.22], |
14 | [libgnome-keyring], |
15 | diff -Naur xfce4-session-4.10.0/xfce4-session/Makefile.am xfce4-session-4.10.0-magellan/xfce4-session/Makefile.am |
16 | --- xfce4-session-4.10.0/xfce4-session/Makefile.am 2012-04-28 20:43:27.000000000 +0000 |
17 | +++ xfce4-session-4.10.0-magellan/xfce4-session/Makefile.am 2013-01-09 11:47:27.895720098 +0000 |
18 | @@ -38,8 +38,6 @@ |
19 | xfsm-compat-gnome.h \ |
20 | xfsm-compat-kde.c \ |
21 | xfsm-compat-kde.h \ |
22 | - xfsm-consolekit.c \ |
23 | - xfsm-consolekit.h \ |
24 | xfsm-dns.c \ |
25 | xfsm-dns.h \ |
26 | xfsm-error.c \ |
27 | @@ -65,6 +63,16 @@ |
28 | xfsm-upower.c \ |
29 | xfsm-upower.h |
30 | |
31 | +if HAVE_SYSTEMD |
32 | +xfce4_session_SOURCES += \ |
33 | + xfsm-systemd.c \ |
34 | + xfsm-systemd.h |
35 | +else |
36 | +xfce4_session_SOURCES += \ |
37 | + xfsm-consolekit.c \ |
38 | + xfsm-consolekit.h |
39 | +endif |
40 | + |
41 | xfce4_session_CFLAGS = \ |
42 | $(GNOME_KEYRING_CFLAGS) \ |
43 | $(LIBSM_CFLAGS) \ |
44 | @@ -73,6 +81,7 @@ |
45 | $(DBUS_CFLAGS) \ |
46 | $(DBUS_GLIB_CFLAGS) \ |
47 | $(LIBWNCK_CFLAGS) \ |
48 | + $(SYSTEMD_CFLAGS) \ |
49 | $(XFCONF_CFLAGS) \ |
50 | $(GMODULE_CFLAGS) \ |
51 | $(PLATFORM_CFLAGS) |
52 | @@ -92,6 +101,7 @@ |
53 | $(DBUS_LIBS) \ |
54 | $(DBUS_GLIB_LIBS) \ |
55 | $(LIBWNCK_LIBS) \ |
56 | + $(SYSTEMD_LIBS) \ |
57 | $(XFCONF_LIBS) \ |
58 | $(GNOME_KEYRING_LIBS) \ |
59 | -lm |
60 | diff -Naur xfce4-session-4.10.0/xfce4-session/xfsm-shutdown.c xfce4-session-4.10.0-magellan/xfce4-session/xfsm-shutdown.c |
61 | --- xfce4-session-4.10.0/xfce4-session/xfsm-shutdown.c 2012-04-28 20:43:27.000000000 +0000 |
62 | +++ xfce4-session-4.10.0-magellan/xfce4-session/xfsm-shutdown.c 2013-01-09 11:51:43.085733211 +0000 |
63 | @@ -66,10 +66,13 @@ |
64 | #include <xfce4-session/xfsm-fadeout.h> |
65 | #include <xfce4-session/xfsm-global.h> |
66 | #include <xfce4-session/xfsm-legacy.h> |
67 | -#include <xfce4-session/xfsm-consolekit.h> |
68 | #include <xfce4-session/xfsm-upower.h> |
69 | |
70 | - |
71 | +#ifdef HAVE_SYSTEMD |
72 | +#include <xfce4-session/xfsm-systemd.h> |
73 | +#else |
74 | +#include <xfce4-session/xfsm-consolekit.h> |
75 | +#endif |
76 | |
77 | static void xfsm_shutdown_finalize (GObject *object); |
78 | static void xfsm_shutdown_sudo_free (XfsmShutdown *shutdown); |
79 | @@ -93,7 +96,11 @@ |
80 | { |
81 | GObject __parent__; |
82 | |
83 | +#ifdef HAVE_SYSTEMD |
84 | + XfsmSystemd *systemd; |
85 | +#else |
86 | XfsmConsolekit *consolekit; |
87 | +#endif |
88 | XfsmUPower *upower; |
89 | |
90 | /* kiosk settings */ |
91 | @@ -131,7 +138,11 @@ |
92 | { |
93 | XfceKiosk *kiosk; |
94 | |
95 | +#ifdef HAVE_SYSTEMD |
96 | + shutdown->systemd = xfsm_systemd_get (); |
97 | +#else |
98 | shutdown->consolekit = xfsm_consolekit_get (); |
99 | +#endif |
100 | shutdown->upower = xfsm_upower_get (); |
101 | shutdown->helper_state = SUDO_NOT_INITIAZED; |
102 | shutdown->helper_require_password = FALSE; |
103 | @@ -150,7 +161,11 @@ |
104 | { |
105 | XfsmShutdown *shutdown = XFSM_SHUTDOWN (object); |
106 | |
107 | +#ifdef HAVE_SYSTEMD |
108 | + g_object_unref (G_OBJECT (shutdown->systemd)); |
109 | +#else |
110 | g_object_unref (G_OBJECT (shutdown->consolekit)); |
111 | +#endif |
112 | g_object_unref (G_OBJECT (shutdown->upower)); |
113 | |
114 | /* close down helper */ |
115 | @@ -641,7 +656,11 @@ |
116 | if (shutdown->helper_state == SUDO_AVAILABLE) |
117 | return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_RESTART, error); |
118 | else |
119 | +#ifdef HAVE_SYSTEMD |
120 | + return xfsm_systemd_try_restart (shutdown->systemd, error); |
121 | +#else |
122 | return xfsm_consolekit_try_restart (shutdown->consolekit, error); |
123 | +#endif |
124 | } |
125 | |
126 | |
127 | @@ -658,7 +677,11 @@ |
128 | if (shutdown->helper_state == SUDO_AVAILABLE) |
129 | return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_SHUTDOWN, error); |
130 | else |
131 | +#ifdef HAVE_SYSTEMD |
132 | + return xfsm_systemd_try_shutdown (shutdown->systemd, error); |
133 | +#else |
134 | return xfsm_consolekit_try_shutdown (shutdown->consolekit, error); |
135 | +#endif |
136 | } |
137 | |
138 | |
139 | @@ -698,7 +721,11 @@ |
140 | return TRUE; |
141 | } |
142 | |
143 | +#ifdef HAVE_SYSTEMD |
144 | + if (xfsm_systemd_can_restart (shutdown->systemd, can_restart, error)) |
145 | +#else |
146 | if (xfsm_consolekit_can_restart (shutdown->consolekit, can_restart, error)) |
147 | +#endif |
148 | return TRUE; |
149 | |
150 | if (xfsm_shutdown_sudo_init (shutdown, error)) |
151 | @@ -725,7 +752,11 @@ |
152 | return TRUE; |
153 | } |
154 | |
155 | +#ifdef HAVE_SYSTEMD |
156 | + if (xfsm_systemd_can_shutdown (shutdown->systemd, can_shutdown, error)) |
157 | +#else |
158 | if (xfsm_consolekit_can_shutdown (shutdown->consolekit, can_shutdown, error)) |
159 | +#endif |
160 | return TRUE; |
161 | |
162 | if (xfsm_shutdown_sudo_init (shutdown, error)) |
163 | diff -Naur xfce4-session-4.10.0/xfce4-session/xfsm-systemd.c xfce4-session-4.10.0-magellan/xfce4-session/xfsm-systemd.c |
164 | --- xfce4-session-4.10.0/xfce4-session/xfsm-systemd.c 1970-01-01 00:00:00.000000000 +0000 |
165 | +++ xfce4-session-4.10.0-magellan/xfce4-session/xfsm-systemd.c 2013-01-09 11:53:36.296738282 +0000 |
166 | @@ -0,0 +1,229 @@ |
167 | +/*- |
168 | + * Copyright (C) 2012 Christian Hesse |
169 | + * |
170 | + * This program is free software; you can redistribute it and/or modify |
171 | + * it under the terms of the GNU General Public License as published by |
172 | + * the Free Software Foundation; either version 2, or (at your option) |
173 | + * any later version. |
174 | + * |
175 | + * This program is distributed in the hope that it will be useful, |
176 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
177 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
178 | + * GNU General Public License for more details. |
179 | + * |
180 | + * You should have received a copy of the GNU General Public License |
181 | + * along with this program; if not, write to the Free Software |
182 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
183 | + * MA 02110-1301 USA. |
184 | + */ |
185 | + |
186 | +#include <config.h> |
187 | + |
188 | +#include <gio/gio.h> |
189 | +#include <polkit/polkit.h> |
190 | +#include <dbus/dbus-glib.h> |
191 | +#include <dbus/dbus-glib-lowlevel.h> |
192 | + |
193 | +#include <xfce4-session/xfsm-systemd.h> |
194 | + |
195 | + |
196 | + |
197 | +#define SYSTEMD_DBUS_NAME "org.freedesktop.login1" |
198 | +#define SYSTEMD_DBUS_PATH "/org/freedesktop/login1" |
199 | +#define SYSTEMD_DBUS_INTERFACE "org.freedesktop.login1.Manager" |
200 | +#define SYSTEMD_REBOOT_ACTION "Reboot" |
201 | +#define SYSTEMD_POWEROFF_ACTION "PowerOff" |
202 | +#define SYSTEMD_REBOOT_TEST "org.freedesktop.login1.reboot" |
203 | +#define SYSTEMD_POWEROFF_TEST "org.freedesktop.login1.power-off" |
204 | + |
205 | + |
206 | + |
207 | +static void xfsm_systemd_finalize (GObject *object); |
208 | + |
209 | + |
210 | + |
211 | +struct _XfsmSystemdClass |
212 | +{ |
213 | + GObjectClass __parent__; |
214 | +}; |
215 | + |
216 | +struct _XfsmSystemd |
217 | +{ |
218 | + GObject __parent__; |
219 | + |
220 | + PolkitAuthority *authority; |
221 | + PolkitSubject *subject; |
222 | +}; |
223 | + |
224 | + |
225 | + |
226 | +G_DEFINE_TYPE (XfsmSystemd, xfsm_systemd, G_TYPE_OBJECT) |
227 | + |
228 | + |
229 | + |
230 | +static void |
231 | +xfsm_systemd_class_init (XfsmSystemdClass *klass) |
232 | +{ |
233 | + GObjectClass *gobject_class; |
234 | + |
235 | + gobject_class = G_OBJECT_CLASS (klass); |
236 | + gobject_class->finalize = xfsm_systemd_finalize; |
237 | +} |
238 | + |
239 | + |
240 | + |
241 | +static void |
242 | +xfsm_systemd_init (XfsmSystemd *systemd) |
243 | +{ |
244 | + systemd->authority = polkit_authority_get_sync (NULL, NULL); |
245 | + systemd->subject = polkit_unix_process_new (getpid()); |
246 | +} |
247 | + |
248 | + |
249 | + |
250 | +static void |
251 | +xfsm_systemd_finalize (GObject *object) |
252 | +{ |
253 | + XfsmSystemd *systemd = XFSM_SYSTEMD (object); |
254 | + |
255 | + g_object_unref (G_OBJECT (systemd->authority)); |
256 | + g_object_unref (G_OBJECT (systemd->subject)); |
257 | + |
258 | + (*G_OBJECT_CLASS (xfsm_systemd_parent_class)->finalize) (object); |
259 | +} |
260 | + |
261 | + |
262 | +static gboolean |
263 | +xfsm_systemd_can_method (XfsmSystemd *systemd, |
264 | + gboolean *can_method, |
265 | + const gchar *method, |
266 | + GError **error) |
267 | +{ |
268 | + PolkitAuthorizationResult *res; |
269 | + GError *local_error = NULL; |
270 | + |
271 | + *can_method = FALSE; |
272 | + |
273 | + res = polkit_authority_check_authorization_sync (systemd->authority, |
274 | + systemd->subject, |
275 | + method, |
276 | + NULL, |
277 | + POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE, |
278 | + NULL, |
279 | + &local_error); |
280 | + |
281 | + if (res == NULL) |
282 | + { |
283 | + g_propagate_error (error, local_error); |
284 | + return FALSE; |
285 | + } |
286 | + |
287 | + *can_method = polkit_authorization_result_get_is_authorized (res) |
288 | + || polkit_authorization_result_get_is_challenge (res); |
289 | + |
290 | + g_object_unref (G_OBJECT (res)); |
291 | + |
292 | + return TRUE; |
293 | +} |
294 | + |
295 | + |
296 | + |
297 | +static gboolean |
298 | +xfsm_systemd_try_method (XfsmSystemd *systemd, |
299 | + const gchar *method, |
300 | + GError **error) |
301 | +{ |
302 | + GDBusConnection *bus; |
303 | + GError *local_error = NULL; |
304 | + |
305 | + bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); |
306 | + if (G_UNLIKELY (bus == NULL)) |
307 | + return FALSE; |
308 | + |
309 | + g_dbus_connection_call_sync (bus, |
310 | + SYSTEMD_DBUS_NAME, |
311 | + SYSTEMD_DBUS_PATH, |
312 | + SYSTEMD_DBUS_INTERFACE, |
313 | + method, |
314 | + g_variant_new ("(b)", TRUE), |
315 | + NULL, 0, G_MAXINT, NULL, |
316 | + &local_error); |
317 | + |
318 | + g_object_unref (G_OBJECT (bus)); |
319 | + |
320 | + if (local_error != NULL) |
321 | + { |
322 | + g_propagate_error (error, local_error); |
323 | + return FALSE; |
324 | + } |
325 | + |
326 | + return TRUE; |
327 | +} |
328 | + |
329 | + |
330 | + |
331 | +XfsmSystemd * |
332 | +xfsm_systemd_get (void) |
333 | +{ |
334 | + static XfsmSystemd *object = NULL; |
335 | + |
336 | + if (G_LIKELY (object != NULL)) |
337 | + { |
338 | + g_object_ref (G_OBJECT (object)); |
339 | + } |
340 | + else |
341 | + { |
342 | + object = g_object_new (XFSM_TYPE_SYSTEMD, NULL); |
343 | + g_object_add_weak_pointer (G_OBJECT (object), (gpointer) &object); |
344 | + } |
345 | + |
346 | + return object; |
347 | +} |
348 | + |
349 | + |
350 | + |
351 | +gboolean |
352 | +xfsm_systemd_try_restart (XfsmSystemd *systemd, |
353 | + GError **error) |
354 | +{ |
355 | + return xfsm_systemd_try_method (systemd, |
356 | + SYSTEMD_REBOOT_ACTION, |
357 | + error); |
358 | +} |
359 | + |
360 | + |
361 | + |
362 | +gboolean |
363 | +xfsm_systemd_try_shutdown (XfsmSystemd *systemd, |
364 | + GError **error) |
365 | +{ |
366 | + return xfsm_systemd_try_method (systemd, |
367 | + SYSTEMD_POWEROFF_ACTION, |
368 | + error); |
369 | +} |
370 | + |
371 | + |
372 | + |
373 | +gboolean |
374 | +xfsm_systemd_can_restart (XfsmSystemd *systemd, |
375 | + gboolean *can_restart, |
376 | + GError **error) |
377 | +{ |
378 | + return xfsm_systemd_can_method (systemd, |
379 | + can_restart, |
380 | + SYSTEMD_REBOOT_TEST, |
381 | + error); |
382 | +} |
383 | + |
384 | + |
385 | + |
386 | +gboolean |
387 | +xfsm_systemd_can_shutdown (XfsmSystemd *systemd, |
388 | + gboolean *can_shutdown, |
389 | + GError **error) |
390 | +{ |
391 | + return xfsm_systemd_can_method (systemd, |
392 | + can_shutdown, |
393 | + SYSTEMD_POWEROFF_TEST, |
394 | + error); |
395 | +} |
396 | diff -Naur xfce4-session-4.10.0/xfce4-session/xfsm-systemd.h xfce4-session-4.10.0-magellan/xfce4-session/xfsm-systemd.h |
397 | --- xfce4-session-4.10.0/xfce4-session/xfsm-systemd.h 1970-01-01 00:00:00.000000000 +0000 |
398 | +++ xfce4-session-4.10.0-magellan/xfce4-session/xfsm-systemd.h 2013-01-09 11:53:36.296738282 +0000 |
399 | @@ -0,0 +1,55 @@ |
400 | +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
401 | + * |
402 | + * Copyright (C) 2012 Christian Hesse |
403 | + * |
404 | + * Licensed under the GNU General Public License Version 2 |
405 | + * |
406 | + * This program is free software; you can redistribute it and/or modify |
407 | + * it under the terms of the GNU General Public License as published by |
408 | + * the Free Software Foundation; either version 2 of the License, or |
409 | + * (at your option) any later version. |
410 | + * |
411 | + * This program is distributed in the hope that it will be useful, |
412 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
413 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
414 | + * GNU General Public License for more details. |
415 | + * |
416 | + * You should have received a copy of the GNU General Public License |
417 | + * along with this program; if not, write to the Free Software |
418 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
419 | + */ |
420 | + |
421 | +#ifndef __XFSM_SYSTEMD_H__ |
422 | +#define __XFSM_SYSTEMD_H__ |
423 | + |
424 | +typedef struct _XfsmSystemdClass XfsmSystemdClass; |
425 | +typedef struct _XfsmSystemd XfsmSystemd; |
426 | + |
427 | +#define XFSM_TYPE_SYSTEMD (xfsm_systemd_get_type ()) |
428 | +#define XFSM_SYSTEMD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFSM_TYPE_SYSTEMD, XfsmSystemd)) |
429 | +#define XFSM_SYSTEMD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFSM_TYPE_SYSTEMD, XfsmSystemdClass)) |
430 | +#define XFSM_IS_SYSTEMD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFSM_TYPE_SYSTEMD)) |
431 | +#define XFSM_IS_SYSTEMD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFSM_TYPE_SYSTEMD)) |
432 | +#define XFSM_SYSTEMD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFSM_TYPE_SYSTEMD, XfsmSystemdClass)) |
433 | + |
434 | +GType xfsm_systemd_get_type (void) G_GNUC_CONST; |
435 | + |
436 | +XfsmSystemd *xfsm_systemd_get (void); |
437 | + |
438 | +gboolean xfsm_systemd_try_restart (XfsmSystemd *systemd, |
439 | + GError **error); |
440 | + |
441 | +gboolean xfsm_systemd_try_shutdown (XfsmSystemd *systemd, |
442 | + GError **error); |
443 | + |
444 | +gboolean xfsm_systemd_can_restart (XfsmSystemd *systemd, |
445 | + gboolean *can_restart, |
446 | + GError **error); |
447 | + |
448 | +gboolean xfsm_systemd_can_shutdown (XfsmSystemd *systemd, |
449 | + gboolean *can_shutdown, |
450 | + GError **error); |
451 | + |
452 | +G_END_DECLS |
453 | + |
454 | +#endif /* __XFSM_SYSTEMD_H__ */ |