diff mbox series

[V2,08/11] Reset action_id after usage

Message ID 20231017140657.95860-9-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series Handle Hawkbit action_id and on the fly updates | expand

Commit Message

Stefano Babic Oct. 17, 2023, 2:06 p.m. UTC
When a feedback is successfully sent, the action_id must be removed.
This avoid that the feedback can be sent again with wrong action_id if
SWUpdate is restarted (or if the boot resumes after a power cut).

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 suricatta/server_hawkbit.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 9b71987c..572ee1e3 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -868,8 +868,14 @@  static void get_action_id_from_env(int *action_id)
 	 */
 	char *action_str = swupdate_vars_get("action_id", NULL);
 	if (action_str) {
-		*action_id = ustrtoull(action_str, NULL, 10);
-		TRACE("Stored action_id from previous run: %d", *action_id);
+		int tmp = ustrtoull(action_str, NULL, 10);
+		/*
+		 * 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);
 	}
 }
@@ -937,6 +943,11 @@  server_op_res_t server_handle_initial_state(update_state_t stateovrrd)
 	if (result != SERVER_UPDATE_AVAILABLE)
 		return result;
 
+	/*
+	 * Everything fine, reset action_id if any
+	 */
+	swupdate_vars_set("action_id", NULL, NULL);
+
 	/* NOTE (Re-)setting STATE_KEY=STATE_OK == '0' instead of deleting it
 	 *      as it may be required for the switchback/recovery U-Boot logics.
 	 */