Pulse-Eight / libcec

USB CEC Adapter communication Library http://libcec.pulse-eight.com/
Other
721 stars 290 forks source link

"Open()" in Python wrapper resulting in "Segmentation fault" #113

Closed Forage closed 9 years ago

Forage commented 9 years ago

Libcec, the Python wrapper in particular, is having issues since build #0703 of OpenElec (@MilhouseVH build). Since #0703 "self.lib.Open()" give me a "Segmentation fault" (line 80 in /usr/bin/pyCecClient.py) when trying to open a connection to a USB-CEC adapter on a RPi.

This build included quite a few libcec updates, as you can see in the post above, but I can't spot an obvious one resulting in this issue. Do you have an idea which one could be the cause of the problem or is there any way to get some more debug info to narrow it down?

MilhouseVH commented 9 years ago

Is this a Kodi segfault, if so you should have a crash log.

If it's some other non-Kodi process that is faulting try enabling core dumping (ulimit -c unlimited) then once you have a core, try running it through gdb (gdb /path/to/your/executable --core="<your core>" --batch -ex "thread apply all bt" 2>/dev/null)

opdenkamp commented 9 years ago

i haven't tested if this displays a proper message and exits correctly if a second program tries to open a connection, but i think that's what happening here. Kodi will be having an open connection to the adapter here, and then the second instance (python) will fail.

you'll have to disable CEC in Kodi for this to work.

but still, I'd like to see a stack trace of this so it can complain without crashing. thanks

Forage commented 9 years ago

It happens when I run e.g. "python /usr/bin/pyCecClient.py" in through ssh and it's just the script breaking so I don't think this qualifies as a Kodi segfault.

It's not a problem of a second connection being opened to an adapter with an existing connection. Kodi had one open with the RPi CEC adapter. I'm connecting to an attached USB-CEC adapter (/dev/ttyACM0) which is disabled in the Kodi settings. This has worked without issues until the update I referred to.

Does the method described by MilhouseVH provide the desired stack trace? I'll give that a go tomorrow if needed.

For what it's worth: if I do steal Kodi's connection to the RPi's adapter on purpose then I didn't get a segfault in the past either. Kodi looses it's connection but python is using it happily from there on. I'll check if this is still the case after the update tomorrow as well.

MilhouseVH commented 9 years ago

Does the method described by MilhouseVH provide the desired stack trace? I'll give that a go tomorrow if needed.

Yes. If you run:

ulimit -c unlimited
python /usr/bin/pyCecClient.py

you should end up with a core dump in /storage/.cache/cores once the process has seg faulted, eg.

-rw-------    1 root     root      63127552 Jul 14 23:35 core.!usr!bin!python2.7.1436913318.8747

Your filename will be similar, but different.

Then use gdb to print the stacktrace::

gdb python --core=/storage/.cache/cores/core.!usr!bin!python2.7.1436913318.8747 --batch -ex "thread apply all bt"

should get you a stacktrace - not sure how useful the stacktraces will be as you're not using a debug build, but it's better than nothing (if you need a debug build, let me know - your FAT partition will need to be at least 384MB to use a debug build).

By the way, /usr/bin/pyCecClient.py isn't crashing for me (tested on both Pi1 and Pi2) with build #0714, but then I don't use CEC (it's disabled in Kodi), or have any additional USB CEC dongles connected (does it still crash with the dongle unplugged?)

opdenkamp commented 9 years ago

it may be a bug in the detection code. stack trace will tell. never tested it with both the pi's internal wire and a usb-cec either ;-)

Forage commented 9 years ago

Here's the output of the gdb command: http://pastebin.com/nSgw58ns Let met know if it's useful this way or if you need any more information.

When I disconnect the USB-CEC adapter then the same pyCecClient.py script will happily connect to the RPi's CEC adapter.

P.s. does ulimit -c unlimited need to be undone or is it not persistent?

MilhouseVH commented 9 years ago

P.s. does ulimit -c unlimited need to be undone or is it not persistent?

It's not persistent and only applies to that ssh session.

opdenkamp commented 9 years ago

it's a bug in https://github.com/Pulse-Eight/libcec/commit/2ac430f0f2d68a338f4f08b774482741436f23ce

Forage commented 9 years ago

I bet it's not the typo in line 49 of src/libcec/platform/drm/drm-edid.cpp ;-P

anaconda commented 9 years ago

opendir() returns NULL if the directory doesn't exist. This should fix it: https://clbin.com/sEYl5

MilhouseVH commented 9 years ago

@Forage: I have included @anaconda's patch in the latest #0901 test build - perhaps you can give it a try and report?

Forage commented 9 years ago

@MilhouseVH thanks for including it to be able to take it for a spin. @anaconda your fix works like a charm! Thank you!

opdenkamp commented 9 years ago

@anaconda could you create a PR from that patch please, and sign the dev agreement, then we can include it: http://www.pulse-eight.net/contributors

thanks!

anaconda commented 9 years ago

It seems you've merged a similar fix in #133, so this can be closed.

opdenkamp commented 9 years ago

yeah sorry, same bug got fixed in there ;-)