[arch-projects] [RFCv2] [PATCH] Fix add_binary() when -b BASEDIR is used.
Gerardo Exequiel Pozzi
vmlinuz386 at yahoo.com.ar
Mon Nov 21 16:59:05 EST 2011
RFC: Use chroot command to execute ldd. (needs root)
RFCv2: Use LD_LIBRARY_PATH= enviroment variable to execute ldd (not needs root).
NOTE1: this still has at least one issue (I guess), when a binary has RPATH set,
in that case LD_LIBRARY_PATH is secondary in case that RPATH fails.
There is a way to ignore-rpath but needs to execute ld-linux directly,
ldd script does not support passing --inhibit-rpath, but this option is
ignored if non-root user use it on set-uid binary.
NOTE2: LD_LIBRARY_PATH is ignored if binary is set-uid,
non-root user will see different behaviour than root.
mkinitcpio fails silently when a binary is installed on $BASEDIR
(for example $BASEDIR/usr/bin/curl with all sodeps) but outside $BASEDIR curl
and deps is not installed.
----
A simple hook
build() {
add_binary "/usr/bin/curl"
}
----
Before the fix:
-> Parsing hook: [curl]
adding file: /usr/bin/curl
adding symlink: /lib/librt.so.1 -> /lib/librt-2.14.1.so
adding file: /lib/librt-2.14.1.so
adding dir: /usr/lib
adding symlink: /usr/lib/libz.so.1 -> /usr/lib/libz.so.1.2.5
adding file: /usr/lib/libz.so.1.2.5
adding symlink: /lib/libpthread.so.0 -> /lib/libpthread-2.14.1.so
adding file: /lib/libpthread-2.14.1.so
With this fix applied:
-> Parsing hook: [curl]
adding file: /usr/bin/curl
adding dir: /usr/lib
adding symlink: /usr/lib/libcurl.so.4 -> /usr/lib/libcurl.so.4.2.0
adding file: /usr/lib/libcurl.so.4.2.0
adding symlink: /lib/librt.so.1 -> /lib/librt-2.14.1.so
adding file: /lib/librt-2.14.1.so
adding symlink: /usr/lib/libz.so.1 -> /usr/lib/libz.so.1.2.5
adding file: /usr/lib/libz.so.1.2.5
adding symlink: /lib/libpthread.so.0 -> /lib/libpthread-2.14.1.so
adding file: /lib/libpthread-2.14.1.so
adding symlink: /usr/lib/libssh2.so.1 -> /usr/lib/libssh2.so.1.0.1
adding file: /usr/lib/libssh2.so.1.0.1
adding file: /usr/lib/libssl.so.1.0.0
adding file: /usr/lib/libcrypto.so.1.0.0
adding symlink: /lib/libdl.so.2 -> /lib/libdl-2.14.1.so
adding file: /lib/libdl-2.14.1.so
---
functions | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/functions b/functions
index ef4463e..8a14485 100644
--- a/functions
+++ b/functions
@@ -300,7 +300,11 @@ add_binary() {
# always add the binary itself
_add_file "${dest#$BASEDIR}" "$binary" "$mode"
- lddout=$(ldd "$binary" 2>/dev/null) || return 1 # not a binary!
+ if [[ -z $BASEDIR ]]; then
+ lddout=$(ldd "$binary" 2>/dev/null) || return 1 # not a binary!
+ else
+ lddout=$(LD_LIBRARY_PATH=$BASEDIR/lib:$BASEDIR/usr/lib ldd "$binary" 2>/dev/null) || return 1 # not a binary!
+ fi
# resolve sodeps
regex='(/.+) \(0x[a-fA-F0-9]+\)'
@@ -309,12 +313,12 @@ add_binary() {
if [[ -f "$sodep" ]]; then # -f follows symlinks, don't believe it!
if [[ ! -L $sodep ]]; then
- _add_file "$sodep" "$BASEDIR$sodep" "$(stat -c %a "$sodep")"
+ _add_file "${sodep#$BASEDIR}" "$sodep" "$(stat -c %a "$sodep")"
else
- resolved=$(readlink -e "$BASEDIR$sodep")
+ resolved=$(readlink -e "$sodep")
dirname=${resolved%/*}
_add_dir "${dirname#$BASEDIR}" 755
- _add_symlink "$sodep" "${resolved#$BASEDIR}"
+ _add_symlink "${sodep#$BASEDIR}" "${resolved#$BASEDIR}"
_add_file "${resolved#$BASEDIR}" "$resolved" 755
fi
fi
--
1.7.7.3
More information about the arch-projects
mailing list