@@ -1,470 +0,0 @@
1−From ae28aef315a7a6b90f1649ce6d1f30b842791cbf Mon Sep 17 00:00:00 2001
2−From: Nick Schermer <nick@xfce.org>
3−Date: Sun, 04 Nov 2012 20:23:36 +0000
4−Subject: Add shutdown/reboot functionality for systemd (bug #8729).
6−Based on patch by Christian Hesse and Evangelos Foutras.
8−diff --git a/configure.in.in b/configure.in.in
9−index 9aa4f8f..134d0f7 100644
12−@@ -96,6 +96,10 @@ XDT_CHECK_PACKAGE([DBUS], [dbus-1], [1.1.0])
13− XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.84])
14− XDT_CHECK_PACKAGE([XFCONF], [libxfconf-0], [4.9.0])
16−+dnl Check for polkit / systemd integration
17−+XDT_CHECK_OPTIONAL_PACKAGE([SYSTEMD], [polkit-gobject-1], [0.100],
18−+ [systemd], [Systemd support (through polit)])
20− dnl Check for debugging support
21− XDT_FEATURE_DEBUG([xfsm_debug_default])
23−diff --git a/xfce4-session/Makefile.am b/xfce4-session/Makefile.am
24−index c015154..f748b2b 100644
25−--- a/xfce4-session/Makefile.am
26−+++ b/xfce4-session/Makefile.am
27−@@ -38,8 +38,6 @@ xfce4_session_SOURCES = \
28− xfsm-compat-gnome.h \
36−@@ -65,6 +63,16 @@ xfce4_session_SOURCES = \
41−+xfce4_session_SOURCES += \
45−+xfce4_session_SOURCES += \
50− xfce4_session_CFLAGS = \
53−@@ -72,6 +80,7 @@ xfce4_session_CFLAGS = \
55− $(DBUS_GLIB_CFLAGS) \
61−@@ -91,6 +100,7 @@ xfce4_session_LDADD = \
69−diff --git a/xfce4-session/xfsm-shutdown.c b/xfce4-session/xfsm-shutdown.c
70−index d8757a8..4c483a7 100644
71−--- a/xfce4-session/xfsm-shutdown.c
72−+++ b/xfce4-session/xfsm-shutdown.c
74− #include <xfce4-session/xfsm-fadeout.h>
75− #include <xfce4-session/xfsm-global.h>
76− #include <xfce4-session/xfsm-legacy.h>
77−-#include <xfce4-session/xfsm-consolekit.h>
78− #include <xfce4-session/xfsm-upower.h>
82−+#include <xfce4-session/xfsm-systemd.h>
84−+#include <xfce4-session/xfsm-consolekit.h>
87− static void xfsm_shutdown_finalize (GObject *object);
88− static void xfsm_shutdown_sudo_free (XfsmShutdown *shutdown);
89−@@ -93,7 +96,11 @@ struct _XfsmShutdown
94−+ XfsmSystemd *systemd;
96− XfsmConsolekit *consolekit;
100− /* kiosk settings */
101−@@ -131,7 +138,11 @@ xfsm_shutdown_init (XfsmShutdown *shutdown)
106−+ shutdown->systemd = xfsm_systemd_get ();
108− shutdown->consolekit = xfsm_consolekit_get ();
110− shutdown->upower = xfsm_upower_get ();
111− shutdown->helper_state = SUDO_NOT_INITIAZED;
112− shutdown->helper_require_password = FALSE;
113−@@ -150,7 +161,11 @@ xfsm_shutdown_finalize (GObject *object)
115− XfsmShutdown *shutdown = XFSM_SHUTDOWN (object);
118−+ g_object_unref (G_OBJECT (shutdown->systemd));
120− g_object_unref (G_OBJECT (shutdown->consolekit));
122− g_object_unref (G_OBJECT (shutdown->upower));
124− /* close down helper */
125−@@ -641,7 +656,11 @@ xfsm_shutdown_try_restart (XfsmShutdown *shutdown,
126− if (shutdown->helper_state == SUDO_AVAILABLE)
127− return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_RESTART, error);
130−+ return xfsm_systemd_try_restart (shutdown->systemd, error);
132− return xfsm_consolekit_try_restart (shutdown->consolekit, error);
137−@@ -658,7 +677,11 @@ xfsm_shutdown_try_shutdown (XfsmShutdown *shutdown,
138− if (shutdown->helper_state == SUDO_AVAILABLE)
139− return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_SHUTDOWN, error);
142−+ return xfsm_systemd_try_shutdown (shutdown->systemd, error);
144− return xfsm_consolekit_try_shutdown (shutdown->consolekit, error);
149−@@ -698,7 +721,11 @@ xfsm_shutdown_can_restart (XfsmShutdown *shutdown,
154−+ if (xfsm_systemd_can_restart (shutdown->systemd, can_restart, error))
156− if (xfsm_consolekit_can_restart (shutdown->consolekit, can_restart, error))
160− if (xfsm_shutdown_sudo_init (shutdown, error))
161−@@ -725,7 +752,11 @@ xfsm_shutdown_can_shutdown (XfsmShutdown *shutdown,
166−+ if (xfsm_systemd_can_shutdown (shutdown->systemd, can_shutdown, error))
168− if (xfsm_consolekit_can_shutdown (shutdown->consolekit, can_shutdown, error))
172− if (xfsm_shutdown_sudo_init (shutdown, error))
173−diff --git a/xfce4-session/xfsm-systemd.c b/xfce4-session/xfsm-systemd.c
175−index 0000000..7bdd39d
177−+++ b/xfce4-session/xfsm-systemd.c
180−+ * Copyright (C) 2012 Christian Hesse
182−+ * This program is free software; you can redistribute it and/or modify
183−+ * it under the terms of the GNU General Public License as published by
184−+ * the Free Software Foundation; either version 2, or (at your option)
185−+ * any later version.
187−+ * This program is distributed in the hope that it will be useful,
188−+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
189−+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
190−+ * GNU General Public License for more details.
192−+ * You should have received a copy of the GNU General Public License
193−+ * along with this program; if not, write to the Free Software
194−+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
195−+ * MA 02110-1301 USA.
200−+#include <gio/gio.h>
201−+#include <polkit/polkit.h>
202−+#include <dbus/dbus-glib.h>
203−+#include <dbus/dbus-glib-lowlevel.h>
205−+#include <xfce4-session/xfsm-systemd.h>
209−+#define SYSTEMD_DBUS_NAME "org.freedesktop.login1"
210−+#define SYSTEMD_DBUS_PATH "/org/freedesktop/login1"
211−+#define SYSTEMD_DBUS_INTERFACE "org.freedesktop.login1.Manager"
212−+#define SYSTEMD_REBOOT_ACTION "Reboot"
213−+#define SYSTEMD_POWEROFF_ACTION "PowerOff"
214−+#define SYSTEMD_REBOOT_TEST "org.freedesktop.login1.reboot"
215−+#define SYSTEMD_POWEROFF_TEST "org.freedesktop.login1.power-off"
219−+static void xfsm_systemd_finalize (GObject *object);
223−+struct _XfsmSystemdClass
225−+ GObjectClass __parent__;
230−+ GObject __parent__;
232−+ PolkitAuthority *authority;
233−+ PolkitSubject *subject;
238−+G_DEFINE_TYPE (XfsmSystemd, xfsm_systemd, G_TYPE_OBJECT)
243−+xfsm_systemd_class_init (XfsmSystemdClass *klass)
245−+ GObjectClass *gobject_class;
247−+ gobject_class = G_OBJECT_CLASS (klass);
248−+ gobject_class->finalize = xfsm_systemd_finalize;
254−+xfsm_systemd_init (XfsmSystemd *systemd)
256−+ systemd->authority = polkit_authority_get_sync (NULL, NULL);
257−+ systemd->subject = polkit_unix_process_new (getpid());
263−+xfsm_systemd_finalize (GObject *object)
265−+ XfsmSystemd *systemd = XFSM_SYSTEMD (object);
267−+ g_object_unref (G_OBJECT (systemd->authority));
268−+ g_object_unref (G_OBJECT (systemd->subject));
270−+ (*G_OBJECT_CLASS (xfsm_systemd_parent_class)->finalize) (object);
275−+xfsm_systemd_can_method (XfsmSystemd *systemd,
276−+ gboolean *can_method,
277−+ const gchar *method,
280−+ PolkitAuthorizationResult *res;
281−+ GError *local_error = NULL;
283−+ *can_method = FALSE;
285−+ res = polkit_authority_check_authorization_sync (systemd->authority,
289−+ POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
295−+ g_propagate_error (error, local_error);
299−+ *can_method = polkit_authorization_result_get_is_authorized (res)
300−+ || polkit_authorization_result_get_is_challenge (res);
302−+ g_object_unref (G_OBJECT (res));
310−+xfsm_systemd_try_method (XfsmSystemd *systemd,
311−+ const gchar *method,
314−+ GDBusConnection *bus;
315−+ GError *local_error = NULL;
317−+ bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
318−+ if (G_UNLIKELY (bus == NULL))
321−+ g_dbus_connection_call_sync (bus,
324−+ SYSTEMD_DBUS_INTERFACE,
326−+ g_variant_new ("(b)", TRUE),
327−+ NULL, 0, G_MAXINT, NULL,
330−+ g_object_unref (G_OBJECT (bus));
332−+ if (local_error != NULL)
334−+ g_propagate_error (error, local_error);
344−+xfsm_systemd_get (void)
346−+ static XfsmSystemd *object = NULL;
348−+ if (G_LIKELY (object != NULL))
350−+ g_object_ref (G_OBJECT (object));
354−+ object = g_object_new (XFSM_TYPE_SYSTEMD, NULL);
355−+ g_object_add_weak_pointer (G_OBJECT (object), (gpointer) &object);
364−+xfsm_systemd_try_restart (XfsmSystemd *systemd,
367−+ return xfsm_systemd_try_method (systemd,
368−+ SYSTEMD_REBOOT_ACTION,
375−+xfsm_systemd_try_shutdown (XfsmSystemd *systemd,
378−+ return xfsm_systemd_try_method (systemd,
379−+ SYSTEMD_POWEROFF_ACTION,
386−+xfsm_systemd_can_restart (XfsmSystemd *systemd,
387−+ gboolean *can_restart,
390−+ return xfsm_systemd_can_method (systemd,
392−+ SYSTEMD_REBOOT_TEST,
399−+xfsm_systemd_can_shutdown (XfsmSystemd *systemd,
400−+ gboolean *can_shutdown,
403−+ return xfsm_systemd_can_method (systemd,
405−+ SYSTEMD_POWEROFF_TEST,
408−diff --git a/xfce4-session/xfsm-systemd.h b/xfce4-session/xfsm-systemd.h
410−index 0000000..8223622
412−+++ b/xfce4-session/xfsm-systemd.h
414−+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
416−+ * Copyright (C) 2012 Christian Hesse
418−+ * Licensed under the GNU General Public License Version 2
420−+ * This program is free software; you can redistribute it and/or modify
421−+ * it under the terms of the GNU General Public License as published by
422−+ * the Free Software Foundation; either version 2 of the License, or
423−+ * (at your option) any later version.
425−+ * This program is distributed in the hope that it will be useful,
426−+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
427−+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
428−+ * GNU General Public License for more details.
430−+ * You should have received a copy of the GNU General Public License
431−+ * along with this program; if not, write to the Free Software
432−+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
435−+#ifndef __XFSM_SYSTEMD_H__
436−+#define __XFSM_SYSTEMD_H__
438−+typedef struct _XfsmSystemdClass XfsmSystemdClass;
439−+typedef struct _XfsmSystemd XfsmSystemd;
441−+#define XFSM_TYPE_SYSTEMD (xfsm_systemd_get_type ())
442−+#define XFSM_SYSTEMD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFSM_TYPE_SYSTEMD, XfsmSystemd))
443−+#define XFSM_SYSTEMD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFSM_TYPE_SYSTEMD, XfsmSystemdClass))
444−+#define XFSM_IS_SYSTEMD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFSM_TYPE_SYSTEMD))
445−+#define XFSM_IS_SYSTEMD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFSM_TYPE_SYSTEMD))
446−+#define XFSM_SYSTEMD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFSM_TYPE_SYSTEMD, XfsmSystemdClass))
448−+GType xfsm_systemd_get_type (void) G_GNUC_CONST;
450−+XfsmSystemd *xfsm_systemd_get (void);
452−+gboolean xfsm_systemd_try_restart (XfsmSystemd *systemd,
455−+gboolean xfsm_systemd_try_shutdown (XfsmSystemd *systemd,
458−+gboolean xfsm_systemd_can_restart (XfsmSystemd *systemd,
459−+ gboolean *can_restart,
462−+gboolean xfsm_systemd_can_shutdown (XfsmSystemd *systemd,
463−+ gboolean *can_shutdown,
468−+#endif /* __XFSM_SYSTEMD_H__ */