summaryrefslogtreecommitdiff
path: root/src/gpm-control.c
diff options
context:
space:
mode:
authorFabio Erculiani <[email protected]>2013-07-10 14:10:03 +0200
committerFabio Erculiani <[email protected]>2013-07-10 14:10:03 +0200
commitc415be077de603ac1a5f4fafc6df649e12bc6118 (patch)
tree9b6ddcc08757cf9a3395caad8cbf83f95e7558a3 /src/gpm-control.c
parentc53504907c06e8f20272ad32ff8e516f36d92ddb (diff)
downloadmate-power-manager-c415be077de603ac1a5f4fafc6df649e12bc6118.tar.bz2
mate-power-manager-c415be077de603ac1a5f4fafc6df649e12bc6118.tar.xz
Add systemd Shutdown() API support to gpm-control.c
Diffstat (limited to 'src/gpm-control.c')
-rw-r--r--src/gpm-control.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/src/gpm-control.c b/src/gpm-control.c
index d0db730..d7ba36c 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -86,6 +86,50 @@ gpm_control_error_quark (void)
}
/**
+ * gpm_manager_systemd_shutdown:
+ *
+ * Shutdown the system using systemd-logind.
+ *
+ * Return value: fd, -1 on error
+ **/
+static gboolean
+gpm_control_systemd_shutdown (void) {
+ GError *error = NULL;
+ DBusGProxy *proxy;
+
+ egg_debug ("Requesting systemd to shutdown");
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ NULL,
+ &error );
+ //append all our arguments
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ g_dbus_proxy_call_sync (proxy, "PowerOff",
+ g_variant_new( "(b)", FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error
+ );
+ if (error != NULL) {
+ egg_error ("Error in dbus - %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* gpm_control_shutdown:
* @control: This class instance
*
@@ -96,9 +140,14 @@ gpm_control_shutdown (GpmControl *control, GError **error)
{
gboolean ret;
EggConsoleKit *console;
- console = egg_console_kit_new ();
- ret = egg_console_kit_stop (console, error);
- g_object_unref (console);
+
+ if (LOGIND_RUNNING()) {
+ ret = gpm_control_systemd_shutdown ();
+ } else {
+ console = egg_console_kit_new ();
+ ret = egg_console_kit_stop (console, error);
+ g_object_unref (console);
+ }
return ret;
}