summaryrefslogtreecommitdiff
path: root/src/gpm-control.c
diff options
context:
space:
mode:
authorFabio Erculiani <[email protected]>2013-07-04 23:11:54 +0200
committerFabio Erculiani <[email protected]>2013-07-05 12:49:56 +0200
commitb36c93575f88bd5a045c36f3d8084608ae20879f (patch)
tree3165189b3184ab2e0fb12eb033eb2df04b071379 /src/gpm-control.c
parent4d842135ce677957aee8bd5bb47f875b0ece570a (diff)
downloadmate-power-manager-b36c93575f88bd5a045c36f3d8084608ae20879f.tar.bz2
mate-power-manager-b36c93575f88bd5a045c36f3d8084608ae20879f.tar.xz
drop --with-systemdsleep and move logind detection to runtime
There is no need to bind the user to either systemd-logind or upower at build time. People can switch between init systems or run logind without systemd.
Diffstat (limited to 'src/gpm-control.c')
-rw-r--r--src/gpm-control.c179
1 files changed, 90 insertions, 89 deletions
diff --git a/src/gpm-control.c b/src/gpm-control.c
index 71f857c..d0db730 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -166,23 +166,23 @@ gpm_control_suspend (GpmControl *control, GError **error)
gboolean lock_mate_keyring;
MateKeyringResult keyres;
#endif /* WITH_KEYRING */
-#ifdef WITH_SYSTEMD_SLEEP
+
GError *dbus_error = NULL;
DBusGProxy *proxy;
GVariant *res;
-#endif
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 */
@@ -208,40 +208,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);
@@ -278,23 +279,21 @@ gpm_control_hibernate (GpmControl *control, GError **error)
MateKeyringResult keyres;
#endif /* WITH_KEYRING */
-#ifdef WITH_SYSTEMD_SLEEP
GError *dbus_error = NULL;
DBusGProxy *proxy;
-#endif
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 */
@@ -320,39 +319,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);