summarylogtreecommitdiffstats
path: root/systemd-support.patch
blob: 8c39f834678dd17b1ad1f51c10c5ca6aa8f68e93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
=== modified file 'src/gtk-logout-helper.c'
--- src/gtk-logout-helper.c	2012-11-29 22:09:57 +0000
+++ src/gtk-logout-helper.c	2013-01-02 19:00:42 +0000
@@ -31,6 +31,71 @@
 #include "shared-names.h"
 
 static GVariant *
+call_systemd (const gchar *method, GVariant *parameters, GError **error)
+{
+	GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
+	if (!bus)
+	{
+		g_variant_unref (parameters);
+		return NULL;
+	}
+
+	GVariant *result = g_dbus_connection_call_sync(bus,
+	                                               "org.freedesktop.login1",
+	                                               "/org/freedesktop/login1",
+	                                               "org.freedesktop.login1.Manager",
+	                                               method,
+	                                               parameters,
+	                                               NULL,
+	                                               G_DBUS_CALL_FLAGS_NONE,
+	                                               -1,
+	                                               NULL,
+	                                               error);
+	g_object_unref (bus);
+
+	return result;
+}
+
+static void
+systemd_fallback (LogoutDialogType action)
+{
+	GError * error = NULL;
+	GVariant *result = NULL;
+
+	g_debug("Falling back to using systemd for action");
+
+	switch (action) {
+		case LOGOUT_DIALOG_TYPE_LOG_OUT:
+			g_warning("Unable to fallback to systemd for logout as it's a session issue.  We need some sort of session handler.");
+			break;
+		case LOGOUT_DIALOG_TYPE_SHUTDOWN:
+			g_debug("Telling systemd to 'PowerOff'");
+			result = call_systemd ("PowerOff", g_variant_new ("(b)", TRUE), &error);
+			break;
+		case LOGOUT_DIALOG_TYPE_RESTART:
+			g_debug("Telling systemd to 'Reboot'");
+			result = call_systemd ("Reboot", g_variant_new ("(b)", TRUE), &error);
+			break;
+		default:
+			g_warning("Unknown action");
+			break;
+	}
+
+	if (!result) {
+		if (error != NULL) {
+			g_warning ("systemd action failed: %s", error->message);
+		} else {
+			g_warning ("systemd action failed: unknown error");
+		}
+	}
+	else
+		g_variant_unref (result);
+	g_clear_error (&error);
+
+	return;
+}
+
+static GVariant *
 call_console_kit (const gchar *method, GVariant *parameters, GError **error)
 {
 	GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
@@ -88,7 +153,7 @@
 			g_warning ("ConsoleKit action failed: unknown error");
 		}
 
-		consolekit_fallback(action);
+		systemd_fallback(action);
 	}
 	else
 		g_variant_unref (result);