summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/opkg/opkg/0001-Add-retry-get-lock-argument.patch
blob: 1e9b4893ce55c25876ac46976e26c3e2752cff39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
From a87e269f4aa9843c5a44d69736f3faa223a036a0 Mon Sep 17 00:00:00 2001
From: TIm Orling <tim.orling@konsulko.com>
Date: Wed, 27 Mar 2024 22:15:44 -0700
Subject: [PATCH] Add --retry-get-lock argument

When running post install scripts with systemd run-postinsts.service in
OpenEmbedded, we often see a race condition where the service is being
restarted before the run-postints script is complete:

meta/lib/oeqa/runtime/cases/opkg.py

    def test_opkg_install_from_repo(self):
        self.setup_source_config_for_package_install()
        self.pkg('update')
        self.pkg('remove run-postinsts-dev')
        self.pkg('install run-postinsts-dev')
        self.cleanup_source_config_for_package_install()

Which is trying to run:
- opkg update
- opkg remove run-postinsts-dev
- opkg install run-postinsts-dev
- opkg configure

[YOCTO #15428]

Upstream-Status: Pending
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 libopkg/opkg_conf.c |  8 +++++++-
 src/opkg.c          | 10 +++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c
index c2e1c2f..cb6300a 100644
--- a/libopkg/opkg_conf.c
+++ b/libopkg/opkg_conf.c
@@ -90,6 +90,7 @@ static opkg_option_t options[] = {
     {"cache_local_files", OPKG_OPT_TYPE_BOOL, &_conf.cache_local_files},
     {"verbose_status_file", OPKG_OPT_TYPE_BOOL, &_conf.verbose_status_file},
     {"compress_list_files", OPKG_OPT_TYPE_BOOL, &_conf.compress_list_files},
+    {"retry_get_lock", OPKG_OPT_TYPE_BOOL, &_conf.retry_get_lock},
 #if defined(HAVE_GPGME)
     {"gpg_dir", OPKG_OPT_TYPE_STRING, &_conf.gpg_dir},
     {"gpg_trust_level", OPKG_OPT_TYPE_STRING, &_conf.gpg_trust_level},
@@ -620,7 +621,12 @@ int opkg_lock()
         return -1;
     }
 
-    r = lockf(lock_fd, F_TLOCK, (off_t) 0);
+    if (opkg_config->retry_get_lock) {
+        r = lockf(lock_fd, F_LOCK, (off_t) 0);
+    }
+    else {
+        r = lockf(lock_fd, F_TLOCK, (off_t) 0);
+    }
     if (r == -1) {
         opkg_perror(ERROR, "Could not lock %s", opkg_config->lock_file);
         r = close(lock_fd);
diff --git a/src/opkg.c b/src/opkg.c
index 0c729ff..996aac9 100644
--- a/src/opkg.c
+++ b/src/opkg.c
@@ -66,6 +66,7 @@ enum {
     ARGS_OPT_HOST_CACHE_DIR,
     ARGS_OPT_SHORT_DESCRIPTION,
     ARGS_OPT_FIELDS_FILTER,
+    ARGS_OPT_RETRY_GET_LOCK,
 };
 
 static struct option long_options[] = {
@@ -124,6 +125,8 @@ static struct option long_options[] = {
     {"volatile-cache", 0, 0, ARGS_OPT_VOLATILE_CACHE},
     {"short-description", 0, 0, ARGS_OPT_SHORT_DESCRIPTION},
     {"fields", 1, 0, ARGS_OPT_FIELDS_FILTER},
+    {"retry-get-lock", 0, 0, ARGS_OPT_RETRY_GET_LOCK},
+    {"retry_get_lock", 0, 0, ARGS_OPT_RETRY_GET_LOCK},
     {"verbosity", 2, 0, 'V'},
     {"version", 0, 0, 'v'},
     {0, 0, 0, 0}
@@ -266,6 +269,9 @@ static int args_parse(int argc, char *argv[])
         case ARGS_OPT_FIELDS_FILTER:
             opkg_config->fields_filter = xstrdup(optarg);
             break;
+        case ARGS_OPT_RETRY_GET_LOCK:
+            store_str_arg(&opkg_config->retry_get_lock = 1);
+            break;
         case ARGS_OPT_COMBINE:
             opkg_config->combine = 1;
             break;
@@ -384,7 +390,9 @@ static void usage()
     printf("\t                                automatically to satisfy dependencies\n");
     printf("\t--host-cache-dir                Don't place cache in offline root dir.\n");
     printf("\t--volatile-cache                Use volatile cache.\n");
-    printf("\t                                Volatile cache will be cleared on exit\n");
+    printf("\t                                Volatile cache will be cleared on exit\n")j;
+    printf("\t--retry-get-lock                Allow retry if we fail to get lock file.\n");
+    printf("\t                                This helps with systemd postinsts service.\n");
     printf("\n");
 
     printf(" glob could be something like 'pkgname*' '*file*' or similar\n");