[Xfce4-commits] [apps/xfce4-screensaver] 51/425: add support for systemd-logind http://git.gnome.org/browse/gnome-screensaver/commit/?id=6bb98e9acb9391d1aec8f7dcb44ef7d16b3dcb91 https://bugzilla.gnome.org/show_bug.cgi?id=669787
noreply at xfce.org
noreply at xfce.org
Mon Oct 15 01:48:18 CEST 2018
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/xfce4-screensaver.
commit 49b028e85839da7006b4857cf323a7cbee91316c
Author: Stefano Karapetsas <stefano at karapetsas.com>
Date: Mon Nov 12 14:33:34 2012 +0100
add support for systemd-logind
http://git.gnome.org/browse/gnome-screensaver/commit/?id=6bb98e9acb9391d1aec8f7dcb44ef7d16b3dcb91
https://bugzilla.gnome.org/show_bug.cgi?id=669787
---
configure.ac | 40 ++++++++-
src/Makefile.am | 2 +
src/gs-listener-dbus.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 252 insertions(+), 11 deletions(-)
diff --git a/configure.ac b/configure.ac
index f70ad46..ace76f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -485,7 +485,7 @@ fi
#
if test "$ac_macosx" = yes; then
if test "$enable_locking" = yes; then
- AC_MSG_RESULT(locking disabled: it doesn't work on MacOS X)
+ AC_MSG_RESULT(locking disabled: it doesnt work on MacOS X)
enable_locking=no
AC_DEFINE(NO_LOCKING, 1, [Define if screen locking support is disabled])
fi
@@ -893,6 +893,42 @@ fi
AC_SUBST(AUTH_SCHEME)
dnl ---------------------------------------------------------------------------
+dnl ConsoleKit
+dnl ---------------------------------------------------------------------------
+
+AC_ARG_WITH(console-kit,
+ AS_HELP_STRING([--with-console-kit],
+ [Add ConsoleKit support]),,
+ with_console_kit=auto)
+
+use_console_kit=no
+if test "x$with_console_kit" != "xno" ; then
+ use_console_kit=yes
+ AC_DEFINE(WITH_CONSOLE_KIT, 1, [ConsoleKit support])
+fi
+AM_CONDITIONAL(WITH_CONSOLE_KIT, test x$use_console_kit = xyes)
+AC_SUBST(WITH_CONSOLE_KIT)
+
+dnl ---------------------------------------------------------------------------
+dnl systemd
+dnl ---------------------------------------------------------------------------
+
+AC_ARG_WITH(systemd,
+ AS_HELP_STRING([--with-systemd],
+ [Add systemd support]),,
+ with_systemd=auto)
+
+use_systemd=no
+if test "x$with_systemd" != "xno" ; then
+ use_systemd=yes
+ AC_DEFINE(WITH_SYSTEMD, 1, [systemd support])
+
+ PKG_CHECK_MODULES(SYSTEMD, libsystemd-login libsystemd-daemon)
+fi
+AM_CONDITIONAL(WITH_SYSTEMD, test x$use_systemd = xyes)
+AC_SUBST(WITH_SYSTEMD)
+
+dnl ---------------------------------------------------------------------------
dnl libmatekbd
dnl ---------------------------------------------------------------------------
@@ -1107,6 +1143,8 @@ echo "
Screen locking enabled: ${enable_locking}
Show keyboard indicator: ${with_kbd_layout_indicator}
+ systemd support: ${use_systemd}
+ ConsoleKit support: ${use_console_kit}
libmatenotify support: ${have_libmatenotify}
PAM support: ${have_pam}
Have shadow passwords: ${have_shadow}
diff --git a/src/Makefile.am b/src/Makefile.am
index 1de819f..272b931 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,6 +31,7 @@ INCLUDES = \
$(DBUS_CFLAGS) \
$(LIBMATEKBDUI_CFLAGS) \
$(LIBMATENOTIFY_CFLAGS) \
+ $(SYSTEMD_CFLAGS) \
$(NULL)
bin_PROGRAMS = \
@@ -213,6 +214,7 @@ mate_screensaver_gl_helper_SOURCES = \
mate_screensaver_LDADD = \
$(MATE_SCREENSAVER_LIBS) \
$(SAVER_LIBS) \
+ $(SYSTEMD_LIBS) \
$(NULL)
mate_screensaver_LDFLAGS = -export-dynamic
diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c
index 601689c..5a4afb4 100644
--- a/src/gs-listener-dbus.c
+++ b/src/gs-listener-dbus.c
@@ -32,6 +32,11 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
+#ifdef WITH_SYSTEMD
+#include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
+#endif
+
#include "gs-listener-dbus.h"
#include "gs-marshal.h"
#include "gs-debug.h"
@@ -59,6 +64,15 @@ static DBusHandlerResult gs_listener_message_handler (DBusConnection *connec
#define HAL_DEVICE_INTERFACE "org.freedesktop.Hal.Device"
+/* systemd logind */
+#define SYSTEMD_LOGIND_SERVICE "org.freedesktop.login1"
+#define SYSTEMD_LOGIND_PATH "/org/freedesktop/login1"
+#define SYSTEMD_LOGIND_INTERFACE "org.freedesktop.login1.Manager"
+
+#define SYSTEMD_LOGIND_SESSION_INTERFACE "org.freedesktop.login1.Session"
+#define SYSTEMD_LOGIND_SESSION_PATH "/org/freedesktop/login1/session"
+
+/* consolekit */
#define CK_NAME "org.freedesktop.ConsoleKit"
#define CK_MANAGER_PATH "/org/freedesktop/ConsoleKit/Manager"
#define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager"
@@ -87,6 +101,10 @@ struct GSListenerPrivate
time_t session_idle_start;
char *session_id;
+#ifdef WITH_SYSTEMD
+ gboolean have_systemd;
+#endif
+
guint32 ck_throttle_cookie;
};
@@ -1539,20 +1557,101 @@ _listener_message_path_is_our_session (GSListener *listener,
DBusMessage *message)
{
const char *ssid;
- gboolean ours;
-
- ours = FALSE;
ssid = dbus_message_get_path (message);
- if (ssid != NULL
- && listener->priv->session_id != NULL
- && strcmp (ssid, listener->priv->session_id) == 0)
- {
- ours = TRUE;
+
+ if (ssid == NULL)
+ return FALSE;
+
+ if (listener->priv->session_id == NULL)
+ return FALSE;
+
+#ifdef WITH_SYSTEMD
+ /* The bus object path is simply the actual session ID
+ * prefixed to make it a bus path */
+ if (listener->priv->have_systemd)
+ return g_str_has_prefix (ssid, SYSTEMD_LOGIND_SESSION_PATH "/")
+ && strcmp (ssid + sizeof (SYSTEMD_LOGIND_SESSION_PATH),
+ listener->priv->session_id) == 0;
+#endif
+
+#ifdef WITH_CONSOLE_KIT
+ if (strcmp (ssid, listener->priv->session_id) == 0)
+ return TRUE;
+#endif
+
+ return FALSE;
+}
+
+#ifdef WITH_SYSTEMD
+static gboolean
+properties_changed_match (DBusMessage *message,
+ const char *property)
+{
+ DBusMessageIter iter, sub, sub2;
+
+ /* Checks whether a certain property is listed in the
+ * specified PropertiesChanged message */
+
+ if (!dbus_message_iter_init (message, &iter))
+ goto failure;
+
+ /* Jump over interface name */
+ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
+ goto failure;
+
+ dbus_message_iter_next (&iter);
+
+ /* First, iterate through the changed properties array */
+ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY ||
+ dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_DICT_ENTRY)
+ goto failure;
+
+ dbus_message_iter_recurse (&iter, &sub);
+ while (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_INVALID) {
+ const char *name;
+
+ if (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_DICT_ENTRY)
+ goto failure;
+
+ dbus_message_iter_recurse (&sub, &sub2);
+ dbus_message_iter_get_basic (&sub2, &name);
+
+ if (strcmp (name, property) == 0)
+ return TRUE;
+
+ dbus_message_iter_next (&sub);
}
- return ours;
+ dbus_message_iter_next (&iter);
+
+ /* Second, iterate through the invalidated properties array */
+ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY ||
+ dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_STRING)
+ goto failure;
+
+ dbus_message_iter_recurse (&iter, &sub);
+ while (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_INVALID) {
+ const char *name;
+
+ if (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_STRING)
+ goto failure;
+
+ dbus_message_iter_get_basic (&sub, &name);
+
+ if (strcmp (name, property) == 0)
+ return TRUE;
+
+ dbus_message_iter_next (&sub);
+ }
+
+ return FALSE;
+
+failure:
+ gs_debug ("Failed to decode PropertiesChanged message.");
+ return FALSE;
}
+#endif
static DBusHandlerResult
listener_dbus_handle_system_message (DBusConnection *connection,
@@ -1573,6 +1672,52 @@ listener_dbus_handle_system_message (DBusConnection *connection,
dbus_message_get_destination (message));
#endif
+#ifdef WITH_SYSTEMD
+ if (listener->priv->have_systemd) {
+
+ if (dbus_message_is_signal (message, SYSTEMD_LOGIND_SESSION_INTERFACE, "Unlock")) {
+ if (_listener_message_path_is_our_session (listener, message)) {
+ gs_debug ("Console kit requested session unlock");
+ gs_listener_set_active (listener, FALSE);
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ } else if (dbus_message_is_signal (message, SYSTEMD_LOGIND_SESSION_INTERFACE, "Lock")) {
+ if (_listener_message_path_is_our_session (listener, message)) {
+ gs_debug ("ConsoleKit requested session lock");
+ g_signal_emit (listener, signals [LOCK], 0);
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ } else if (dbus_message_is_signal (message, DBUS_INTERFACE_PROPERTIES, "PropertiesChanged")) {
+
+ if (_listener_message_path_is_our_session (listener, message)) {
+
+ if (properties_changed_match (message, "Active")) {
+ gboolean new_active;
+
+ /* Instead of going via the
+ * bus to read the new
+ * property state, let's
+ * shortcut this and ask
+ * directly the low-level
+ * information */
+
+ new_active = sd_session_is_active (listener->priv->session_id) != 0;
+ if (new_active)
+ g_signal_emit (listener, signals [SIMULATE_USER_ACTIVITY], 0);
+ }
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+#endif
+
+#ifdef WITH_CONSOLE_KIT
+
if (dbus_message_is_signal (message, HAL_DEVICE_INTERFACE, "Condition"))
{
DBusError error;
@@ -1600,6 +1745,8 @@ listener_dbus_handle_system_message (DBusConnection *connection,
return DBUS_HANDLER_RESULT_HANDLED;
}
+
+
else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "Unlock"))
{
if (_listener_message_path_is_our_session (listener, message))
@@ -1683,7 +1830,7 @@ listener_dbus_handle_system_message (DBusConnection *connection,
return DBUS_HANDLER_RESULT_HANDLED;
}
-
+#endif
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
@@ -2134,7 +2281,32 @@ gs_listener_acquire (GSListener *listener,
listener_dbus_system_filter_function,
listener,
NULL);
+#ifdef WITH_SYSTEMD
+ if (listener->priv->have_systemd) {
+ dbus_bus_add_match (listener->priv->system_connection,
+ "type='signal'"
+ ",sender='"SYSTEMD_LOGIND_SERVICE"'"
+ ",interface='"SYSTEMD_LOGIND_SESSION_INTERFACE"'"
+ ",member='Unlock'",
+ NULL);
+ dbus_bus_add_match (listener->priv->system_connection,
+ "type='signal'"
+ ",sender='"SYSTEMD_LOGIND_SERVICE"'"
+ ",interface='"SYSTEMD_LOGIND_SESSION_INTERFACE"'"
+ ",member='Lock'",
+ NULL);
+ dbus_bus_add_match (listener->priv->system_connection,
+ "type='signal'"
+ ",sender='"SYSTEMD_LOGIND_SERVICE"'"
+ ",interface='"DBUS_INTERFACE_PROPERTIES"'"
+ ",member='PropertiesChanged'",
+ NULL);
+
+ goto finish;
+ }
+#endif
+#ifdef WITH_CONSOLE_KIT
dbus_bus_add_match (listener->priv->system_connection,
"type='signal'"
",interface='"HAL_DEVICE_INTERFACE"'"
@@ -2155,8 +2327,10 @@ gs_listener_acquire (GSListener *listener,
",interface='"CK_SESSION_INTERFACE"'"
",member='ActiveChanged'",
NULL);
+#endif
}
+finish:
return acquired;
}
@@ -2179,6 +2353,26 @@ query_session_id (GSListener *listener)
dbus_error_init (&error);
+#ifdef WITH_SYSTEMD
+ if (listener->priv->have_systemd) {
+ char *t;
+ int r;
+
+ r = sd_pid_get_session (0, &t);
+ if (r < 0) {
+ gs_debug ("Couldn't determine our own session id: %s", strerror (-r));
+ return NULL;
+ }
+
+ /* t is allocated with malloc(), we need it with g_malloc() */
+ ssid = g_strdup(t);
+ free (t);
+
+ return ssid;
+ }
+#endif
+
+#ifdef WITH_CONSOLE_KIT
message = dbus_message_new_method_call (CK_NAME, CK_MANAGER_PATH, CK_MANAGER_INTERFACE, "GetCurrentSession");
if (message == NULL)
{
@@ -2205,6 +2399,9 @@ query_session_id (GSListener *listener)
dbus_message_unref (reply);
return g_strdup (ssid);
+#else
+ return NULL;
+#endif
}
static void
@@ -2220,6 +2417,10 @@ gs_listener_init (GSListener *listener)
{
listener->priv = GS_LISTENER_GET_PRIVATE (listener);
+#ifdef WITH_SYSTEMD
+ listener->priv->have_systemd = sd_booted () > 0;
+#endif
+
gs_listener_dbus_init (listener);
init_session_id (listener);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list