Skip to content

Instantly share code, notes, and snippets.

@wvengen
Last active August 1, 2022 07:08
Show Gist options
  • Save wvengen/2c36d2083556b52ea351ebe98cad0f9a to your computer and use it in GitHub Desktop.
Save wvengen/2c36d2083556b52ea351ebe98cad0f9a to your computer and use it in GitHub Desktop.
Using trickle with Flatpak applications

Trickle is a command-line tool to throttle network bandwidth of other applications. You use it on the command-line to start the application. It uses LD_PRELOAD to override network-related calls. As a result, using it with containerized apps, like Flatpak, does not work out of the box.

To get trickle to function with a Flatpak application, the preloaded library needs to be available in the container. And it needs to be compatible with the software in the container (notably, a glibc version that is compatible).

First try

  1. Install trickle on your (host) system, on Debian/Ubuntu that would be apt install trickle.
  2. Make sure you have the flatpak application installed. I'm using com.slack.Slack as an example here.
  3. Run the flatpak application with trickle
    trickle -s -d 250 -u 250 flatpak run com.slack.Slack
    
  4. Find out it doesn't work. Error message:
    ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/trickle/trickle-overload.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
    

Second try

  1. (as above)
  2. (as above)
  3. Find out what runtime the flatpak application uses. flatpak info com.slack.Slack, e.g. org.freedesktop.Platform/x86_64/21.08
  4. Copy the trickle library to the runtime
    RUNTIME=`flatpak info com.slack.Slack | sed 's/^\s*Runtime:\s*//p;d'`
    cd "/var/lib/flatpak/runtime/$RUNTIME/active/files/lib/x86_64-linux-gnu"
    sudo mkdir trickle
    sudo ln /usr/lib/x86_64-linux-gnu/trickle/trickle-overload.so trickle # use cp on different filesystem
    
  5. Run the flatpak with trickle (as above)
  6. Find out it still doesn't work
    /bin/sh: /usr/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /usr/lib/x86_64-linux-gnu/trickle/trickle-overload.so)
    

You can find out which GLIBC version a library needs using objdump -T. Running it on the system's trickle library, we find

$ objdump -T /usr/lib/x86_64-linux-gnu/trickle/trickle-overload.so | grep GLIBC
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.2.5) getenv
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.3.4) __snprintf_chk
...
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.4)  __stack_chk_fail
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.15) __fdelt_chk
...
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.34) dlsym
0000000000000000      DF *UND*	0000000000000000 (GLIBC_2.2.5) exit

You see that there is one external symbol that needs glibc 2.34, hence the requirement or this minimum version.

Third try

  1. (as above)
  2. (as above)
  3. Download a binary package of trickle for an older operating system. Debian stretch will do here (package). Extract the library.
    wget http://ftp.de.debian.org/debian/pool/main/t/trickle/trickle_1.07-10+b1_amd64.deb
    mkdir trickle-stretch
    dpkg-deb -x trickle_1.07-10+b1_amd64.deb trickle-stretch
    sudo cp trickle-stretch/usr/lib/trickle/trickle-overload.so /tmp
    
  4. Copy the older library to the flatpak runtime
    RUNTIME=`flatpak info com.slack.Slack | sed 's/^\s*Runtime:\s*//p;d'`
    cd "/var/lib/flatpak/runtime/$RUNTIME/active/files/lib/x86_64-linux-gnu"
    sudo mkdir -p trickle
    sudo cp /tmp/trickle-overload.so trickle/
    
  5. Run the flatpak application with trickle
    trickle -s -d 250 -u 250 flatpak run com.slack.Slack
    
  6. Finally it runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment