Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suspend via logind over UPower if available. #4273

Merged
merged 1 commit into from Jun 8, 2015
Merged

Suspend via logind over UPower if available. #4273

merged 1 commit into from Jun 8, 2015

Conversation

yasij
Copy link
Contributor

@yasij yasij commented Feb 24, 2014

From pull request #4168:
The suspend feature of UPower is deprecated. XBMC supports suspending using systemd-logind, however it defaults to a few other UPower methods first before trying Logind. This patch checks for logind first, and uses it if available.

I've updated the HasLogind() method to make sure systemd is at least version 183, or if the systemd version API is missing, that Upstart is at least version 1.11. This way, XBMC will default to suspending via logind if the version supports suspend. If it does not, it will skip logind and try UPower as before.

@yasij
Copy link
Contributor Author

yasij commented Feb 24, 2014

@topfs2 @t-nelson Here is a version of the patch that checks for systemd or upstart version.

@topfs2
Copy link
Contributor

topfs2 commented Feb 24, 2014

Nice! I will try to review it today or tomorrow!
Den 24 feb 2014 02:48 skrev "Joseph A. Yasi" notifications@github.com:

@topfs2 https://github.com/topfs2 @t-nelsonhttps://github.com/t-nelsonHere is a version of the patch that checks for systemd or upstart version.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4273#issuecomment-35851908
.

@topfs2
Copy link
Contributor

topfs2 commented Feb 24, 2014

Oh and you could have used old PR via git push -f if you'd wanted
Den 24 feb 2014 07:03 skrev "Tobias Arrskog" topfs2@xboxmediacenter.com:

Nice! I will try to review it today or tomorrow!
Den 24 feb 2014 02:48 skrev "Joseph A. Yasi" notifications@github.com:

@topfs2 https://github.com/topfs2 @t-nelsonhttps://github.com/t-nelsonHere is a version of the patch that checks for systemd or upstart version.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4273#issuecomment-35851908
.

@yasij
Copy link
Contributor Author

yasij commented Feb 24, 2014

