commit:     77abf7456bf0af2b145e44a0148fcecae882b9b9
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 28 23:25:31 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Mon Jul 29 20:00:27 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=77abf745

gen_funcs.sh: Refactor get_chost_libdir() error handling

We need to check each returned value because last call to
dirname() would return "." when called for an empty path
caused by a previous failure.

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 gen_funcs.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gen_funcs.sh b/gen_funcs.sh
index a1fe98a..59c7507 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -736,9 +736,21 @@ debug_breakpoint() {
 
 get_chost_libdir() {
        local cc=$(tc-getCC)
-       local libdir=$(dirname "$(realpath "$(${cc} 
-print-file-name=libnss_files.so)")")
 
-       if [[ -z "${libdir}" ]]
+       local test_file=$("${cc}" -print-file-name=libnss_files.so 2>/dev/null)
+       if [ -z "${test_file}" ]
+       then
+               gen_die "$(get_useful_function_stack "${FUNCNAME}")Unable to 
determine CHOST's libdir: '${cc} -print-file-name=libnss_files.so' returned 
nothing!"
+       fi
+
+       local test_file_realpath=$(realpath "${test_file}" 2>/dev/null)
+       if [ -z "${test_file_realpath}" ]
+       then
+               gen_die "$(get_useful_function_stack "${FUNCNAME}")Unable to 
determine CHOST's libdir: 'realpath \"${test_file}\"' returned nothing!"
+       fi
+
+       local libdir=$(dirname "${test_file_realpath}" 2>/dev/null)
+       if [ -z "${libdir}" ]
        then
                gen_die "$(get_useful_function_stack "${FUNCNAME}")Unable to 
determine CHOST's libdir!"
        fi

Reply via email to