summaryrefslogtreecommitdiff
path: root/src/gpm-control.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpm-control.c')
-rw-r--r--src/gpm-control.c266
1 files changed, 158 insertions, 108 deletions
diff --git a/src/gpm-control.c b/src/gpm-control.c
index 71f857c..ec50136 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -39,10 +39,11 @@
#include <glib/gi18n.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
+#define UPOWER_ENABLE_DEPRECATED
#include <libupower-glib/upower.h>
#ifdef WITH_KEYRING
-#include <mate-keyring.h>
+#include <gnome-keyring.h>
#endif /* WITH_KEYRING */
#include "egg-debug.h"
@@ -86,6 +87,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;
+ GDBusProxy *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 +141,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;
}
@@ -163,33 +213,32 @@ gpm_control_suspend (GpmControl *control, GError **error)
GpmScreensaver *screensaver;
guint32 throttle_cookie = 0;
#ifdef WITH_KEYRING
- gboolean lock_mate_keyring;
- MateKeyringResult keyres;
+ gboolean lock_gnome_keyring;
+ GnomeKeyringResult keyres;
#endif /* WITH_KEYRING */
-#ifdef WITH_SYSTEMD_SLEEP
+
GError *dbus_error = NULL;
- DBusGProxy *proxy;
- GVariant *res;
-#endif
+ GDBusProxy *proxy;
screensaver = gpm_screensaver_new ();
-#ifndef WITH_SYSTEMD_SLEEP
- g_object_get (control->priv->client,
- "can-suspend", &allowed,
- NULL);
- if (!allowed) {
- egg_debug ("cannot suspend as not allowed from policy");
- g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend");
- goto out;
+
+ if (!LOGIND_RUNNING()) {
+ g_object_get (control->priv->client,
+ "can-suspend", &allowed,
+ NULL);
+ if (!allowed) {
+ egg_debug ("cannot suspend as not allowed from policy");
+ g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend");
+ goto out;
+ }
}
-#endif
#ifdef WITH_KEYRING
/* we should perhaps lock keyrings when sleeping #375681 */
- lock_mate_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_SUSPEND);
- if (lock_mate_keyring) {
- keyres = mate_keyring_lock_all_sync ();
- if (keyres != MATE_KEYRING_RESULT_OK)
+ lock_gnome_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_SUSPEND);
+ if (lock_gnome_keyring) {
+ keyres = gnome_keyring_lock_all_sync ();
+ if (keyres != GNOME_KEYRING_RESULT_OK)
egg_warning ("could not lock keyring");
}
#endif /* WITH_KEYRING */
@@ -208,40 +257,41 @@ gpm_control_suspend (GpmControl *control, GError **error)
egg_debug ("emitting sleep");
g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND);
-#ifdef WITH_SYSTEMD_SLEEP
- /* sleep via logind */
- 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,
- &dbus_error );
- if (proxy == NULL) {
- egg_error("Error connecting to dbus - %s", dbus_error->message);
- g_error_free (dbus_error);
- return -1;
- }
- g_dbus_proxy_call_sync (proxy, "Suspend",
- g_variant_new( "(b)",FALSE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &dbus_error
- );
- if (dbus_error != NULL ) {
- egg_debug ("Error in dbus - %s", dbus_error->message);
- g_error_free (dbus_error);
- ret = TRUE;
- }
- else {
- ret = TRUE;
- }
- g_object_unref(proxy);
-#else
- ret = up_client_suspend_sync (control->priv->client, NULL, error);
-#endif
+ if (LOGIND_RUNNING()) {
+ /* sleep via logind */
+ 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,
+ &dbus_error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ return -1;
+ }
+ g_dbus_proxy_call_sync (proxy, "Suspend",
+ g_variant_new( "(b)",FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &dbus_error
+ );
+ if (dbus_error != NULL ) {
+ egg_debug ("Error in dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ ret = TRUE;
+ }
+ else {
+ ret = TRUE;
+ }
+ g_object_unref(proxy);
+ }
+ else {
+ ret = up_client_suspend_sync (control->priv->client, NULL, error);
+ }
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND);
@@ -274,34 +324,32 @@ gpm_control_hibernate (GpmControl *control, GError **error)
GpmScreensaver *screensaver;
guint32 throttle_cookie = 0;
#ifdef WITH_KEYRING
- gboolean lock_mate_keyring;
- MateKeyringResult keyres;
+ gboolean lock_gnome_keyring;
+ GnomeKeyringResult keyres;
#endif /* WITH_KEYRING */
-#ifdef WITH_SYSTEMD_SLEEP
GError *dbus_error = NULL;
- DBusGProxy *proxy;
-#endif
+ GDBusProxy *proxy;
screensaver = gpm_screensaver_new ();
-#ifndef WITH_SYSTEMD_SLEEP
- g_object_get (control->priv->client,
- "can-hibernate", &allowed,
- NULL);
- if (!allowed) {
- egg_debug ("cannot hibernate as not allowed from policy");
- g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot hibernate");
- goto out;
+ if (!LOGIND_RUNNING()) {
+ g_object_get (control->priv->client,
+ "can-hibernate", &allowed,
+ NULL);
+ if (!allowed) {
+ egg_debug ("cannot hibernate as not allowed from policy");
+ g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot hibernate");
+ goto out;
+ }
}
-#endif
#ifdef WITH_KEYRING
/* we should perhaps lock keyrings when sleeping #375681 */
- lock_mate_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_HIBERNATE);
- if (lock_mate_keyring) {
- keyres = mate_keyring_lock_all_sync ();
- if (keyres != MATE_KEYRING_RESULT_OK) {
+ lock_gnome_keyring = g_settings_get_boolean (control->priv->settings, GPM_SETTINGS_LOCK_KEYRING_HIBERNATE);
+ if (lock_gnome_keyring) {
+ keyres = gnome_keyring_lock_all_sync ();
+ if (keyres != GNOME_KEYRING_RESULT_OK) {
egg_warning ("could not lock keyring");
}
}
@@ -320,39 +368,41 @@ gpm_control_hibernate (GpmControl *control, GError **error)
egg_debug ("emitting sleep");
g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_HIBERNATE);
-#ifdef WITH_SYSTEMD_SLEEP
- /* sleep via logind */
- 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,
- &dbus_error );
- if (proxy == NULL) {
- egg_error("Error connecting to dbus - %s", dbus_error->message);
- g_error_free (dbus_error);
- return -1;
- }
- g_dbus_proxy_call_sync (proxy, "Hibernate",
- g_variant_new( "(b)",FALSE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &dbus_error
- );
- if (dbus_error != NULL ) {
- egg_debug ("Error in dbus - %s", dbus_error->message);
- g_error_free (dbus_error);
- ret = TRUE;
- }
- else {
- ret = TRUE;
- }
-#else
- ret = up_client_hibernate_sync (control->priv->client, NULL, error);
-#endif
+ if (LOGIND_RUNNING()) {
+ /* sleep via logind */
+ 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,
+ &dbus_error );
+ if (proxy == NULL) {
+ egg_error("Error connecting to dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ return -1;
+ }
+ g_dbus_proxy_call_sync (proxy, "Hibernate",
+ g_variant_new( "(b)",FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &dbus_error
+ );
+ if (dbus_error != NULL ) {
+ egg_debug ("Error in dbus - %s", dbus_error->message);
+ g_error_free (dbus_error);
+ ret = TRUE;
+ }
+ else {
+ ret = TRUE;
+ }
+ }
+ else {
+ ret = up_client_hibernate_sync (control->priv->client, NULL, error);
+ }
+
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE);