diff mbox series

suricatta: save action_id in grubenv when in use

Message ID 20240605104554.5296-1-vincent.prince.fr@gmail.com
State Changes Requested
Headers show
Series suricatta: save action_id in grubenv when in use | expand

Commit Message

vincent....@gmail.com June 5, 2024, 10:45 a.m. UTC
From: Vincent Prince <vincent.prince.external@saftbatteries.com>

When GRUB is selected as bootloader, use GRUB environment file
to save action_id instead of using libubootenv methods

Signed-off-by: Vincent Prince <vincent.prince.fr@gmail.com>
---
 suricatta/server_hawkbit.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 9c3e9741..f2a6edf7 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -32,6 +32,7 @@ 
 #include "swupdate_settings.h"
 #include "swupdate_dict.h"
 #include "swupdate_vars.h"
+#include "bootloader.h"
 
 #define INITIAL_STATUS_REPORT_WAIT_DELAY 10
 
@@ -868,7 +869,14 @@  static void get_action_id_from_env(int *action_id)
 	 * stored.
 	 */
 	*action_id = -1;
-	char *action_str = swupdate_vars_get("action_id", NULL);
+	char *action_str = NULL;
+
+        if (is_bootloader(BOOTLOADER_GRUB)) {
+            action_str = bootloader_env_get("action_id");
+        } else {
+            action_str = swupdate_vars_get("action_id", NULL);
+        }
+
 	if (action_str) {
 		int tmp = ustrtoull(action_str, NULL, 10);
 		if (errno)
@@ -882,6 +890,8 @@  static void get_action_id_from_env(int *action_id)
 			TRACE("Retrieve action_id from previous run: %d", *action_id);
 		}
 		free(action_str);
+	} else {
+                INFO("'action_id' not found in environment.");
 	}
 }
 
@@ -951,7 +961,11 @@  server_op_res_t server_handle_initial_state(update_state_t stateovrrd)
 	/*
 	 * Everything fine, reset action_id if any
 	 */
-	swupdate_vars_set("action_id", NULL, NULL);
+        if (is_bootloader(BOOTLOADER_GRUB)) {
+            bootloader_env_unset("action_id");
+        } else {
+            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.
@@ -1112,9 +1126,17 @@  server_op_res_t server_process_update_artifact(int action_id,
 		ERROR("OOM reached when saving action_id");
 		return SERVER_EERR;
 	}
-	if (swupdate_vars_set("action_id", action_id_str, NULL)) {
-		WARN("Action_id cannot be stored, do yourself");
-	}
+
+        int ret;
+        if (is_bootloader(BOOTLOADER_GRUB)) {
+            ret = bootloader_env_set("action_id", action_id_str);
+        } else {
+            ret = swupdate_vars_set("action_id", action_id_str, NULL);
+        }
+        if (ret) {
+            WARN("Action_id cannot be stored, do yourself");
+        }
+
 	free(action_id_str);
 
 	for (int json_data_artifact_count = 0;