]> git.pld-linux.org Git - packages/xfce4-session.git/blob - xfce4-session-add-systemd-support.patch
75eb6c08635c52ca6166849f9f23c99778e5b14e
[packages/xfce4-session.git] / xfce4-session-add-systemd-support.patch
1 diff -up xfce4-session-4.10.0/configure.in.systemd xfce4-session-4.10.0/configure.in
2 --- xfce4-session-4.10.0/configure.in.systemd   2012-04-28 15:43:29.000000000 -0500
3 +++ xfce4-session-4.10.0/configure.in   2013-03-29 14:29:28.468230742 -0500
4 @@ -101,6 +101,33 @@ XDT_CHECK_PACKAGE([DBUS], [dbus-1], [1.1
5  XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.84])
6  XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.9.0])
7  
8 +dnl systemd integration
9 +AC_ARG_ENABLE([systemd],
10 +              AS_HELP_STRING([--enable-systemd], [Use systemd]),
11 +              [with_systemd=$enableval],
12 +              [with_systemd=auto])
13 +PKG_CHECK_MODULES(SYSTEMD,
14 +                  [libsystemd-daemon libsystemd-login polkit-gobject-1],
15 +                  [have_systemd=yes], [have_systemd=no])
16 +AC_MSG_CHECKING([whether to use systemd])
17 +if test x$with_systemd = xauto ; then
18 +        if test x$have_systemd = xno ; then
19 +                with_systemd=no
20 +        else
21 +                with_systemd=yes
22 +        fi
23 +fi
24 +AC_MSG_RESULT($with_systemd)
25 +if test x$with_systemd = xyes; then
26 +        if test x$have_systemd = xno; then
27 +                AC_MSG_ERROR([Systemd support explicitly required, but systemd not found])
28 +        fi
29 +        AC_DEFINE(HAVE_SYSTEMD, 1, [Define if systemd is used for session tracking])
30 +fi
31 +AC_SUBST(SYSTEMD_CFLAGS)
32 +AC_SUBST(SYSTEMD_LIBS)
33 +AM_CONDITIONAL(WITH_SYSTEMD, [test "$with_systemd" = "yes"], [Using systemd])
34 +
35  dnl Check for gnome support
36  XDT_CHECK_OPTIONAL_PACKAGE([GNOME_KEYRING], [gnome-keyring-1], [2.22],
37                             [libgnome-keyring],
38 diff -up xfce4-session-4.10.0/xfce4-session/Makefile.am.systemd xfce4-session-4.10.0/xfce4-session/Makefile.am
39 --- xfce4-session-4.10.0/xfce4-session/Makefile.am.systemd      2012-04-28 15:43:27.000000000 -0500
40 +++ xfce4-session-4.10.0/xfce4-session/Makefile.am      2013-03-29 14:29:28.468230742 -0500
41 @@ -65,6 +63,12 @@ xfce4_session_SOURCES =                                                      \
42         xfsm-upower.c                                                   \
43         xfsm-upower.h
44  
45 +if WITH_SYSTEMD
46 +xfce4_session_SOURCES +=                                               \
47 +       xfsm-systemd.c                                                  \
48 +       xfsm-systemd.h
49 +endif
50 +
51  xfce4_session_CFLAGS =                                                 \
52         $(GNOME_KEYRING_CFLAGS)                                         \
53         $(LIBSM_CFLAGS)                                                 \
54 @@ -73,6 +81,7 @@ xfce4_session_CFLAGS =                                                        \
55         $(DBUS_CFLAGS)                                                  \
56         $(DBUS_GLIB_CFLAGS)                                             \
57         $(LIBWNCK_CFLAGS)                                               \
58 +       $(SYSTEMD_CFLAGS)                                               \
59         $(XFCONF_CFLAGS)                                                \
60         $(GMODULE_CFLAGS)                                               \
61         $(PLATFORM_CFLAGS)
62 @@ -92,6 +101,7 @@ xfce4_session_LDADD =                                                        \
63         $(DBUS_LIBS)                                                    \
64         $(DBUS_GLIB_LIBS)                                               \
65         $(LIBWNCK_LIBS)                                                 \
66 +       $(SYSTEMD_LIBS)                                                 \
67         $(XFCONF_LIBS)                                                  \
68         $(GNOME_KEYRING_LIBS)                                           \
69         -lm
70 diff -up xfce4-session-4.10.0/xfce4-session/xfsm-shutdown.c.systemd xfce4-session-4.10.0/xfce4-session/xfsm-shutdown.c
71 --- xfce4-session-4.10.0/xfce4-session/xfsm-shutdown.c.systemd  2012-04-28 15:43:27.000000000 -0500
72 +++ xfce4-session-4.10.0/xfce4-session/xfsm-shutdown.c  2013-03-29 14:34:40.377331342 -0500
73 @@ -66,7 +66,10 @@
74  #include <xfce4-session/xfsm-consolekit.h>
75  #include <xfce4-session/xfsm-upower.h>
76  
77 -
78 +#ifdef HAVE_SYSTEMD
79 +#include <systemd/sd-daemon.h>
80 +#include <xfce4-session/xfsm-systemd.h>
81 +#endif
82  
83  static void xfsm_shutdown_finalize  (GObject      *object);
84  static void xfsm_shutdown_sudo_free (XfsmShutdown *shutdown);
85 @@ -93,6 +96,9 @@ struct _XfsmShutdown
86    GObject __parent__;
87  
88    XfsmConsolekit *consolekit;
89 +#ifdef HAVE_SYSTEMD
90 +  SystemdProxy   *systemd_proxy;
91 +#endif
92    XfsmUPower     *upower;
93  
94    /* kiosk settings */
95 @@ -130,6 +137,12 @@ xfsm_shutdown_init (XfsmShutdown *shutdown)
96  {
97    XfceKiosk *kiosk;
98  
99 +#ifdef HAVE_SYSTEMD
100 +  shutdown->systemd_proxy = NULL;
101 +  if (sd_booted() > 0)
102 +    shutdown->systemd_proxy = systemd_proxy_new ();
103 +  else
104 +#endif
105    shutdown->consolekit = xfsm_consolekit_get ();
106    shutdown->upower = xfsm_upower_get ();
107    shutdown->helper_state = SUDO_NOT_INITIAZED;
108 @@ -150,6 +160,11 @@ xfsm_shutdown_finalize (GObject *object)
109  {
110    XfsmShutdown *shutdown = XFSM_SHUTDOWN (object);
111  
112 +#ifdef HAVE_SYSTEMD
113 +  if (shutdown->systemd_proxy)
114 +    systemd_proxy_free (shutdown->systemd_proxy);
115 +  else
116 +#endif
117    g_object_unref (G_OBJECT (shutdown->consolekit));
118    g_object_unref (G_OBJECT (shutdown->upower));
119  
120 @@ -641,6 +655,11 @@ xfsm_shutdown_try_restart (XfsmShutdown
121    if (shutdown->helper_state == SUDO_AVAILABLE)
122      return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_RESTART, error);
123    else
124 +#ifdef HAVE_SYSTEMD
125 +    if (shutdown->systemd_proxy)
126 +      return systemd_proxy_restart (shutdown->systemd_proxy, error);
127 +    else
128 +#endif
129      return xfsm_consolekit_try_restart (shutdown->consolekit, error);
130  }
131  
132 @@ -658,6 +676,11 @@ xfsm_shutdown_try_shutdown (XfsmShutdown
133    if (shutdown->helper_state == SUDO_AVAILABLE)
134      return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_SHUTDOWN, error);
135    else
136 +#ifdef HAVE_SYSTEMD
137 +    if (shutdown->systemd_proxy)
138 +      return systemd_proxy_shutdown (shutdown->systemd_proxy, error);
139 +    else
140 +#endif
141      return xfsm_consolekit_try_shutdown (shutdown->consolekit, error);
142  }
143  
144 @@ -669,6 +691,11 @@ xfsm_shutdown_try_suspend (XfsmShutdown
145  {
146    g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
147  
148 +#ifdef HAVE_SYSTEMD
149 +  if (shutdown->systemd_proxy)
150 +    return systemd_proxy_suspend (shutdown->systemd_proxy, error);
151 +  else
152 +#endif
153    return xfsm_upower_try_suspend (shutdown->upower, error);
154  }
155  
156 @@ -680,6 +706,11 @@ xfsm_shutdown_try_hibernate (XfsmShutdow
157  {
158    g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
159  
160 +#ifdef HAVE_SYSTEMD
161 +  if (shutdown->systemd_proxy)
162 +    return systemd_proxy_hibernate (shutdown->systemd_proxy, error);
163 +  else
164 +#endif
165    return xfsm_upower_try_hibernate (shutdown->upower, error);
166  }
167  
168 @@ -697,6 +727,12 @@ xfsm_shutdown_can_restart (XfsmShutdown
169        return TRUE;
170      }
171  
172 +#ifdef HAVE_SYSTEMD
173 +  if (shutdown->systemd_proxy) {
174 +    if (systemd_proxy_can_restart (shutdown->systemd_proxy, can_restart, error))
175 +      return TRUE;
176 +  } else
177 +#endif
178    if (xfsm_consolekit_can_restart (shutdown->consolekit, can_restart, error))
179      return TRUE;
180  
181 @@ -724,6 +757,12 @@ xfsm_shutdown_can_shutdown (XfsmShutdown
182        return TRUE;
183      }
184  
185 +#ifdef HAVE_SYSTEMD
186 +  if (shutdown->systemd_proxy) {
187 +    if (systemd_proxy_can_shutdown (shutdown->systemd_proxy, can_shutdown, error))
188 +      return TRUE;
189 +  } else
190 +#endif
191    if (xfsm_consolekit_can_shutdown (shutdown->consolekit, can_shutdown, error))
192      return TRUE;
193  
194 diff -up xfce4-session-4.10.0/xfce4-session/xfsm-systemd.c.systemd xfce4-session-4.10.0/xfce4-session/xfsm-systemd.c
195 --- xfce4-session-4.10.0/xfce4-session/xfsm-systemd.c.systemd   2013-03-29 14:29:28.469230730 -0500
196 +++ xfce4-session-4.10.0/xfce4-session/xfsm-systemd.c   2013-03-29 14:39:52.551428628 -0500
197 @@ -0,0 +1,146 @@
198 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
199 + *
200 + * Copyright (C) 2012 Christian Hesse
201 + *
202 + * Licensed under the GNU General Public License Version 2
203 + *
204 + * This program is free software; you can redistribute it and/or modify
205 + * it under the terms of the GNU General Public License as published by
206 + * the Free Software Foundation; either version 2 of the License, or
207 + * (at your option) any later version.
208 + *
209 + * This program is distributed in the hope that it will be useful,
210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
212 + * GNU General Public License for more details.
213 + *
214 + * You should have received a copy of the GNU General Public License
215 + * along with this program; if not, write to the Free Software
216 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
217 + */
218 +
219 +#include <config.h>
220 +
221 +#include <gio/gio.h>
222 +#include <polkit/polkit.h>
223 +
224 +#include "xfsm-systemd.h"
225 +
226 +#define SYSTEMD_DBUS_NAME       "org.freedesktop.login1"
227 +#define SYSTEMD_DBUS_PATH       "/org/freedesktop/login1"
228 +#define SYSTEMD_DBUS_INTERFACE  "org.freedesktop.login1.Manager"
229 +#define SYSTEMD_REBOOT_ACTION   "org.freedesktop.login1.reboot"
230 +#define SYSTEMD_SHUTDOWN_ACTION "org.freedesktop.login1.power-off"
231 +#define SYSTEMD_SUSPEND_ACTION  "org.freedesktop.login1.suspend"
232 +#define SYSTEMD_HIBERNATE_ACTION "org.freedesktop.login1.hibernate"
233 +
234 +struct _SystemdProxy {
235 +        PolkitAuthority *authority;
236 +        PolkitSubject *subject;
237 +};
238 +
239 +SystemdProxy *
240 +systemd_proxy_new (void)
241 +{
242 +        SystemdProxy *proxy;
243 +
244 +        proxy = g_new0 (SystemdProxy, 1);
245 +
246 +        proxy->authority = polkit_authority_get_sync (NULL, NULL);
247 +        proxy->subject = polkit_unix_process_new (getpid());
248 +
249 +        return proxy;
250 +}
251 +
252 +void
253 +systemd_proxy_free (SystemdProxy *proxy)
254 +{
255 +        g_object_unref (proxy->authority);
256 +        g_object_unref (proxy->subject);
257 +
258 +        g_free (proxy);
259 +}
260 +
261 +gboolean systemd_proxy_can_method (SystemdProxy *proxy, gboolean *can_method, const gchar *method, GError **error)
262 +{
263 +        PolkitAuthorizationResult *res;
264 +        GError *local_error = NULL;
265 +
266 +        *can_method = FALSE;
267 +        res = polkit_authority_check_authorization_sync (proxy->authority,
268 +                                                         proxy->subject,
269 +                                                         method,
270 +                                                         NULL,
271 +                                                         POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
272 +                                                         NULL,
273 +                                                         &local_error);
274 +        if (res == NULL) {
275 +                g_propagate_error (error, local_error);
276 +                return FALSE;
277 +        }
278 +
279 +        *can_method = polkit_authorization_result_get_is_authorized (res) ||
280 +                       polkit_authorization_result_get_is_challenge (res);
281 +
282 +        g_object_unref (res);
283 +
284 +        return TRUE;
285 +}
286 +
287 +gboolean systemd_proxy_can_restart (SystemdProxy *proxy, gboolean *can_restart, GError **error)
288 +{
289 +       return systemd_proxy_can_method(proxy, can_restart, SYSTEMD_REBOOT_ACTION, error);
290 +}
291 +
292 +gboolean systemd_proxy_can_shutdown (SystemdProxy *proxy, gboolean *can_shutdown, GError **error)
293 +{
294 +       return systemd_proxy_can_method(proxy, can_shutdown, SYSTEMD_SHUTDOWN_ACTION, error);
295 +}
296 +
297 +gboolean systemd_proxy_can_suspend (SystemdProxy *proxy, gboolean *can_suspend, GError **error)
298 +{
299 +        return systemd_proxy_can_method(proxy, can_suspend, SYSTEMD_SUSPEND_ACTION, error);
300 +}
301 +
302 +gboolean systemd_proxy_can_hibernate (SystemdProxy *proxy, gboolean *can_hibernate, GError **error)
303 +{
304 +        return systemd_proxy_can_method(proxy, can_hibernate, SYSTEMD_HIBERNATE_ACTION, error);
305 +}
306 +
307 +gboolean systemd_proxy_method (SystemdProxy *proxy, const gchar *method, GError **error)
308 +{
309 +        GDBusConnection *bus;
310 +
311 +        bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
312 +        g_dbus_connection_call_sync (bus,
313 +                                     SYSTEMD_DBUS_NAME,
314 +                                     SYSTEMD_DBUS_PATH,
315 +                                     SYSTEMD_DBUS_INTERFACE,
316 +                                     method,
317 +                                     g_variant_new ("(b)", TRUE),
318 +                                     NULL, 0, G_MAXINT, NULL, NULL);
319 +        g_object_unref (bus);
320 +
321 +        return TRUE;
322 +}
323 +
324 +gboolean systemd_proxy_restart (SystemdProxy *proxy, GError **error)
325 +{
326 +       return systemd_proxy_method(proxy, "Reboot", error);
327 +}
328 +
329 +gboolean systemd_proxy_shutdown (SystemdProxy *proxy, GError **error)
330 +{
331 +       return systemd_proxy_method(proxy, "PowerOff", error);
332 +}
333 +
334 +gboolean systemd_proxy_suspend (SystemdProxy *proxy, GError **error)
335 +{
336 +        return systemd_proxy_method(proxy, "Suspend", error);
337 +}
338 +
339 +gboolean systemd_proxy_hibernate (SystemdProxy *proxy, GError **error)
340 +{
341 +        return systemd_proxy_method(proxy, "Hibernate", error);
342 +}
343 +
344 diff -up xfce4-session-4.10.0/xfce4-session/xfsm-systemd.h.systemd xfce4-session-4.10.0/xfce4-session/xfsm-systemd.h
345 --- xfce4-session-4.10.0/xfce4-session/xfsm-systemd.h.systemd   2013-03-29 14:29:28.469230730 -0500
346 +++ xfce4-session-4.10.0/xfce4-session/xfsm-systemd.h   2013-03-29 14:35:54.549404063 -0500
347 @@ -0,0 +1,46 @@
348 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
349 + *
350 + * Copyright (C) 2012 Christian Hesse
351 + *
352 + * Licensed under the GNU General Public License Version 2
353 + *
354 + * This program is free software; you can redistribute it and/or modify
355 + * it under the terms of the GNU General Public License as published by
356 + * the Free Software Foundation; either version 2 of the License, or
357 + * (at your option) any later version.
358 + *
359 + * This program is distributed in the hope that it will be useful,
360 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
362 + * GNU General Public License for more details.
363 + *
364 + * You should have received a copy of the GNU General Public License
365 + * along with this program; if not, write to the Free Software
366 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
367 + */
368 +
369 +#ifndef __SYSTEMD_PROXY_H__
370 +#define __SYSTEMD_PROXY_H__
371 +
372 +#include <glib.h>
373 +
374 +G_BEGIN_DECLS
375 +
376 +typedef struct _SystemdProxy SystemdProxy;
377 +
378 +SystemdProxy *systemd_proxy_new (void);
379 +void          systemd_proxy_free (SystemdProxy *proxy);
380 +gboolean      systemd_proxy_can_method (SystemdProxy *proxy, gboolean *can_method, const char *method, GError **error);
381 +gboolean      systemd_proxy_can_restart (SystemdProxy *proxy, gboolean *can_restart, GError **error);
382 +gboolean      systemd_proxy_can_shutdown (SystemdProxy *proxy, gboolean *can_shutdown, GError **error);
383 +gboolean      systemd_proxy_can_suspend (SystemdProxy *proxy, gboolean *can_suspend, GError **error);
384 +gboolean      systemd_proxy_can_hibernate (SystemdProxy *proxy, gboolean *can_hibernate, GError **error);
385 +gboolean      systemd_proxy_method (SystemdProxy *proxy, const char *method, GError **error);
386 +gboolean      systemd_proxy_restart (SystemdProxy *proxy, GError **error);
387 +gboolean      systemd_proxy_shutdown (SystemdProxy *proxy, GError **error);
388 +gboolean      systemd_proxy_suspend (SystemdProxy *proxy, GError **error);
389 +gboolean      systemd_proxy_hibernate (SystemdProxy *proxy, GError **error);
390 +
391 +G_END_DECLS
392 +
393 +#endif  /* __SYSTEMD_PROXY_H__ */
This page took 0.166967 seconds and 2 git commands to generate.