Magellan Linux

Annotation of /trunk/xfce4-session/patches/xfce4-session-4.10.0-systemd-v3.patch

Parent Directory Parent Directory | Revision Log Revision Log


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