]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
run-postinsts: propagate exit state to run-postinsts.service
authorGermann, Bastian <Bastian.Germann@duagon.com>
Fri, 12 Dec 2025 13:47:07 +0000 (13:47 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 15 Dec 2025 18:00:31 +0000 (18:00 +0000)
In case an exec_postinst_scriptlets child process fails during installation we
want indication that the run-postinsts.service had a problem.

We still try to install all scriptlets and only run remove_rcsd_link if all
postinst scripts ran without error. Otherwise on every following boot a new
install attempt of the missing scriptlet(s) is performed.

Signed-off-by: Bastian Germann <Bastian.Germann@duagon.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts

index a94a769b590d13155ac3d385d9e2918f64204d41..b7352aa24df078c0205c4639d52924f299b34812 100755 (executable)
@@ -62,22 +62,29 @@ if [ "$POSTINST_LOGGING" = "1" ]; then
 fi
 
 exec_postinst_scriptlets() {
-       for i in `ls $pi_dir`; do
-               i=$pi_dir/$i
+       ret=0
+       for i in "$pi_dir"/*; do
                echo "Running postinst $i..."
                [ "$POSTINST_LOGGING" = "1" ] && eval echo "Running postinst $i..." $append_log
-               if [ -x $i ]; then
-                       (sh -c $i $append_log)
-                       rm $i
+               if [ -x "$i" ]; then
+                       (sh -c "$i" $append_log)
+                       status=$?
+                       if [ $status -ne 0 ]; then
+                               echo "ERROR: postinst $i failed with exit code $status."
+                               [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed with exit code $status." $append_log
+                               ret=1
+                       else
+                               rm -f "$i"
+                       fi
                else
-                       echo "ERROR: postinst $i failed."
-                       [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
-                       remove_rcsd_link=0
+                       echo "ERROR: postinst $i is not executable."
+                       [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i is not executable." $append_log
+                       ret=1
                fi
        done
+       return $ret
 }
 
-remove_rcsd_link=1
 if $pm_installed; then
        case $pm in
                "ipk")
@@ -96,10 +103,9 @@ if $pm_installed; then
                        ;;
        esac
 else
-       exec_postinst_scriptlets
-fi
-
-# since all postinstalls executed successfully, remove the rcS.d link
-if [ $remove_rcsd_link = 1 ]; then
+       if ! exec_postinst_scriptlets; then
+               exit 1
+       fi
+       # since all postinstalls executed successfully, remove the rcS.d link
        remove_rcsd_link
 fi