]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
check kernel module existance
authorCong Wang <xiyou.wangcong@gmail.com>
Tue, 15 May 2012 06:19:56 +0000 (14:19 +0800)
committerHarald Hoyer <harald@redhat.com>
Wed, 16 May 2012 09:43:25 +0000 (11:43 +0200)
This patch adds check of kernel module existance and
propagate errors to upper callers.

In case of break other callers of instmods(), this patch
adds an option '-c' to it, only when "-c" is specified
we fail, otherwise, errors are ignored.

Reported-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Harald Hoyer <harald@redhat.com>
dracut-functions.sh
dracut.sh
modules.d/90kernel-modules/module-setup.sh

index 8256e023ec7fafd790bd2e8276e6c1b67086baa9..4fe428ef084df72e31095b6c1aa6df50a98efc5e 100755 (executable)
@@ -1108,17 +1108,22 @@ find_kernel_modules () {
     find_kernel_modules_by_path  drivers
 }
 
-# instmods <kernel module> [<kernel module> ... ]
-# instmods <kernel subsystem>
+# instmods [-c] <kernel module> [<kernel module> ... ]
+# instmods [-c] <kernel subsystem>
 # install kernel modules along with all their dependencies.
 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
 instmods() {
     [[ $no_kernel = yes ]] && return
     # called [sub]functions inherit _fderr
     local _fderr=9
+    local _check=no
+    if [[ $1 = '-c' ]]; then
+        _check=yes
+        shift
+    fi
 
     function inst1mod() {
-        local _mod="$1"
+        local _ret=0 _mod="$1"
         case $_mod in
             =*)
                 if [ -f $srcmods/modules.${_mod#=} ]; then
@@ -1162,26 +1167,40 @@ instmods() {
                 ((_ret+=$?))
                 ;;
         esac
+        return $_ret
     }
 
     function instmods_1() {
-        local _ret=0 _mod _mpargs
+        local _mod _mpargs
         if (($# == 0)); then  # filenames from stdin
             while read _mod; do
-                inst1mod "${_mod%.ko*}"
+                inst1mod "${_mod%.ko*}" || {
+                    if [ "$_check" = "yes" ]; then
+                        dfatal "Failed to install $_mod"
+                        return 1
+                    fi
+                }
             done
         fi
         while (($# > 0)); do  # filenames as arguments
-            inst1mod ${1%.ko*}
+            inst1mod ${1%.ko*} || {
+                if [ "$_check" = "yes" ]; then
+                    dfatal "Failed to install $1"
+                    return 1
+                fi
+            }
             shift
         done
-        return $_ret
+        return 0
     }
 
-    local _filter_not_found='FATAL: Module .* not found.'
+    local _ret _filter_not_found='FATAL: Module .* not found.'
+    set -o pipefail
     # Capture all stderr from modprobe to _fderr. We could use {var}>...
     # redirections, but that would make dracut require bash4 at least.
     eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
     | while read line; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
-    return $?
+    _ret=$?
+    set +o pipefail
+    return $_ret
 }
index 2a7a812bec15120bd465b3afc8ad959aa2cc8c27..315b965e706c33a5b2f216bdc1327fed77a36478 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -708,11 +708,17 @@ for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
         [[ $show_modules = yes ]] && echo "$_d_mod" || \
             dinfo "*** Including module: $_d_mod ***"
         if [[ $kernel_only = yes ]]; then
-            module_installkernel $_d_mod
+            module_installkernel $_d_mod || {
+                dfatal "installkernel failed in module $_d_mod"
+                exit 1
+            }
         else
             module_install $_d_mod
             if [[ $no_kernel != yes ]]; then
-                module_installkernel $_d_mod
+                module_installkernel $_d_mod || {
+                    dfatal "installkernel failed in module $_d_mod"
+                    exit 1
+                }
             fi
         fi
         mods_to_load=${mods_to_load// $_d_mod /}
index 97e1de8369f4cdd3e853f742c8d82b682628bc63..b91785e1490eaada391f5240ef243dc49ad4f786 100755 (executable)
@@ -58,8 +58,12 @@ installkernel() {
         hostonly='' instmods $drivers
     fi
 
-    [[ $add_drivers ]] && hostonly='' instmods $add_drivers
-    [[ $filesystems ]] && hostonly='' instmods $filesystems
+    if [[ $add_drivers ]]; then
+        hostonly='' instmods -c $add_drivers || return 1
+    fi
+    if [[ $filesystems ]]; then
+        hostonly='' instmods -c $filesystems || return 1
+    fi
 
     # force install of scsi_wait_scan
     hostonly='' instmods scsi_wait_scan