LD_PRELOAD causing issues in Enigma2 spawned children

Issue #602 resolved
IanSav created an issue

I am trying to create a feed server to serve the OverlayHD skin and any other future packages I write for the Beyonwiz and OpenViX communities. I have a test environment on my internal web server and a production environment on the BitBucket web server. My test server uses the http protocol while the production server uses https.

I can use the "opkg update" command from the Enigma2 command line on both servers and it runs to completion without error:

root@beyonwizt3:~# opkg update
Downloading http://feeds.beyonwiz.org/beyonwiz/17.5/inihdx/3rdparty/Packages.gz.
Updated source 'beyonwiz-3rdparty'.
Downloading https://iansav.bitbucket.io/feeds/Packages.gz.
Updated source 'IanSav-Plugins'.
Downloading http://feeds.beyonwiz.org/beyonwiz/17.5/inihdx/all/Packages.gz.
Updated source 'beyonwiz-all'.
Downloading http://feeds.beyonwiz.org/beyonwiz/17.5/inihdx/beyonwizt3/Packages.gz.
Updated source 'beyonwiz-beyonwizt3'.
Downloading http://feeds.beyonwiz.org/beyonwiz/17.5/inihdx/inihdx/Packages.gz.
Updated source 'beyonwiz-inihdx'.
Downloading http://feeds.beyonwiz.org/beyonwiz/17.5/inihdx/inihdx_3rdparty/Packages.gz.
Updated source 'beyonwiz-inihdx_3rdparty'.
Downloading http://feeds.beyonwiz.org/beyonwiz/17.5/inihdx/mips32el/Packages.gz.
Updated source 'beyonwiz-mips32el'.

When I point opkg to my test feed and run "MENU > Setup > Software manager > Check for updates now" everything works fine. However, when I point opkg to my production feed I get an error that results in the message "Can not retrieve data from feed server. Check your Internet connection and try again later.". I believe this message is being generated from line 70 of "Screens/SoftwareUpdate.py". This is basically reporting that the "opkg update" command is returning a message containing 'wget returned 1' or 'wget returned 255' or '404 Not Found'. As demonstrated above this is NOT what I get when I manually run the opkg command.

With the assistance of IanB we believe the problem is caused by the environment LD_PRELOAD=/usr/lib/ libopen.so.0.0.0 in the enigma2.sh launch script.

The libopen.so.0.0.0 library is a tools stub that was created by Andreas Monzner and committed Oct 18, 2006. It overrides all the libc open/fopen calls in an application and sets the FD_CLOEXEC flag on the returned fd so they cannot leak into any child processes. This library is invoked in the Enigma2 startup shell script.

The gotcha is the LD_PRELOAD environment is inherited by all child processes spawned from enigma2 like the calls to opkg. Opkg calls wget to do it's repository file fetching. Busybox wget calls out to openssl to do it's https handling and, you guessed it, the opened stdin and stdout fd's are of course flagged as closed on exec. This causes the opkg to fail when connecting to https sites within Enigma2 or any environment where the LD_PRELOAD environment in in effect.

The fact that we found this bug in my call to opkg is just a example failure. The underlying bug could cause erratic behaviour is any programs launched from within Enigma2. For example, a shell script that pipes output from one command to another will also fail.

From the OpenViX developers I have learned that this tool stub was put there to limit the number of file handles created in Enigma2 from being propagated to any and all of its children. This controls the number of file handles that must be managed by the kernel.

To address this issue Enigma2 probably should unset the LD_PRELOAD environment before it spawns child processes.

Any fix to the Beyonwiz repository should also be replicated to the OpenViX repository.

Comments (1)

  1. Log in to comment