Message ID | 20240709075833.2345799-2-stefano.babic@swupdate.org |
---|---|
State | Accepted |
Headers | show |
Series | [1/2] Degrade to WARN if a var is not found in env | expand |
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 <stefano.babic@swupdate.org> Thanks! Reviewed-by: Dominique Martinet <dominique.martinet@atmark-techno.com> > --- > 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)
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)
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 <stefano.babic@swupdate.org> --- suricatta/server_hawkbit.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) -- 2.34.1