~ballogy/indicator-session/systemd-support

« back to all changes in this revision

Viewing changes to src/gtk-logout-helper.c

  • Committer: György Balló
  • Date: 2013-01-02 17:11:40 UTC
  • Revision ID: ballogy@freestart.hu-20130102171140-s902gvb89jkrmxcc
Add support for systemd

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "shared-names.h"
32
32
 
33
33
static GVariant *
 
34
call_systemd (const gchar *method, GVariant *parameters, GError **error)
 
35
{
 
36
        GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
 
37
        if (!bus)
 
38
        {
 
39
                g_variant_unref (parameters);
 
40
                return NULL;
 
41
        }
 
42
 
 
43
        GVariant *result = g_dbus_connection_call_sync(bus,
 
44
                                                       "org.freedesktop.login1",
 
45
                                                       "/org/freedesktop/login1",
 
46
                                                       "org.freedesktop.login1.Manager",
 
47
                                                       method,
 
48
                                                       parameters,
 
49
                                                       NULL,
 
50
                                                       G_DBUS_CALL_FLAGS_NONE,
 
51
                                                       -1,
 
52
                                                       NULL,
 
53
                                                       error);
 
54
        g_object_unref (bus);
 
55
 
 
56
        return result;
 
57
}
 
58
 
 
59
static void
 
60
systemd_fallback (LogoutDialogType action)
 
61
{
 
62
        GError * error = NULL;
 
63
        GVariant *result = NULL;
 
64
 
 
65
        g_debug("Falling back to using systemd for action");
 
66
 
 
67
        switch (action) {
 
68
                case LOGOUT_DIALOG_TYPE_LOG_OUT:
 
69
                        g_warning("Unable to fallback to systemd for logout as it's a session issue.  We need some sort of session handler.");
 
70
                        break;
 
71
                case LOGOUT_DIALOG_TYPE_SHUTDOWN:
 
72
                        g_debug("Telling systemd to 'PowerOff'");
 
73
                        result = call_systemd ("PowerOff", g_variant_new ("(b)", TRUE), &error);
 
74
                        break;
 
75
                case LOGOUT_DIALOG_TYPE_RESTART:
 
76
                        g_debug("Telling systemd to 'Reboot'");
 
77
                        result = call_systemd ("Reboot", g_variant_new ("(b)", TRUE), &error);
 
78
                        break;
 
79
                default:
 
80
                        g_warning("Unknown action");
 
81
                        break;
 
82
        }
 
83
 
 
84
        if (!result) {
 
85
                if (error != NULL) {
 
86
                        g_warning ("systemd action failed: %s", error->message);
 
87
                } else {
 
88
                        g_warning ("systemd action failed: unknown error");
 
89
                }
 
90
        }
 
91
        else
 
92
                g_variant_unref (result);
 
93
        g_clear_error (&error);
 
94
 
 
95
        return;
 
96
}
 
97
 
 
98
static GVariant *
34
99
call_console_kit (const gchar *method, GVariant *parameters, GError **error)
35
100
{
36
101
        GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
88
153
                        g_warning ("ConsoleKit action failed: unknown error");
89
154
                }
90
155
 
91
 
                consolekit_fallback(action);
 
156
                systemd_fallback(action);
92
157
        }
93
158
        else
94
159
                g_variant_unref (result);