Holger Freyther has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/11580 )

Change subject: misc: Use RPATH to avoid having tests to set LD_LIBRARY_PATH
......................................................................

misc: Use RPATH to avoid having tests to set LD_LIBRARY_PATH

Instead of each binary launcher having to check if there is a lib/
directory and then setting a LD_LIBRARY_PATH we can use an RPATH and
know these binaries pick-up the right libraries.

This requires I6e4ad2e3855af7bcefc22d4190cc4e6f58581857.

Change-Id: If771767dd82662e13b6b10ee7a8b8d0c84dcbdb1
---
M contrib/jenkins-build-common.sh
1 file changed, 26 insertions(+), 0 deletions(-)

Approvals:
  Pau Espin Pedrol: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/contrib/jenkins-build-common.sh b/contrib/jenkins-build-common.sh
index 17ab7df..a9eaf7a 100644
--- a/contrib/jenkins-build-common.sh
+++ b/contrib/jenkins-build-common.sh
@@ -175,6 +175,31 @@
         done
 }

+add_rpath() {
+       # Adds an RPATH to executables in bin/ or sbin/ to search for the
+       # (Osmocom) libraries in `dirname /proc/self/exe`/../lib/. Adds an
+       # RPATH to a library to search in the same directory as the library.
+       #
+       # NOTE: Binaries should not have the SUID bit set and should run as the
+       # user executing the binary.
+       #
+       # NOTE: $ORIGIN is not a shell variable but a feature of the dynamic
+       # linker that will be expanded at runtime. For details see:
+       # http://man7.org/linux/man-pages/man8/ld.so.8.html
+       #
+       # Add an rpath relative to the binary and library if the directory
+       # exists.
+       if [ -d bin/ ]; then
+               find bin -depth -type f -exec patchelf --set-rpath 
'$ORIGIN/../lib/' {} \;
+       fi
+       if [ -d sbin/ ]; then
+               find sbin -depth -type f -exec patchelf --set-rpath 
'$ORIGIN/../lib/' {} \;
+       fi
+       if [ -d lib/ ]; then
+               find lib -depth -type f -name "lib*.so.*" -exec patchelf 
--set-rpath '$ORIGIN/' {} \;
+       fi
+}
+
 create_bin_tgz() {
   # build the archive that is going to be copied to the tester

@@ -190,6 +215,7 @@
   prune_files sbin "$wanted_binaries_sbin"

   cd "$prefix_real"
+  add_rpath
   this="$name.build-${BUILD_NUMBER-$(date +%Y-%m-%d_%H_%M_%S)}"
   tar="${this}.tgz"
   tar czf "$base/$tar" *

--
To view, visit https://gerrit.osmocom.org/11580
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: If771767dd82662e13b6b10ee7a8b8d0c84dcbdb1
Gerrit-Change-Number: 11580
Gerrit-PatchSet: 4
Gerrit-Owner: Holger Freyther <[email protected]>
Gerrit-Reviewer: Holger Freyther <[email protected]>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <[email protected]>

Reply via email to