From 78d712a80daa55ed056ee6b685623f352fd2a204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sat, 23 Mar 2019 08:03:56 +0100 Subject: [PATCH] Add support for elogind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for elogind, the split-off implementation of systemd-logind for non-systemd systems. It is mostly API-compatible, with the notable exception of renaming the library, so I've managed to keep changes to the minimum. I've replaced 'systemd' and 'SYSTEMD_LOGIND' with plain 'logind' to avoid the confusion that they are only used by systemd branches of the code. Signed-off-by: Michał Górny --- Makefile.am | 1 + configure.ac | 32 +++++++++++++++++++++ src/Makefile.am | 2 ++ src/gs-listener-dbus.c | 63 ++++++++++++++++++++++-------------------- 4 files changed, 68 insertions(+), 30 deletions(-) diff --git a/Makefile.am b/Makefile.am index b88bf8c..94f4989 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,7 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} NULL = DISTCHECK_CONFIGURE_FLAGS = \ + --without-elogind \ --without-systemd SUBDIRS = \ diff --git a/configure.ac b/configure.ac index f0ec537..2c474a2 100644 --- a/configure.ac +++ b/configure.ac @@ -982,6 +982,37 @@ fi AC_SUBST(SYSTEMD_CFLAGS) AC_SUBST(SYSTEMD_LIBS) +dnl --------------------------------------------------------------------------- +dnl elogind +dnl --------------------------------------------------------------------------- + +AC_ARG_WITH(elogind, + AS_HELP_STRING([--with-elogind], + [Add elogind support]), + [with_elogind=$withval], [with_elogind=auto]) + +PKG_CHECK_MODULES(ELOGIND, [libelogind], [have_elogind=yes], [have_elogind=no]) + +if test "x$with_elogind" = "xauto" ; then + if test x$have_elogind = xno ; then + use_elogind=no + else + use_elogind=yes + fi +else + use_elogind=$with_elogind +fi + +if test "x$use_elogind" = "xyes"; then + if test "x$have_elogind" = "xno"; then + AC_MSG_ERROR([Elogind support explicitly required, but elogind not found]) + fi + + AC_DEFINE(WITH_ELOGIND, 1, [elogind support]) +fi +AC_SUBST(ELOGIND_CFLAGS) +AC_SUBST(ELOGIND_LIBS) + dnl --------------------------------------------------------------------------- dnl libxfcekbd dnl --------------------------------------------------------------------------- @@ -1173,6 +1204,7 @@ echo " Screen locking enabled: ${enable_locking} Show keyboard indicator: ${with_kbd_layout_indicator} systemd support: ${use_systemd} + elogind support: ${use_elogind} ConsoleKit support: ${use_console_kit} PAM support: ${have_pam} PAM auth type: ${PAM_AUTH_TYPE} diff --git a/src/Makefile.am b/src/Makefile.am index 8d69b5c..31068e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,6 +32,7 @@ AM_CPPFLAGS = \ $(LIBXFCEKBDUI_CFLAGS) \ $(LIBXKLAVIER_CFLAGS) \ $(SYSTEMD_CFLAGS) \ + $(ELOGIND_CFLAGS) \ $(NULL) bin_PROGRAMS = \ @@ -248,6 +249,7 @@ xfce4_screensaver_LDADD = \ $(XFCE_SCREENSAVER_LIBS) \ $(SAVER_LIBS) \ $(SYSTEMD_LIBS) \ + $(ELOGIND_LIBS) \ $(NULL) xfce4_screensaver_LDFLAGS = -export-dynamic diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c index 715cf48..2e2f5e5 100644 --- a/src/gs-listener-dbus.c +++ b/src/gs-listener-dbus.c @@ -38,6 +38,9 @@ #ifdef WITH_SYSTEMD #include #endif +#ifdef WITH_ELOGIND +#include +#endif #include "gs-listener-dbus.h" #include "gs-marshal.h" @@ -61,12 +64,12 @@ 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 LOGIND_SERVICE "org.freedesktop.login1" +#define LOGIND_PATH "/org/freedesktop/login1" +#define LOGIND_INTERFACE "org.freedesktop.login1.Manager" -#define SYSTEMD_LOGIND_SESSION_INTERFACE "org.freedesktop.login1.Session" -#define SYSTEMD_LOGIND_SESSION_PATH "/org/freedesktop/login1/session" +#define LOGIND_SESSION_INTERFACE "org.freedesktop.login1.Session" +#define LOGIND_SESSION_PATH "/org/freedesktop/login1/session" /* consolekit */ #define CK_NAME "org.freedesktop.ConsoleKit" @@ -95,8 +98,8 @@ struct GSListenerPrivate { time_t session_idle_start; char *session_id; -#ifdef WITH_SYSTEMD - gboolean have_systemd; +#if defined(WITH_SYSTEMD) || defined(WITH_ELOGIND) + gboolean have_logind; #endif guint32 ck_throttle_cookie; @@ -1393,7 +1396,7 @@ _listener_message_path_is_our_session (GSListener *listener, return FALSE; } -#ifdef WITH_SYSTEMD +#if defined(WITH_SYSTEMD) || defined(WITH_ELOGIND) static gboolean properties_changed_match (DBusMessage *message, const char *property) { @@ -1480,23 +1483,23 @@ 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 defined(WITH_SYSTEMD) || defined(WITH_ELOGIND) + if (listener->priv->have_logind) { + if (dbus_message_is_signal (message, LOGIND_SESSION_INTERFACE, "Unlock")) { if (_listener_message_path_is_our_session (listener, message)) { gs_debug ("Systemd 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")) { + } else if (dbus_message_is_signal (message, LOGIND_SESSION_INTERFACE, "Lock")) { if (_listener_message_path_is_our_session (listener, message)) { gs_debug ("Systemd requested session lock"); g_signal_emit (listener, signals[LOCK], 0); } return DBUS_HANDLER_RESULT_HANDLED; - } else if (dbus_message_is_signal (message, SYSTEMD_LOGIND_INTERFACE, "PrepareForSleep")) { + } else if (dbus_message_is_signal (message, LOGIND_INTERFACE, "PrepareForSleep")) { gboolean active = 0; DBusError error; @@ -2059,29 +2062,29 @@ gs_listener_acquire (GSListener *listener, listener_dbus_system_filter_function, listener, NULL); -#ifdef WITH_SYSTEMD - if (listener->priv->have_systemd) { +#if defined(WITH_SYSTEMD) || defined(WITH_ELOGIND) + if (listener->priv->have_logind) { dbus_bus_add_match (listener->priv->system_connection, "type='signal'" - ",sender='"SYSTEMD_LOGIND_SERVICE"'" - ",interface='"SYSTEMD_LOGIND_SESSION_INTERFACE"'" + ",sender='"LOGIND_SERVICE"'" + ",interface='"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"'" + ",sender='"LOGIND_SERVICE"'" + ",interface='"LOGIND_SESSION_INTERFACE"'" ",member='Lock'", NULL); dbus_bus_add_match (listener->priv->system_connection, "type='signal'" - ",sender='"SYSTEMD_LOGIND_SERVICE"'" - ",interface='"SYSTEMD_LOGIND_INTERFACE"'" + ",sender='"LOGIND_SERVICE"'" + ",interface='"LOGIND_INTERFACE"'" ",member='PrepareForSleep'", NULL); dbus_bus_add_match (listener->priv->system_connection, "type='signal'" - ",sender='"SYSTEMD_LOGIND_SERVICE"'" + ",sender='"LOGIND_SERVICE"'" ",interface='"DBUS_INTERFACE_PROPERTIES"'" ",member='PropertiesChanged'", NULL); @@ -2134,14 +2137,14 @@ query_session_id (GSListener *listener) { dbus_error_init (&error); -#ifdef WITH_SYSTEMD - if (listener->priv->have_systemd) { +#if defined(WITH_SYSTEMD) || defined(WITH_ELOGIND) + if (listener->priv->have_logind) { dbus_uint32_t pid = getpid(); - message = dbus_message_new_method_call (SYSTEMD_LOGIND_SERVICE, - SYSTEMD_LOGIND_PATH, - SYSTEMD_LOGIND_INTERFACE, - "GetSessionByPID"); + message = dbus_message_new_method_call (LOGIND_SERVICE, + LOGIND_PATH, + LOGIND_INTERFACE, + "GetSessionByPID"); if (message == NULL) { gs_debug ("Couldn't allocate the dbus message"); return NULL; @@ -2216,9 +2219,9 @@ static void gs_listener_init (GSListener *listener) { listener->priv = gs_listener_get_instance_private (listener); -#ifdef WITH_SYSTEMD +#if defined(WITH_SYSTEMD) || defined(WITH_ELOGIND) /* check if logind is running */ - listener->priv->have_systemd = (access("/run/systemd/seats/", F_OK) >= 0); + listener->priv->have_logind = (access("/run/systemd/seats/", F_OK) >= 0); #endif gs_listener_dbus_init (listener); -- 2.21.0