From 49336aa33623fb20a495ecd329a2504511a0c112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 19 Feb 2013 00:39:49 +0200 Subject: allow compiling with systemd, but have systemd booted optional --- src/Makefile.am | 1 + src/gpm-manager.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b5e7369..fcbca7d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -192,6 +192,7 @@ mate_power_manager_LDADD = \ $(LIBNOTIFY_LIBS) \ $(GPM_EXTRA_LIBS) \ $(UPOWER_LIBS) \ + $(SYSTEMD_INHIBIT_LIBS) \ -lm mate_power_manager_CFLAGS = \ diff --git a/src/gpm-manager.c b/src/gpm-manager.c index 3d501b4..9b697b5 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -33,6 +33,9 @@ #ifdef HAVE_UNISTD_H #include #endif /* HAVE_UNISTD_H */ +#ifdef WITH_SYSTEMD_INHIBIT +#include +#endif /* WITH_SYSTEMD_INHIBIT */ #include #include @@ -1847,17 +1850,19 @@ gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, Gpm #ifdef WITH_SYSTEMD_INHIBIT /** * gpm_main_system_inhibit: + * + * Return a fd to the to the inhibitor, that we can close on exit. + * + * Return value: fd, -1 on error **/ static gint32 gpm_manager_systemd_inhibit (GDBusProxy *proxy) { - /* Return a fd to the to the inhibitor, that we can close on exit. */ - //GDBusProxy *proxy; GError *error = NULL; gint32 r = -1; gint32 fd = -1; GVariant *res; GUnixFDList *fd_list = NULL; - //proxy == NULL; + /* Should we define these elsewhere? */ const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch"; const char* arg_who = g_get_user_name (); @@ -1892,7 +1897,7 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { &fd_list, NULL, &error - ); + ); if (error == NULL && res != NULL) { g_variant_get(res, "(h)", &r); egg_debug ("Inhibiting systemd sleep res = %i", r); @@ -1907,8 +1912,8 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { } else if (error != NULL || res == NULL) { egg_error ("Error in dbus - %s", error->message); g_error_free (error); - return -EIO; - } + return -EIO; + } egg_debug ("Inhibiting systemd sleep - success"); return r; } @@ -1933,7 +1938,10 @@ gpm_manager_init (GpmManager *manager) #ifdef WITH_SYSTEMD_INHIBIT /* We want to inhibit the systemd suspend options, and take care of them ourselves */ - manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy); + if (sd_booted() > 0) { + manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy); + } + #endif /* init to unthrottled */ -- cgit v1.2.1