From 09a19bb1ba221bbac31d9d2932d0507c2d643399 Mon Sep 17 00:00:00 2001 From: Michal Soltys Date: Tue, 10 May 2011 14:36:23 +0200 Subject: [PATCH] dracut-functions: update inst_binary() This update adds support for sort-of corner case - when explicitly specified binary (e.g. through dracut_install or inst) is a library itself. In such case, we would expect the binary to undergo typical library-related handling (symlinks and such). Apart from that, the patch cleans indenting and a few unused variables in inst_binary() (probably leftovers from the past ?) Signed-off-by: Michal Soltys --- dracut-functions | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/dracut-functions b/dracut-functions index 41187e0..959c1d3 100755 --- a/dracut-functions +++ b/dracut-functions @@ -32,9 +32,6 @@ if ! type dinfo >/dev/null 2>&1; then dlog_init fi -IF_RTLD="" -IF_dynamic="" - # Generic substring function. If $2 is in $1, return 0. strstr() { [[ $1 =~ $2 ]]; } @@ -330,14 +327,20 @@ find_binary() { # Same as above, but specialized to install binary executables. # Install binary executable, and all shared library dependencies, if any. inst_binary() { - local bin target + local bin target f self so_regex lib_regex TLIBDIR BASE FILE + bin=$(find_binary "$1") || return 1 target=${2:-$bin} inst_symlink $bin $target && return 0 - local LDSO NAME IO FILE ADDR I1 n f TLIBDIR [[ -e $initdir$target ]] && return 0 + + # If the binary being installed is also a library, add it to the loop. + so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)' + [[ $bin =~ $so_regex ]] && self="\t${bin##*/} => ${bin} (0x0)\n" + + lib_regex='^(/lib[^/]*).*' # I love bash! - LC_ALL=C ldd $bin 2>/dev/null | while read line; do + { LC_ALL=C ldd $bin 2>/dev/null; echo -en "$self"; } | while read line; do [[ $line = 'not a dynamic executable' ]] && return 1 if [[ $line =~ not\ found ]]; then dfatal "Missing a shared library required by $bin." @@ -345,28 +348,28 @@ inst_binary() { dfatal "dracut cannot create an initrd." exit 1 fi - so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)' [[ $line =~ $so_regex ]] || continue FILE=${BASH_REMATCH[1]} [[ -e ${initdir}$FILE ]] && continue - # see if we are loading an optimized version of a shared lib. - lib_regex='^(/lib[^/]*).*' + + # See if we are loading an optimized version of a shared lib. if [[ $FILE =~ $lib_regex ]]; then TLIBDIR=${BASH_REMATCH[1]} BASE=${FILE##*/} - # prefer nosegneg libs, then unoptimized ones. + # Prefer nosegneg libs to unoptimized ones. for f in "$TLIBDIR/i686/nosegneg" "$TLIBDIR"; do [[ -e $f/$BASE ]] || continue FILE=$f/$BASE break done inst_library "$FILE" "$TLIBDIR/$BASE" - IF_dynamic=yes - continue - fi + else inst_library "$FILE" + fi done - inst_simple "$bin" "$target" + + # Install the binary if it wasn't handled in the above loop. + [[ -z $self ]] && inst_simple "$bin" "$target" } # same as above, except for shell scripts. -- 2.7.4