diff options
author | Martijn Kaijser <martijn@xbmc.org> | 2018-12-01 22:35:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-01 22:35:09 +0100 |
commit | 149cd9a9b64b04cf5f23f4b18551184e9b279107 (patch) | |
tree | 074b3e22c81dd3299f68cf945c415d4b1199e8eb | |
parent | 5880ccf21c62d60ae2779cc69b4d8952ea4174ad (diff) | |
parent | 4b5cb88305a149fe5c89a87220361a5b66cf2368 (diff) |
Merge pull request #14976 from wsnipex/dbus-logind
[linux] powermanagement: change logind detection to also use Dbus
-rw-r--r-- | xbmc/platform/linux/powermanagement/LogindUPowerSyscall.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/xbmc/platform/linux/powermanagement/LogindUPowerSyscall.cpp b/xbmc/platform/linux/powermanagement/LogindUPowerSyscall.cpp index 120429ecee..9e65e939fc 100644 --- a/xbmc/platform/linux/powermanagement/LogindUPowerSyscall.cpp +++ b/xbmc/platform/linux/powermanagement/LogindUPowerSyscall.cpp @@ -121,7 +121,37 @@ bool CLogindUPowerSyscall::HasLogind() // recommended method by systemd devs. The seats directory // doesn't exist unless logind created it and therefore is running. // see also https://mail.gnome.org/archives/desktop-devel-list/2013-March/msg00092.html - return (access("/run/systemd/seats/", F_OK) >= 0); + if (access("/run/systemd/seats/", F_OK) >= 0) + return true; + + // on some environments "/run/systemd/seats/" doesn't exist, e.g. on flatpak. Try DBUS instead. + CDBusMessage message(LOGIND_DEST, LOGIND_PATH, LOGIND_IFACE, "ListSeats"); + DBusMessage *reply = message.SendSystem(); + if (!reply) + return false; + + DBusMessageIter arrIter; + if (dbus_message_iter_init(reply, &arrIter) && dbus_message_iter_get_arg_type(&arrIter) == DBUS_TYPE_ARRAY) + { + DBusMessageIter structIter; + dbus_message_iter_recurse(&arrIter, &structIter); + if (dbus_message_iter_get_arg_type(&structIter) == DBUS_TYPE_STRUCT) + { + DBusMessageIter strIter; + dbus_message_iter_recurse(&structIter, &strIter); + if (dbus_message_iter_get_arg_type(&strIter) == DBUS_TYPE_STRING) + { + char *seat; + dbus_message_iter_get_basic(&strIter, &seat); + if (StringUtils::StartsWith(seat, "seat")) + { + CLog::Log(LOGDEBUG, "LogindUPowerSyscall::HasLogind - found seat: {}", seat); + return true; + } + } + } + } + return false; } bool CLogindUPowerSyscall::LogindSetPowerState(const char *state) |