Issue when snap uses python's ctype.util.find_library


#1

I’ve hit an issue when packaging a python app, the snap package tries to load a library that exists on the host rather than the one in snap. The app uses ctypes.util.find_library to look for the library and seems it is causing the problem.

I’ve made a simple test with this test.py and snapcraft.yaml. This test snap is very simple and does not contain any extra libraries, but if your host has libsodium, the snap will report the library can be found.

If I build the test snap with devmode confinement, then execute snap run --shell test and run ldconfig in it, and then run the test snap again, it will report libsodium cannot be found, which makes me wonder if the problem is related to ldconfig cache.

Thanks.


#2

devmode and strict mode snaps both run in their own mount namespace using the core snap as a runtime, or whatever runtime you specify with base. You’ll need to ship libsodium in your snap and then convince find_library that you have it (eg, perhaps by setting LD_LIBRARY_PATH).

This might be something with your snapcraft.yaml; perhaps @sergiusens can comment.


#3

We have a patch, our last remaining patch for python and classic confinement over at https://github.com/snapcore/snapcraft/blob/master/patches/ctypes_init.diff

The goal is to find time and create a generic solution that can be part of future versions of python and maybe backported and SRUed into Ubuntu so everyone reaps the benefits.