Ah, I haven't used github very much. I didn't know there was a force flag. I realized what was going on with KDE's upstart version check, and I'm fixing the patch. (version 1.11 > version 1.2 but 1.11 < 1.2 numerically.

@yasij
Copy link
Contributor Author

yasij commented Feb 24, 2014

@topfs2 Okay, I've fixed the Upstart version check in the branch.

@MartijnKaijser MartijnKaijser added this to the Pending for inclusion milestone Feb 27, 2014
@mus65
Copy link
Contributor

mus65 commented Mar 7, 2014

please DO NOT merge this. Checking the version number with regexes is hackish and the suspend functionality in KDE recently broke because they did the same thing. See this recent discussion on the systemd-devel mailing list:

http://lists.freedesktop.org/archives/systemd-devel/2014-February/017399.html

One of the systemd devs explains how to properly implement checks like this in the following mail:

http://lists.freedesktop.org/archives/systemd-devel/2014-February/017452.html

@mus65
Copy link
Contributor

mus65 commented Mar 7, 2014

Looking at the code (I am the one who rewrote most of the logind stuff last year), I guess the simplest way to do this is, is to call one of the CanXYZ()-Methods (doesn't really matter which I guess, afaik they were all added in the same systemd version, except for HybridSleep maybe) and check whether it returns org.freedesktop.DBus.Error.UnknownMethod. If so, you could assume that the logind version is too old.
Currently the CanXYZ() calls are all done in LogindCheckCapability() which doesn't distinguish between "machine doesn't support XYZ" and "logind method doesn't exist".

Maybe there is an even more elegant way to this, I'm no DBus expert. But you really, really should NOT check for the version number.

@yasij
Copy link
Contributor Author

yasij commented Mar 8, 2014

Why would they change the Version API like that? Yes, it is generally poor practice to check versions, but people do it, and changing APIs in a stable software like that is also poor practice. I'll update it to call the CanSuspend() and check for a DBus error message.

@yasij
Copy link
Contributor Author

yasij commented Mar 9, 2014

@topfs2, @mus65 I've updated it to call CanSuspend and check for a DBus error. If there is no error, it returns true.

@t-nelson
Copy link
Contributor

@topfs2 for review please

@t-nelson
Copy link
Contributor

t-nelson commented Apr 3, 2014

@topfs2 ping

@wsnipex
Copy link
Member

wsnipex commented May 20, 2014

gave this a try on ubuntu 14.04 cause I was hoping it'd fix hibernate.
Sadly it doesn't work:
process 16022: Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.
process 16022: arguments to dbus_message_unref() were incorrect, assertion "!message->in_cache" failed in file ../../dbus/dbus-message.c line 1618.
This is normally a bug in some application using the D-Bus library.

Result: hibernate is disabled.

@yasij
Copy link
Contributor Author

yasij commented May 21, 2014

Odd that it worked before. I dropped the offending dbus_connection_close line. Try it now.

@wsnipex
Copy link
Member

wsnipex commented May 21, 2014

still produces this error:
process 20172: arguments to dbus_message_unref() were incorrect, assertion "!message->in_cache" failed in file ../../dbus/dbus-message.c line 1618.
This is normally a bug in some application using the D-Bus library.

@yasij
Copy link
Contributor Author

yasij commented May 21, 2014

Try it now. The CDBusMessage wrapper class was handling the free of the
message. I must have assertions turned off because I was not seeing them.
On May 21, 2014 5:51 AM, "Wolfgang Schupp" notifications@github.com
wrote:

still produces this error:
process 20172: arguments to dbus_message_unref() were incorrect, assertion
"!message->in_cache" failed in file ../../dbus/dbus-message.c line 1618.
This is normally a bug in some application using the D-Bus library.


Reply to this email directly or view it on GitHubhttps://github.com//pull/4273#issuecomment-43735320
.

@fritsch
Copy link
Member

fritsch commented Apr 26, 2015

@wsnipex ping

We need to solve those issues as with 15.04 they use logind, but still ship upower and stuff .. bloody mess.

@wsnipex
Copy link
Member

wsnipex commented Apr 26, 2015

the change looks good to me, did anyone test it on 15.04 or another logind based distro?

@fritsch
Copy link
Member

fritsch commented Apr 26, 2015

14.04 is still working as it should with that patch (from Unity).

I don't have full blown 15.04 with desktop here, sadly.

2015-04-26 17:38 GMT+02:00 Wolfgang Schupp notifications@github.com:

the change looks good to me, did anyone test it on 15.04 or another logind
based distro?

Reply to this email directly or view it on GitHub
#4273 (comment).

               Key-ID:     0x1A995A9B
               keyserver: pgp.mit.edu

Fingerprint: 4606 DA19 EC2E 9A0B 0157 C81B DA07 CF63 1A99 5A9B

@wsnipex
Copy link
Member

wsnipex commented Apr 27, 2015

jenkins build this please

@yasij
Copy link
Contributor Author

yasij commented May 3, 2015

I just merged this with tip and tried it with Kubuntu 15.04. It's working. Without it, Kodi doesn't suspend as the UPower CanSuspend calls fail. It looks like Ubuntu stripped that out of UPower.

@fritsch
Copy link
Member

fritsch commented May 4, 2015

Yes, that's the idea behind this approach.

@fritsch fritsch added Type: Fix non-breaking change which fixes an issue v15 Isengard labels May 4, 2015
@fritsch
Copy link
Member

fritsch commented May 4, 2015

@MartijnKaijser @FernetMenta this is needed to make hybrid distros happy, e.g. upower available, but stripped down.

@yasij
Copy link
Contributor Author

yasij commented May 4, 2015

I'd be a bit cautious about adding my change here for those on distros like
14.04 and 14.10 with stripped down systemd-logind and working UPower. The
systemd-shim on Ubuntu with Upstart supports suspend, and this change will
work for suspend on those distros. However, The systemd-shim does not call
the suspend/resume scripts. Scripts that were in /etc/pm/sleep.d are not
called properly. They are called after turning the network off which means
any script that had network depended code won't work anymore. The
/lib/systemd/system-sleep scripts are just totally ignored:
https://bugs.launchpad.net/ubuntu/+source/systemd-shim/+bug/1196752 .

I think the UPower class needs to check for the CanSuspend call before
reporting that it is available.

On Mon, May 4, 2015 at 2:05 AM, Peter Frühberger notifications@github.com
wrote:

@MartijnKaijser https://github.com/MartijnKaijser @FernetMenta
https://github.com/FernetMenta this is needed to make hybrid distros
happy, e.g. upower available, but stripped down.


Reply to this email directly or view it on GitHub
#4273 (comment).

@fritsch
Copy link
Member

fritsch commented May 4, 2015

Not nice - It seems even upstream does not know at all howto do it properly. And we cannot really workaround every mad thing distributions implemented on their way to systemd.

@Paxxi
Copy link
Member

Paxxi commented May 5, 2015

What about brute force instead? Load both and send events to all loaded providers?

@yasij
Copy link
Contributor Author

yasij commented May 5, 2015

That won't work. Both the UPower and the systemd-logind call would trigger
a suspend on Ubuntu 14.04 and 14.10. You'd end up with a double suspend
race condition. I'll modify the Has methods of the other classes to check
for the CanSuspend methods when I get a chance.

On Tue, May 5, 2015 at 9:33 AM, Pär Björklund notifications@github.com
wrote:

What about brute force instead? Load both and send events to all loaded
providers?


Reply to this email directly or view it on GitHub
#4273 (comment).

@Paxxi
Copy link
Member

Paxxi commented May 23, 2015

what's the status on this? Is it in good shape?

@yasij
Copy link
Contributor Author

yasij commented May 24, 2015

I haven't had time to look at it until just now. I think the best way to handle this is in xbmc/powermanagement/PowerManager.cpp. I'm going to drop the two patches from this branch, and instead check capabilities of each type. If UPower doesn't support suspend, try the next class until we find one that does.

@yasij
Copy link
Contributor Author

yasij commented May 25, 2015

Here's a patch that counts the number of available power features on Linux and selects the manager that supports the most. I've only tested this on Kubuntu 15.04 with logind. It successfully tries ConsoleKit + UPower and ConsoleKit + DeviceKit before settling on logind because it supports all of suspend, powerdown, hibernate and reboot.

@wsnipex
Copy link
Member

wsnipex commented May 26, 2015

looks like a nice solution to me. @topfs2 ping

@wsnipex
Copy link
Member

wsnipex commented Jun 5, 2015

I tested this on ubuntu 14.04 and it works fine for me.
Unless someone speaks up, I'll merge it tomorrow.

wsnipex added a commit that referenced this pull request Jun 8, 2015
Suspend via logind over UPower if available.
@wsnipex wsnipex merged commit 33501b9 into xbmc:master Jun 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Fix non-breaking change which fixes an issue v15 Isengard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants