]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(dracut-lib.sh): remove successful finished initqueue scripts
authorMartin Wilck <mwilck@suse.com>
Wed, 3 May 2023 20:21:38 +0000 (22:21 +0200)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Mon, 5 Jun 2023 15:27:27 +0000 (17:27 +0200)
If some "finished" initscripts keep failing, dracut will start
printing warnings after a while. But it will warn about all scripts
in the finished initqueue, not only those that have failed. That
makes it difficult to identify the script that has actually
caused the failure.

To avoid this, delete finished initqueue scripts when they succeed.
Also, instead of returning as soon as one of the scripts fails, try
all scripts, deleting those that succeed, and return failure if at
least one script failed.

If a previously deleted script is recreated by some other part of
the code, it will be re-run the next time the check_finished() function
is called, and will be re-deleted if it still succeeds.

The only case where I see that this might cause issues is if some
condition needs to be tested over and over again, because it succeeds
and then fails later (for example, a device showing up and then being
removed again). But I think that this is not the intended logic.
In general, when a device shows up or another "finished" condition
is met, we assume that this condition will hold at least until the
initramfs switches root and exits. If all conditions are met, the
current code will also exit the initqueue without retrying any of
the conditions again.

modules.d/99base/dracut-lib.sh

index 14f20d78ab464adc383ebac09c15cabe80a201fa..6eaa0fe1497d5e73cf276013737b1397dcfb2568 100755 (executable)
@@ -410,13 +410,17 @@ source_hook() {
 }
 
 check_finished() {
-    local f
+    local f rc=0
     for f in "$hookdir"/initqueue/finished/*.sh; do
         [ "$f" = "$hookdir/initqueue/finished/*.sh" ] && return 0
         # shellcheck disable=SC1090
-        { [ -e "$f" ] && (. "$f"); } || return 1
+        if [ -e "$f" ] && (. "$f"); then
+            rm -f "$f"
+        else
+            rc=1
+        fi
     done
-    return 0
+    return $rc
 }
 
 source_conf() {