[PATCH 2/2] hawkbit: raise a WARN if a action id is not in env

7 views
Skip to first unread message

Stefano Babic

unread,
Jul 9, 2024, 3:58:38 AMJul 9
to swup...@googlegroups.com, Stefano Babic
For long time, thjere was a race condition with Hawkbit: if after a
restart, the operator changed on the server the deploy, SWUpdate
committed an update that wasn't executed. To avoid this, the action id
of the update that was executed is now stored in env, but to be
compatible with the past, the old behavior is accepted as well.

This raises a warning in case the old behavior is chosen to advise that
the answer to Hawkbit could be wrong.

Signed-off-by: Stefano Babic <stefan...@swupdate.org>
---
suricatta/server_hawkbit.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 9d71a318..aa83676a 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -868,20 +868,22 @@ static void get_action_id_from_env(int *action_id)
* stored.
*/
char *action_str = swupdate_vars_get("action_id", NULL);
- if (action_str) {
- int tmp = ustrtoull(action_str, NULL, 10);
- if (errno)
- WARN("action_id %s: ustrtoull failed",
- action_str);
- /*
- * action_id = 0 is invalid, then check it
- */
- if (tmp > 0) {
- *action_id = tmp;
- TRACE("Retrieve action_id from previous run: %d", *action_id);
- }
- free(action_str);
+ if (!action_str) {
+ WARN("Action id not in env: action from server sent, possible mismatch ");
+ return;
+ }
+ int tmp = ustrtoull(action_str, NULL, 10);
+ if (errno)
+ WARN("action_id %s: ustrtoull failed",
+ action_str);
+ /*
+ * action_id = 0 is invalid, then check it
+ */
+ if (tmp > 0) {
+ *action_id = tmp;
+ TRACE("Retrieve action_id from previous run: %d", *action_id);
}
+ free(action_str);
}

server_op_res_t server_handle_initial_state(update_state_t stateovrrd)
--
2.34.1

Stefano Babic

unread,
Jul 9, 2024, 3:58:38 AMJul 9
to swup...@googlegroups.com, Stefano Babic
This is not always an error, so move it to WARN.

Signed-off-by: Stefano Babic <stefan...@swupdate.org>
---
core/swupdate_vars.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/swupdate_vars.c b/core/swupdate_vars.c
index 081e6097..b2074946 100644
--- a/core/swupdate_vars.c
+++ b/core/swupdate_vars.c
@@ -90,7 +90,7 @@ char *swupdate_vars_get(const char *name, const char *namespace)
strlcpy(msg.data.vars.varname, name, sizeof(msg.data.vars.varname));

if (ipc_send_cmd(&msg) || msg.type == NACK) {
- ERROR("Failed to get variable %s", name);
+ WARN("Failed to get variable %s", name);
return NULL;
}
return strdup (msg.data.vars.varvalue);
--
2.34.1

Dominique MARTINET

unread,
Jul 9, 2024, 4:03:22 AMJul 9
to Stefano Babic, swup...@googlegroups.com
Stefano Babic wrote on Tue, Jul 09, 2024 at 09:58:33AM +0200:
> For long time, thjere was a race condition with Hawkbit: if after a
> restart, the operator changed on the server the deploy, SWUpdate
> committed an update that wasn't executed. To avoid this, the action id
> of the update that was executed is now stored in env, but to be
> compatible with the past, the old behavior is accepted as well.
>
> This raises a warning in case the old behavior is chosen to advise that
> the answer to Hawkbit could be wrong.
>
> Signed-off-by: Stefano Babic <stefan...@swupdate.org>


Thanks!

Reviewed-by: Dominique Martinet <dominique...@atmark-techno.com>
Reply all
Reply to author
Forward
0 new messages