diff mbox series

run-postinsts: propagate exit state to run-postinsts.service

Message ID GV0P278MB0688BAE9BDECB0FBFF31582993AEA@GV0P278MB0688.CHEP278.PROD.OUTLOOK.COM
State New
Headers show
Series run-postinsts: propagate exit state to run-postinsts.service | expand

Commit Message

Germann, Bastian Dec. 12, 2025, 1:47 p.m. UTC
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>
---
 .../run-postinsts/run-postinsts/run-postinsts | 34 +++++++++++--------
 1 file changed, 20 insertions(+), 14 deletions(-)

Comments

Alexander Kanavin Dec. 12, 2025, 2:48 p.m. UTC | #1
Thanks, I think this looks fine. If it somehow doesn't make through
yocto CI tests, you'll get a notice.

Alex

On Fri, 12 Dec 2025 at 14:47, Germann, Bastian
<Bastian.Germann@duagon.com> wrote:
>
> 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>
> ---
>  .../run-postinsts/run-postinsts/run-postinsts | 34 +++++++++++--------
>  1 file changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
> index a94a769b59..b7352aa24d 100755
> --- a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
> +++ b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
> @@ -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
diff mbox series

Patch

diff --git a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
index a94a769b59..b7352aa24d 100755
--- a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
+++ b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
@@ -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