Change in osmo-gsm-tester[master]: misc: Use RPATH to avoid having tests to set LD_LIBRARY_PATH

Holger Freyther gerrit-no-reply at lists.osmocom.org
Sun Nov 4 14:50:07 UTC 2018


Holger Freyther has uploaded this change for review. ( 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, 22 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/80/11580/1

diff --git a/contrib/jenkins-build-common.sh b/contrib/jenkins-build-common.sh
index 17ab7df..63058eb 100644
--- a/contrib/jenkins-build-common.sh
+++ b/contrib/jenkins-build-common.sh
@@ -175,6 +175,27 @@
         done
 }
 
+add_rpath() {
+	# Adds an RPATH to executables in bin/ or sbin/ to search for the
+	# (Osmocom) libraries in `basepath /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.
+
+	# 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 +211,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: newchange
Gerrit-Change-Id: If771767dd82662e13b6b10ee7a8b8d0c84dcbdb1
Gerrit-Change-Number: 11580
Gerrit-PatchSet: 1
Gerrit-Owner: Holger Freyther <holger at freyther.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181104/d848e2e6/attachment.html>


More information about the gerrit-log mailing list