[arch-projects] [RFC] [PATCH] [mkinitcpio] Fix add_binary() when -b BASEDIR is used.

Gerardo Exequiel Pozzi vmlinuz386 at yahoo.com.ar
Mon Nov 21 10:09:38 EST 2011


On 11/21/2011 11:11 AM, Dave Reisner wrote:
> On Mon, Nov 21, 2011 at 02:36:17AM -0300, Gerardo Exequiel Pozzi wrote:
>> Maybe the fix is wrong because the usage of chroot? Please review.
>>
>> 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
>>
> Yeah that's definitely wrong.
>
>> 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..78d62d5 100644
>> --- a/functions
>> +++ b/functions
>> @@ -300,16 +300,20 @@ 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=$(chroot $BASEDIR ldd "${binary#$BASEDIR}" 2>/dev/null) || return 1 # not a binary!
> Nope -- we can't use chroot. I don't want to require root for generating
> images (even if it is only for -b). I'll take a look at this when I get a chance.
I guessed that. Ok, the other way that I see is using 
LD_LIBRARY_PATH=$BASEDIR/lib:$BASEDIR/usr/lib... ldd ...
but is not perfect: binaries with RPATH (malo malo!), will fail.

Thanks.
>
>> +    fi
>>
>>       # resolve sodeps
>>       regex='(/.+) \(0x[a-fA-F0-9]+\)'
>>       while read line; do
>>           [[ "$line" =~ $regex ]]&&  sodep=${BASH_REMATCH[1]} || continue
>>
>> -        if [[ -f "$sodep" ]]; then # -f follows symlinks, don't believe it!
>> -            if [[ ! -L $sodep ]]; then
>> -                _add_file "$sodep" "$BASEDIR$sodep" "$(stat -c %a "$sodep")"
>> +        if [[ -f "$BASEDIR$sodep" ]]; then # -f follows symlinks, don't believe it!
>> +            if [[ ! -L $BASEDIR$sodep ]]; then
>> +                _add_file "$sodep" "$BASEDIR$sodep" "$(stat -c %a "$BASEDIR$sodep")"
>>               else
>>                   resolved=$(readlink -e "$BASEDIR$sodep")
>>                   dirname=${resolved%/*}
>> -- 
>> 1.7.7.3
>>


-- 
Gerardo Exequiel Pozzi
\cos^2\alpha + \sin^2\alpha = 1



More information about the arch-projects mailing list