Fix find_binary always succeeding
PATCH 1/1 Fix find_binary always succeeding
find_binary inside dracut-functions always succeeds. Independent of whether the file actually exists or not.
This patch fixes this.
And since we're using the function not only to find binaries at little enhancement there shouldn't be that bad either.
--
dracut-functions | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
dracut-functions +16 -5
@@ -53,11 +53,21 @@ inst_library() { fi } -find_binary() { +find_file() { local binpath="/bin /sbin /usr/bin /usr/sbin" p - [[ ${1##*/} = $1 ]] || { echo $1; return 0; } + + #Full path or not? + if [[ ${1##*/} != $1 ]] ; then + if [[ -e $1 ]] ; then + echo $1; + return 0; + fi + return 1; + fi + + #Search in path for p in $binpath; do - [[ -x $p/$1 ]] && { echo "$p/$1"; return 0; } + [[ -e $p/$1 ]] && { echo "$p/$1"; return 0; } done return 1 }
@@ -96,7 +106,7 @@ inst_binary() { continue } inst_library "$FILE" - done < <(ldd $bin 2>/dev/null) + done < <(ldd $bin) inst_simple "$bin" "$target" }
@@ -134,7 +144,8 @@ inst() { echo "usage: inst <file> <root> [<destination file>]" return 1 fi - local src=$(find_binary "$1") || { + local src=$(find_file "$1") + [[ $src ]] || { echo "Cannot find requested file $1. Exiting." exit 1 }
--
To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Seewer Philippe
find_binaryinside dracut-functions always succeeds. Independent of whether the file actually exists or not.This patch fixes this.
And since we're using the function not only to find binaries at little enhancement there shouldn't be that bad either.
[snip patch]
Hmmm... a bit wordy. Why not
dracut-functions +3 -3
@@ -53,9 +53,9 @@ inst_library() { fi } -find_binary() { +find_file() { local binpath="/bin /sbin /usr/bin /usr/sbin" p - [[ ${1##*/} = $1 ]] || { echo $1; return 0; } + [[ ${1##*/} != $1 && -e $1 ]] && { echo $1; return 0; } for p in $binpath; do [[ -x $p/$1 ]] && { echo "$p/$1"; return 0; } done
@@ -134,7 +134,7 @@ inst() { echo "usage: inst <file> <root> [<destination file>]" return 1 fi - local src=$(find_binary "$1") || { + local src=$(find_file "$1") || { echo "Cannot find requested file $1. Exiting." exit 1 }
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 8 lines
Victor Lowther RHCE# 805008539634727 LPIC-2# LPI000140019 -- To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html