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])
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
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])
29 + AC_DEFINE(HAVE_SYSTEMD, 1, [Define if systemd is used for session tracking])
31 +AC_SUBST(SYSTEMD_CFLAGS)
32 +AC_SUBST(SYSTEMD_LIBS)
33 +AM_CONDITIONAL(WITH_SYSTEMD, [test "$with_systemd" = "yes"], [Using systemd])
35 dnl Check for gnome support
36 XDT_CHECK_OPTIONAL_PACKAGE([GNOME_KEYRING], [gnome-keyring-1], [2.22],
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 = \
46 +xfce4_session_SOURCES += \
51 xfce4_session_CFLAGS = \
52 $(GNOME_KEYRING_CFLAGS) \
54 @@ -73,6 +81,7 @@ xfce4_session_CFLAGS = \
62 @@ -92,6 +101,7 @@ xfce4_session_LDADD = \
68 $(GNOME_KEYRING_LIBS) \
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
74 #include <xfce4-session/xfsm-consolekit.h>
75 #include <xfce4-session/xfsm-upower.h>
79 +#include <systemd/sd-daemon.h>
80 +#include <xfce4-session/xfsm-systemd.h>
83 static void xfsm_shutdown_finalize (GObject *object);
84 static void xfsm_shutdown_sudo_free (XfsmShutdown *shutdown);
85 @@ -93,6 +96,9 @@ struct _XfsmShutdown
88 XfsmConsolekit *consolekit;
90 + SystemdProxy *systemd_proxy;
95 @@ -130,6 +137,12 @@ xfsm_shutdown_init (XfsmShutdown *shutdown)
100 + shutdown->systemd_proxy = NULL;
101 + if (sd_booted() > 0)
102 + shutdown->systemd_proxy = systemd_proxy_new ();
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)
110 XfsmShutdown *shutdown = XFSM_SHUTDOWN (object);
113 + if (shutdown->systemd_proxy)
114 + systemd_proxy_free (shutdown->systemd_proxy);
117 g_object_unref (G_OBJECT (shutdown->consolekit));
118 g_object_unref (G_OBJECT (shutdown->upower));
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);
125 + if (shutdown->systemd_proxy)
126 + return systemd_proxy_restart (shutdown->systemd_proxy, error);
129 return xfsm_consolekit_try_restart (shutdown->consolekit, error);
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);
137 + if (shutdown->systemd_proxy)
138 + return systemd_proxy_shutdown (shutdown->systemd_proxy, error);
141 return xfsm_consolekit_try_shutdown (shutdown->consolekit, error);
144 @@ -669,6 +691,11 @@ xfsm_shutdown_try_suspend (XfsmShutdown
146 g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
149 + if (shutdown->systemd_proxy)
150 + return systemd_proxy_suspend (shutdown->systemd_proxy, error);
153 return xfsm_upower_try_suspend (shutdown->upower, error);
156 @@ -680,6 +706,11 @@ xfsm_shutdown_try_hibernate (XfsmShutdow
158 g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
161 + if (shutdown->systemd_proxy)
162 + return systemd_proxy_hibernate (shutdown->systemd_proxy, error);
165 return xfsm_upower_try_hibernate (shutdown->upower, error);
168 @@ -697,6 +727,12 @@ xfsm_shutdown_can_restart (XfsmShutdown
173 + if (shutdown->systemd_proxy) {
174 + if (systemd_proxy_can_restart (shutdown->systemd_proxy, can_restart, error))
178 if (xfsm_consolekit_can_restart (shutdown->consolekit, can_restart, error))
181 @@ -724,6 +757,12 @@ xfsm_shutdown_can_shutdown (XfsmShutdown
186 + if (shutdown->systemd_proxy) {
187 + if (systemd_proxy_can_shutdown (shutdown->systemd_proxy, can_shutdown, error))
191 if (xfsm_consolekit_can_shutdown (shutdown->consolekit, can_shutdown, error))
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
198 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
200 + * Copyright (C) 2012 Christian Hesse
202 + * Licensed under the GNU General Public License Version 2
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.
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.
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.
221 +#include <gio/gio.h>
222 +#include <polkit/polkit.h>
224 +#include "xfsm-systemd.h"
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"
234 +struct _SystemdProxy {
235 + PolkitAuthority *authority;
236 + PolkitSubject *subject;
240 +systemd_proxy_new (void)
242 + SystemdProxy *proxy;
244 + proxy = g_new0 (SystemdProxy, 1);
246 + proxy->authority = polkit_authority_get_sync (NULL, NULL);
247 + proxy->subject = polkit_unix_process_new (getpid());
253 +systemd_proxy_free (SystemdProxy *proxy)
255 + g_object_unref (proxy->authority);
256 + g_object_unref (proxy->subject);
261 +gboolean systemd_proxy_can_method (SystemdProxy *proxy, gboolean *can_method, const gchar *method, GError **error)
263 + PolkitAuthorizationResult *res;
264 + GError *local_error = NULL;
266 + *can_method = FALSE;
267 + res = polkit_authority_check_authorization_sync (proxy->authority,
271 + POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
275 + g_propagate_error (error, local_error);
279 + *can_method = polkit_authorization_result_get_is_authorized (res) ||
280 + polkit_authorization_result_get_is_challenge (res);
282 + g_object_unref (res);
287 +gboolean systemd_proxy_can_restart (SystemdProxy *proxy, gboolean *can_restart, GError **error)
289 + return systemd_proxy_can_method(proxy, can_restart, SYSTEMD_REBOOT_ACTION, error);
292 +gboolean systemd_proxy_can_shutdown (SystemdProxy *proxy, gboolean *can_shutdown, GError **error)
294 + return systemd_proxy_can_method(proxy, can_shutdown, SYSTEMD_SHUTDOWN_ACTION, error);
297 +gboolean systemd_proxy_can_suspend (SystemdProxy *proxy, gboolean *can_suspend, GError **error)
299 + return systemd_proxy_can_method(proxy, can_suspend, SYSTEMD_SUSPEND_ACTION, error);
302 +gboolean systemd_proxy_can_hibernate (SystemdProxy *proxy, gboolean *can_hibernate, GError **error)
304 + return systemd_proxy_can_method(proxy, can_hibernate, SYSTEMD_HIBERNATE_ACTION, error);
307 +gboolean systemd_proxy_method (SystemdProxy *proxy, const gchar *method, GError **error)
309 + GDBusConnection *bus;
311 + bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
312 + g_dbus_connection_call_sync (bus,
315 + SYSTEMD_DBUS_INTERFACE,
317 + g_variant_new ("(b)", TRUE),
318 + NULL, 0, G_MAXINT, NULL, NULL);
319 + g_object_unref (bus);
324 +gboolean systemd_proxy_restart (SystemdProxy *proxy, GError **error)
326 + return systemd_proxy_method(proxy, "Reboot", error);
329 +gboolean systemd_proxy_shutdown (SystemdProxy *proxy, GError **error)
331 + return systemd_proxy_method(proxy, "PowerOff", error);
334 +gboolean systemd_proxy_suspend (SystemdProxy *proxy, GError **error)
336 + return systemd_proxy_method(proxy, "Suspend", error);
339 +gboolean systemd_proxy_hibernate (SystemdProxy *proxy, GError **error)
341 + return systemd_proxy_method(proxy, "Hibernate", error);
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
348 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
350 + * Copyright (C) 2012 Christian Hesse
352 + * Licensed under the GNU General Public License Version 2
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.
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.
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.
369 +#ifndef __SYSTEMD_PROXY_H__
370 +#define __SYSTEMD_PROXY_H__
376 +typedef struct _SystemdProxy SystemdProxy;
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);
393 +#endif /* __SYSTEMD_PROXY_H__ */