session: merge branch 'th/elogind-bgo779167'

https://bugzilla.gnome.org/show_bug.cgi?id=779167
This commit is contained in:
Thomas Haller
2017-02-24 16:37:39 +01:00
3 changed files with 61 additions and 15 deletions

View File

@@ -428,14 +428,15 @@ AC_ARG_WITH(systemd-logind, AS_HELP_STRING([--with-systemd-logind=yes|no],
[Support systemd session tracking])) [Support systemd session tracking]))
AC_ARG_WITH(consolekit, AS_HELP_STRING([--with-consolekit=yes|no], AC_ARG_WITH(consolekit, AS_HELP_STRING([--with-consolekit=yes|no],
[Support consolekit session tracking])) [Support consolekit session tracking]))
AC_ARG_WITH(session-tracking, AS_HELP_STRING([--with-session-tracking=systemd|consolekit|no], AC_ARG_WITH(session-tracking, AS_HELP_STRING([--with-session-tracking=systemd|elogind|consolekit|no],
[Compatibility option to choose one session tracking module])) [Compatibility option to choose one session tracking module]))
# backwards compatibility # backwards compatibility
AS_IF([test "$with_session_tracking" = "ck"], [use_consolekit="yes" use_systemd_logind="no"]) AS_IF([test "$with_session_tracking" = "ck"], [use_consolekit="yes" use_systemd_logind="no" use_elogind="no"])
AS_IF([test "$with_session_tracking" = "consolekit"], [use_consolekit="yes" use_systemd_logind="no"]) AS_IF([test "$with_session_tracking" = "consolekit"], [use_consolekit="yes" use_systemd_logind="no" use_elogind="no"])
AS_IF([test "$with_session_tracking" = "systemd"], [use_consolekit="no" use_systemd_logind="yes"]) AS_IF([test "$with_session_tracking" = "systemd"], [use_consolekit="no" use_systemd_logind="yes" use_elogind="no"])
AS_IF([test "$with_session_tracking" = "no"], [use_consolekit="no" use_systemd_logind="no"]) AS_IF([test "$with_session_tracking" = "elogind"], [use_consolekit="no" use_systemd_logind="no" use_elogind="yes"])
AS_IF([test "$with_session_tracking" = "none"], [use_consolekit="no" use_systemd_logind="no"]) AS_IF([test "$with_session_tracking" = "no"], [use_consolekit="no" use_systemd_logind="no" use_elogind="no"])
AS_IF([test "$with_session_tracking" = "none"], [use_consolekit="no" use_systemd_logind="no" use_elogind="no"])
# current options # current options
AS_IF([test -n "$with_systemd_logind" ], [use_systemd_logind="$with_systemd_logind"]) AS_IF([test -n "$with_systemd_logind" ], [use_systemd_logind="$with_systemd_logind"])
AS_IF([test -n "$with_consolekit" ], [use_consolekit="$with_consolekit"]) AS_IF([test -n "$with_consolekit" ], [use_consolekit="$with_consolekit"])
@@ -453,9 +454,26 @@ if test "$use_systemd_logind" = "yes" -a "$have_systemd_logind" = "no"; then
AC_MSG_ERROR([You must have libsystemd installed to build with systemd-logind support.]) AC_MSG_ERROR([You must have libsystemd installed to build with systemd-logind support.])
fi fi
if test "$have_systemd_logind" = "yes"; then if test "$have_systemd_logind" = "yes"; then
AC_DEFINE([SESSION_TRACKING_SYSTEMD], 1, [Define to 1 if libsystemd-login is available]) AC_DEFINE([SESSION_TRACKING_SYSTEMD], 1, [Define to 1 if libsystemd-login is available])
session_tracking="$session_tracking, systemd-logind" session_tracking="$session_tracking, systemd-logind"
fi fi
if test "$use_elogind" = "yes" -a "$have_systemd_logind" = "yes"; then
AC_MSG_ERROR([Cannot enable systemd-logind together with elogind.])
fi
if test "$use_elogind" = "yes"; then
PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libelogind], [have_elogind=yes], [PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libelogind], [have_elogind=yes], [have_elogind=no])])
else
have_elogind=no
fi
if test "$use_elogind" = "yes" -a "$have_elogind" = "no"; then
AC_MSG_ERROR([You must have libelogind installed to build with elogind support.])
fi
if test "$have_elogind" = "yes"; then
AC_DEFINE([SESSION_TRACKING_ELOGIND], 1, [Define to 1 if libelogin is available])
session_tracking="$session_tracking, elogind"
fi
if test "$use_consolekit" = "yes"; then if test "$use_consolekit" = "yes"; then
AC_DEFINE([SESSION_TRACKING_CONSOLEKIT], 1, [Define to 1 if ConsoleKit is available]) AC_DEFINE([SESSION_TRACKING_CONSOLEKIT], 1, [Define to 1 if ConsoleKit is available])
AC_DEFINE([CKDB_PATH], "/var/run/ConsoleKit/database", [Path to ConsoleKit database]) AC_DEFINE([CKDB_PATH], "/var/run/ConsoleKit/database", [Path to ConsoleKit database])
@@ -463,7 +481,7 @@ if test "$use_consolekit" = "yes"; then
fi fi
session_tracking="$(printf '%s' "${session_tracking}" | sed 's/^, //')" session_tracking="$(printf '%s' "${session_tracking}" | sed 's/^, //')"
AC_ARG_WITH(suspend-resume, AS_HELP_STRING([--with-suspend-resume=upower|systemd|consolekit], [Build NetworkManager with specific suspend/resume support])) AC_ARG_WITH(suspend-resume, AS_HELP_STRING([--with-suspend-resume=upower|systemd|elogind|consolekit], [Build NetworkManager with specific suspend/resume support]))
if test "z$with_suspend_resume" = "z"; then if test "z$with_suspend_resume" = "z"; then
PKG_CHECK_EXISTS([libsystemd >= 209], [have_systemd_inhibit=yes], PKG_CHECK_EXISTS([libsystemd >= 209], [have_systemd_inhibit=yes],
[PKG_CHECK_EXISTS([libsystemd-login >= 183], [have_systemd_inhibit=yes], [have_systemd_inhibit=no])]) [PKG_CHECK_EXISTS([libsystemd-login >= 183], [have_systemd_inhibit=yes], [have_systemd_inhibit=no])])
@@ -471,6 +489,12 @@ if test "z$with_suspend_resume" = "z"; then
# Use systemd if it's new enough # Use systemd if it's new enough
with_suspend_resume="systemd" with_suspend_resume="systemd"
else else
PKG_CHECK_EXISTS([libelogind >= 219], [have_elogind_inhibit=yes],
[PKG_CHECK_EXISTS([libelogind >= 219], [have_elogind_inhibit=yes], [have_elogind_inhibit=no])])
if test "z${have_elogind_inhibit}" = "zyes"; then
# Use elogind if it's new enough
with_suspend_resume="elogind"
else
if test "$use_consolekit" = "yes"; then if test "$use_consolekit" = "yes"; then
# Use consolekit suspend if session tracking is consolekit # Use consolekit suspend if session tracking is consolekit
with_suspend_resume="consolekit" with_suspend_resume="consolekit"
@@ -480,6 +504,7 @@ if test "z$with_suspend_resume" = "z"; then
fi fi
fi fi
fi fi
fi
case $with_suspend_resume in case $with_suspend_resume in
upower) upower)
@@ -490,11 +515,16 @@ case $with_suspend_resume in
[PKG_CHECK_MODULES(SYSTEMD_INHIBIT, [libsystemd-login >= 183])]) [PKG_CHECK_MODULES(SYSTEMD_INHIBIT, [libsystemd-login >= 183])])
AC_DEFINE([SUSPEND_RESUME_SYSTEMD], 1, [Define to 1 to use systemd suspend api]) AC_DEFINE([SUSPEND_RESUME_SYSTEMD], 1, [Define to 1 to use systemd suspend api])
;; ;;
elogind)
PKG_CHECK_MODULES(ELOGIND_INHIBIT, [libelogind >= 219],,
[PKG_CHECK_MODULES(ELOGIND_INHIBIT, [libelogind >= 219])])
AC_DEFINE([SUSPEND_RESUME_ELOGIND], 1, [Define to 1 to use elogind suspend api])
;;
consolekit) consolekit)
AC_DEFINE([SUSPEND_RESUME_CONSOLEKIT], 1, [Define to 1 to use ConsoleKit2 suspend api]) AC_DEFINE([SUSPEND_RESUME_CONSOLEKIT], 1, [Define to 1 to use ConsoleKit2 suspend api])
;; ;;
*) *)
AC_MSG_ERROR(--with-suspend-resume must be one of [upower, systemd, consolekit]) AC_MSG_ERROR(--with-suspend-resume must be one of [upower, systemd, elogind, consolekit])
;; ;;
esac esac

