opkg: retry opkg_lock
PATCH 1/1 opkg: retry opkg_lock
When systemd is enabled, we can get into a race condition between run-postinsts and systemctl restarting services.
If we fail to create the lock file (or fd), then
sleep 10 seconds and retry up to 5 times.
[YOCTO #15428]
Patch submitted upstream to opkg:
https://lists.yoctoproject.org/g/opkg/message/60
Signed-off-by Tim Orling <[email protected]>
--- ...kg_lock-retry-if-we-fail-to-get-lock.patch | 59 +++++++++++++++++++ meta/recipes-devtools/opkg/opkg_0.6.3.bb | 1 + 2 files changed, 60 insertions(+) create mode 100644 meta/recipes-devtools/opkg/opkg/0001-opkg_lock-retry-if-we-fail-to-get-lock.patch
meta/recipes-devtools/opkg/opkg/0001-opkg_lock-retry-if-we-fail-to-get-lock.patch new file +59 -0
@@ -0,0 +1,59 @@ +From cdc7d347f41a7095ba0e29515951a1394c632479 Mon Sep 17 00:00:00 2001 +From: Tim Orling <[email protected]> +Date: Wed, 20 Mar 2024 23:00:31 -0700 +Subject: [opkg][PATCH] opkg_lock: retry if we fail to get lock +To: [email protected] + +When systemd is enabled, we can get into a race condition +between run-postinsts and systemctl restarting services. + +If we fail to create the lock file (or fd), then +sleep 10 seconds and retry up to 5 times. + +[YOCTO #15428] + +Upstream-Status: Submitted [https://lists.yoctoproject.org/g/opkg/message/60] + +Signed-off-by: Tim Orling <[email protected]> +--- + libopkg/opkg_conf.c | 22 ++++++++++++++++------ + 1 file changed, 16 insertions(+), 6 deletions(-) + +diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c +index 4dc777b..03bb40a 100644 +--- a/libopkg/opkg_conf.c ++++ b/libopkg/opkg_conf.c +@@ -660,14 +660,24 @@ int opkg_lock() + return -1; + } + +- r = lockf(lock_fd, F_TLOCK, (off_t) 0); ++ int retry = 5; ++ do { ++ r = lockf(lock_fd, F_TLOCK, (off_t) 0); ++ if (r == -1) { ++ opkg_perror(INFO, "Could not lock %s, retry %d", opkg_config->lock_file, retry); ++ r = close(lock_fd); ++ if (r == -1) ++ opkg_perror(ERROR, "Couldn't close descriptor %d (%s)", lock_fd, ++ opkg_config->lock_file); ++ retry--; ++ sleep(10); ++ } ++ } ++ while (retry > 0 && r == -1); ++ + if (r == -1) { + opkg_perror(ERROR, "Could not lock %s", opkg_config->lock_file); +- r = close(lock_fd); +- if (r == -1) +- opkg_perror(ERROR, "Couldn't close descriptor %d (%s)", lock_fd, +- opkg_config->lock_file); +- lock_fd = -1; ++ lock_fd = -1; + return -1; + } + +-- +2.34.1 +
meta/recipes-devtools/opkg/opkg_0.6.3.bb +1 -0
@@ -16,6 +16,7 @@ SRC_URI = "http://downloads.yoctoproject.org/releases/${BPN}/${BPN}-${PV}.tar.gz file://opkg.conf \ file://0001-opkg_conf-create-opkg.lock-in-run-instead-of-var-run.patch \ file://0001-libopkg-Use-libgen.h-to-provide-basename-API.patch \ + file://0001-opkg_lock-retry-if-we-fail-to-get-lock.patch \ file://run-ptest \ "
Signature · 1 line
2.34.1