]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix: remove basename calls main
authorBenjamin Drung <benjamin.drung@canonical.com>
Wed, 22 Jul 2026 10:05:13 +0000 (12:05 +0200)
committerdevkontrol <dev@kontrol.dev>
Thu, 23 Jul 2026 10:33:40 +0000 (06:33 -0400)
https://dracut-ng.github.io/dracut/developer/bash.html says that
`basename` should not be used.

So replace the usage of `basename` by variable expansion instead.

dracut-functions.sh
modules.d/45drm/module-setup.sh
modules.d/45simpledrm/module-setup.sh
modules.d/45url-lib/url-lib.sh
modules.d/71systemd-cryptsetup/module-setup.sh

index f162c27ee168a9258ac0de57d5120134d1b7387d..0dd18e86a85ada920abb4434bbe0dcbf754b062e 100755 (executable)
@@ -651,7 +651,7 @@ get_blockdev_drv_through_sys() {
     while :; do
         if [[ -L "$_path"/driver/module ]]; then
             _mod=$(realpath "$_path"/driver/module)
     while :; do
         if [[ -L "$_path"/driver/module ]]; then
             _mod=$(realpath "$_path"/driver/module)
-            _mod=$(basename "$_mod")
+            _mod="${_mod##*/}"
             _block_mods="$_block_mods $_mod"
         fi
         _path="${_path%/*}"
             _block_mods="$_block_mods $_mod"
         fi
         _path="${_path%/*}"
@@ -972,8 +972,8 @@ block_is_fcoe() {
     until [[ -d "$_dir/sys" ]]; do
         _dir="$_dir/.."
         if [[ -d "$_dir/subsystem" ]]; then
     until [[ -d "$_dir/sys" ]]; do
         _dir="$_dir/.."
         if [[ -d "$_dir/subsystem" ]]; then
-            subsystem=$(basename "$(readlink "$_dir"/subsystem)")
-            [[ $subsystem == "fcoe" ]] && return 0
+            subsystem=$(readlink "$_dir"/subsystem)
+            [[ ${subsystem##*/} == "fcoe" ]] && return 0
         fi
     done
     return 1
         fi
     done
     return 1
index 45a458681f68d983e44234c4e91fc5b855241cb4..17f7ebc2efe2031c8c9515b6654c8955ce32682a 100755 (executable)
@@ -46,7 +46,7 @@ installkernel() {
         for i in /sys/class/drm/privacy_screen-*/device/driver/module; do
             [[ -L $i ]] || continue
             modlink=$(readlink "$i")
         for i in /sys/class/drm/privacy_screen-*/device/driver/module; do
             [[ -L $i ]] || continue
             modlink=$(readlink "$i")
-            modname=$(basename "$modlink")
+            modname="${modlink##*/}"
             hostonly=$(optional_hostonly) instmods "$modname"
         done
     else
             hostonly=$(optional_hostonly) instmods "$modname"
         done
     else
index 7ce98ca411bc60252fe5ffd2ce40bd03753ab94f..0681b6aa5dbeab0bca27ca0562b21147f0618032 100755 (executable)
@@ -17,7 +17,7 @@ installkernel() {
         for i in /sys/class/drm/privacy_screen-*/device/driver/module; do
             [[ -L $i ]] || continue
             modlink=$(readlink "$i")
         for i in /sys/class/drm/privacy_screen-*/device/driver/module; do
             [[ -L $i ]] || continue
             modlink=$(readlink "$i")
-            modname=$(basename "$modlink")
+            modname="${modlink##*/}"
             hostonly='' instmods "$modname"
         done
     else
             hostonly='' instmods "$modname"
         done
     else
index f8d5480f3539019a2298bfdbd5c83ed5956da8b7..317db5a6c25510adf1e7193e83c2672cebef8052 100755 (executable)
@@ -160,7 +160,7 @@ nfs_fetch_url() {
         mntdir="$(mkuniqdir /run nfs_mnt)"
         mount_nfs "$nfs:$server:$filepath${options:+:$options}" "$mntdir"
         # lazy unmount during pre-pivot hook
         mntdir="$(mkuniqdir /run nfs_mnt)"
         mount_nfs "$nfs:$server:$filepath${options:+:$options}" "$mntdir"
         # lazy unmount during pre-pivot hook
-        inst_hook --hook pre-pivot --name 99url-lib-umount-nfs-"$(basename "$mntdir")" umount -l -- "$mntdir"
+        inst_hook --hook pre-pivot --name 99url-lib-umount-nfs-"${mntdir##*/}" umount -l -- "$mntdir"
     fi
 
     if [ -z "$outloc" ]; then
     fi
 
     if [ -z "$outloc" ]; then
index 65d729e60c97b6ede80eed4e72c2f0e4a5d9f7f3..4bad1effe026629be3c75ac39444a89d32a4fc5f 100755 (executable)
@@ -121,7 +121,7 @@ install() {
                         "the service unit may encounter a deadlock due to a circular dependency"
                 fi
 
                         "the service unit may encounter a deadlock due to a circular dependency"
                 fi
 
-                socket_unit_basename=$(basename "$socket_unit")
+                socket_unit_basename="${socket_unit##*/}"
                 inst_multiple -H -o \
                     "$systemdsystemunitdir"/sockets.target.wants/"$socket_unit_basename" \
                     "$systemdsystemconfdir"/sockets.target.wants/"$socket_unit_basename"
                 inst_multiple -H -o \
                     "$systemdsystemunitdir"/sockets.target.wants/"$socket_unit_basename" \
                     "$systemdsystemconfdir"/sockets.target.wants/"$socket_unit_basename"