Harald Hoyer 308914
From f769154bccf22d2b5caf5e4888f88bf7edde2662 Mon Sep 17 00:00:00 2001
Harald Hoyer 308914
From: Alexander Tsoy <alexander@tsoy.me>
Harald Hoyer 308914
Date: Mon, 25 May 2020 19:02:05 +0300
Harald Hoyer 308914
Subject: [PATCH] dracut-functions: fix find_binary() to return full path
Harald Hoyer 308914
Harald Hoyer 308914
Fixes: a01204202b30 (Allow running on a cross-compiled rootfs)
Harald Hoyer 308914
---
Harald Hoyer 308914
 dracut-functions.sh | 21 +++++++++++++--------
Harald Hoyer 308914
 1 file changed, 13 insertions(+), 8 deletions(-)
Harald Hoyer 308914
Harald Hoyer 308914
diff --git a/dracut-functions.sh b/dracut-functions.sh
Harald Hoyer 308914
index 3cb9c7af..b5c28248 100755
Harald Hoyer 308914
--- a/dracut-functions.sh
Harald Hoyer 308914
+++ b/dracut-functions.sh
Harald Hoyer 308914
@@ -41,31 +41,36 @@ str_ends() { [ "${1%*"$2"}" != "$1" ]; }
Harald Hoyer 308914
 # search in the usual places to find the binary.
Harald Hoyer 308914
 find_binary() {
Harald Hoyer 308914
     local _delim
Harald Hoyer 308914
+    local _path
Harald Hoyer 308914
     local l
Harald Hoyer 308914
     local p
Harald Hoyer 308914
     [[ -z ${1##/*} ]] || _delim="/"
Harald Hoyer 308914
 
Harald Hoyer 308914
     if [[ "$1" == *.so* ]]; then
Harald Hoyer 308914
         for l in libdirs ; do
Harald Hoyer 308914
-            if { $DRACUT_LDD "$dracutsysrootdir$l$_delim$1" &>/dev/null; };  then
Harald Hoyer 308914
-                printf "%s\n" "$1"
Harald Hoyer 308914
+            _path="${l}${_delim}${1}"
Harald Hoyer 308914
+            if { $DRACUT_LDD "${dracutsysrootdir}${_path}" &>/dev/null; };  then
Harald Hoyer 308914
+                printf "%s\n" "${_path}"
Harald Hoyer 308914
                 return 0
Harald Hoyer 308914
             fi
Harald Hoyer 308914
         done
Harald Hoyer 308914
-        if { $DRACUT_LDD "$dracutsysrootdir$_delim$1" &>/dev/null; }; then
Harald Hoyer 308914
-            printf "%s\n" "$1"
Harald Hoyer 308914
+        _path="${_delim}${1}"
Harald Hoyer 308914
+        if { $DRACUT_LDD "${dracutsysrootdir}${_path}" &>/dev/null; }; then
Harald Hoyer 308914
+            printf "%s\n" "${_path}"
Harald Hoyer 308914
             return 0
Harald Hoyer 308914
         fi
Harald Hoyer 308914
     fi
Harald Hoyer 308914
     if [[ "$1" == */* ]]; then
Harald Hoyer 308914
-        if [[ -L $dracutsysrootdir$_delim$1 ]] || [[ -x $dracutsysrootdir$_delim$1 ]]; then
Harald Hoyer 308914
-            printf "%s\n" "$1"
Harald Hoyer 308914
+        _path="${_delim}${1}"
Harald Hoyer 308914
+        if [[ -L ${dracutsysrootdir}${_path} ]] || [[ -x ${dracutsysrootdir}${_path} ]]; then
Harald Hoyer 308914
+            printf "%s\n" "${_path}"
Harald Hoyer 308914
             return 0
Harald Hoyer 308914
         fi
Harald Hoyer 308914
     fi
Harald Hoyer 308914
     for p in $DRACUT_PATH ; do
Harald Hoyer 308914
-        if [[ -L $dracutsysrootdir$p$_delim$1 ]] || [[ -x $dracutsysrootdir$p$_delim$1 ]];  then
Harald Hoyer 308914
-            printf "%s\n" "$1"
Harald Hoyer 308914
+        _path="${p}${_delim}${1}"
Harald Hoyer 308914
+        if [[ -L ${dracutsysrootdir}${_path} ]] || [[ -x ${dracutsysrootdir}${_path} ]];  then
Harald Hoyer 308914
+            printf "%s\n" "${_path}"
Harald Hoyer 308914
             return 0
Harald Hoyer 308914
         fi
Harald Hoyer 308914
     done
Harald Hoyer 308914