View File

@@ -28,8 +28,20 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#if defined (SESSION_TRACKING_SYSTEMD) && defined (SESSION_TRACKING_ELOGIND)
#error Cannot build both systemd-logind and elogind support
#endif
#ifdef SESSION_TRACKING_SYSTEMD #ifdef SESSION_TRACKING_SYSTEMD
#include <systemd/sd-login.h> #include <systemd/sd-login.h>
#define LOGIND_NAME "systemd-logind"
#endif
#ifdef SESSION_TRACKING_ELOGIND
#include <elogind/sd-login.h>
#define LOGIND_NAME "elogind"
/* Re-Use SESSION_TRACKING_SYSTEMD as elogind substitutes systemd-login */
#define SESSION_TRACKING_SYSTEMD 1
#endif #endif
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
@@ -85,7 +97,7 @@ st_sd_session_exists (NMSessionMonitor *monitor, uid_t uid, gboolean active)
status = sd_uid_get_sessions (uid, active, NULL); status = sd_uid_get_sessions (uid, active, NULL);
if (status < 0) if (status < 0)
_LOGE ("failed to get systemd sessions for uid %d: %d", uid, status); _LOGE ("failed to get "LOGIND_NAME" sessions for uid %d: %d", uid, status);
return status > 0; return status > 0;
} }
@@ -112,7 +124,7 @@ st_sd_init (NMSessionMonitor *monitor)
return; return;
if ((status = sd_login_monitor_new (NULL, &monitor->sd.monitor)) < 0) { if ((status = sd_login_monitor_new (NULL, &monitor->sd.monitor)) < 0) {
_LOGE ("failed to create systemd login monitor: %d", status); _LOGE ("failed to create "LOGIND_NAME" monitor: %d", status);
return; return;
} }
@@ -357,7 +369,7 @@ nm_session_monitor_init (NMSessionMonitor *monitor)
{ {
#ifdef SESSION_TRACKING_SYSTEMD #ifdef SESSION_TRACKING_SYSTEMD
st_sd_init (monitor); st_sd_init (monitor);
_LOGD ("using systemd-logind session tracking"); _LOGD ("using "LOGIND_NAME" session tracking");
#endif #endif
#ifdef SESSION_TRACKING_CONSOLEKIT #ifdef SESSION_TRACKING_CONSOLEKIT

View File

@@ -38,13 +38,17 @@
#define USE_UPOWER 1 #define USE_UPOWER 1
#define _NMLOG_PREFIX_NAME "sleep-monitor-up" #define _NMLOG_PREFIX_NAME "sleep-monitor-up"
#elif defined (SUSPEND_RESUME_SYSTEMD) #elif defined (SUSPEND_RESUME_SYSTEMD) || defined (SUSPEND_RESUME_ELOGIND)
#define SUSPEND_DBUS_NAME "org.freedesktop.login1" #define SUSPEND_DBUS_NAME "org.freedesktop.login1"
#define SUSPEND_DBUS_PATH "/org/freedesktop/login1" #define SUSPEND_DBUS_PATH "/org/freedesktop/login1"
#define SUSPEND_DBUS_INTERFACE "org.freedesktop.login1.Manager" #define SUSPEND_DBUS_INTERFACE "org.freedesktop.login1.Manager"
#define USE_UPOWER 0 #define USE_UPOWER 0
#if defined (SUSPEND_RESUME_SYSTEMD)
#define _NMLOG_PREFIX_NAME "sleep-monitor-sd" #define _NMLOG_PREFIX_NAME "sleep-monitor-sd"
#else
#define _NMLOG_PREFIX_NAME "sleep-monitor-el"
#endif
#elif defined(SUSPEND_RESUME_CONSOLEKIT) #elif defined(SUSPEND_RESUME_CONSOLEKIT)
@@ -60,7 +64,7 @@
#else #else
#error define one of SUSPEND_RESUME_SYSTEMD, SUSPEND_RESUME_CONSOLEKIT, or SUSPEND_RESUME_UPOWER #error define one of SUSPEND_RESUME_SYSTEMD, SUSPEND_RESUME_ELOGIND, SUSPEND_RESUME_CONSOLEKIT, or SUSPEND_RESUME_UPOWER
#endif #endif