scripts: bundle-libraries.sh: retain preloaded libraries
authorJo-Philipp Wich <jo@mein.io>
Thu, 10 Sep 2020 11:55:48 +0000 (13:55 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 10 Sep 2020 12:24:50 +0000 (14:24 +0200)
Since the introduction of fakeroot support, wrapped SDK executables might
be invoked from a shell that has libfakeroot.so preloaded.

Since we're using preloading as well in order to mangle argv[0] when
invoking the shipped ELF interpreter directly, we must take care of
preloading the already preloaded libraries as well, to avoid invoked
programs losing their fakeroot capabilities.

Extend the bundle-libraries.sh script to take any existing $LD_PRELOAD
into account when invoking the target ELF executable with a preloaded
runas.so library.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
scripts/bundle-libraries.sh

index d3c7206a4dddd2b44a5b7d506f88212de850e0b4..9efcbbd0b20e9eccaba51705f3b7776cd91efc70 100755 (executable)
@@ -186,7 +186,7 @@ for BIN in "$@"; do
                        #!/usr/bin/env bash
                        dir="\$(dirname "\$0")"
                        export RUNAS_ARG0="\$0"
-                       export LD_PRELOAD="\$dir/${REL:+$REL/}runas.so"
+                       export LD_PRELOAD="\${LD_PRELOAD:+\$LD_PRELOAD:}\$dir/${REL:+$REL/}runas.so"
                        exec "\$dir/${REL:+$REL/}$LDSO" --library-path "\$dir/${REL:+$REL/}" "\$dir/.${BIN##*/}.bin" "\$@"
                EOF