commit:     5bd81ee6cbbe582c60f0f9971dbb0b60b061b6a4
Author:     Dmitry Baranov <reagentoo <AT> gmail <DOT> com>
AuthorDate: Sat Sep  9 10:37:38 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Oct 28 01:58:52 2023 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=5bd81ee6

gen_moddeps.sh: introduce xbasename()

Introduce xbasename() wrapper to use it instead of xargs basename.
It guards from two cases:
- zero count of module names is passing from pipe
- module name starting with "-" interprets as option

Signed-off-by: Dmitry Baranov <reagentoo <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 gen_moddeps.sh | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/gen_moddeps.sh b/gen_moddeps.sh
index 6915746..556751d 100755
--- a/gen_moddeps.sh
+++ b/gen_moddeps.sh
@@ -10,6 +10,17 @@ mod_dep_list() {
        cat "${TEMP}/moddeps"
 }
 
+xbasename() {
+       local -a moddeplist=( $( </dev/stdin ) )
+
+       if (( ${#moddeplist[@]} > 0 ))
+       then
+               # prepend slash to each moddeplist element
+               # to avoid passing elements as basename options
+               basename -s "${KEXT}" "${moddeplist[@]/#/\/}"
+       fi
+}
+
 gen_dep_list() {
        local moddir="${KERNEL_MODULES_PREFIX%/}/lib/modules/${KV}"
 
@@ -60,5 +71,5 @@ gen_dep_list() {
                )
 
                printf '%s\n' "${moddeplist[@]}"
-       fi | xargs basename -s "${KEXT}" | sort | uniq
+       fi | xbasename | sort | uniq
 }

Reply via email to