diff options
author | Fabio Erculiani <[email protected]> | 2013-07-10 14:10:03 +0200 |
---|---|---|
committer | Fabio Erculiani <[email protected]> | 2013-07-10 14:10:03 +0200 |
commit | c415be077de603ac1a5f4fafc6df649e12bc6118 (patch) | |
tree | 9b6ddcc08757cf9a3395caad8cbf83f95e7558a3 | |
parent | c53504907c06e8f20272ad32ff8e516f36d92ddb (diff) | |
download | mate-power-manager-c415be077de603ac1a5f4fafc6df649e12bc6118.tar.bz2 mate-power-manager-c415be077de603ac1a5f4fafc6df649e12bc6118.tar.xz |
Add systemd Shutdown() API support to gpm-control.c
-rw-r--r-- | src/gpm-control.c | 55 |
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; } |