diff mbox series

[3/3] run-postinsts: Add workaround for locking deadlock issue

Message ID 20240329161742.910250-3-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 96d37df074dc1fe1578c1406235dff7e328b62b7
Headers show
Series [1/3] util-linux: Add missing MIT license | expand

Commit Message

Richard Purdie March 29, 2024, 4:17 p.m. UTC
When run-postinsts is installed, a service is added for system which can run
while the package is still being installed. This calls "opkg configure" and if
package management is still running, it can deadlock and error.

To work around this, call fcntl-lock on the opkg lock file and if the lock
was held, it would wait to obtain it. This wait gives the package management
time to finish the install before the configure can then take the lock and run.

Note the dependency in SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS otherwise we'd see
sstate selftest failures.

Also ensure that if the configure fails, the scripts returns an error. This
applies to opkg and dpkg.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/conf/layer.conf                                  |  1 +
 .../run-postinsts/run-postinsts/run-postinsts         | 11 +++++++++--
 .../run-postinsts/run-postinsts_1.0.bb                |  2 ++
 3 files changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/conf/layer.conf b/meta/conf/layer.conf
index 62f86f361ad..efbf2610f99 100644
--- a/meta/conf/layer.conf
+++ b/meta/conf/layer.conf
@@ -87,6 +87,7 @@  SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS += " \
   sato-icon-theme->gtk+3 \
   adwaita-icon-theme->gdk-pixbuf \
   adwaita-icon-theme->gtk+3 \
+  run-postinsts->util-linux \
 "
 
 # Avoid adding bison-native to the sysroot without a specific
diff --git a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
index 95dccb9cae1..1f3e692029c 100755
--- a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
+++ b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts
@@ -81,11 +81,18 @@  remove_rcsd_link=1
 if $pm_installed; then
 	case $pm in
 		"ipk")
-			eval opkg configure $append_log
+			if ! `fcntl-lock --wait 30 /run/opkg.lock true`; then
+				eval echo "Unable to obtain the opkg lock, deadlock?" $append_log
+			fi
+			if ! eval "opkg configure $append_log"; then
+			    exit 1
+			fi
 			;;
 
 		"deb")
-			eval dpkg --configure -a $append_log
+			if ! eval "eval dpkg --configure -a $append_log"; then
+			    exit 1
+			fi
 			;;
 	esac
 else
diff --git a/meta/recipes-devtools/run-postinsts/run-postinsts_1.0.bb b/meta/recipes-devtools/run-postinsts/run-postinsts_1.0.bb
index 72ba8c02270..e977942de87 100644
--- a/meta/recipes-devtools/run-postinsts/run-postinsts_1.0.bb
+++ b/meta/recipes-devtools/run-postinsts/run-postinsts_1.0.bb
@@ -12,6 +12,8 @@  S = "${WORKDIR}"
 
 inherit allarch systemd update-rc.d
 
+RDEPENDS:${PN} = "util-linux-fcntl-lock"
+
 INITSCRIPT_NAME = "run-postinsts"
 INITSCRIPT_PARAMS = "start 99 S ."