diff mbox series

suricatta: save action_id in grubenv when in use

Message ID 20240605104732.5335-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:47 a.m. UTC
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(-)

Comments

vincent....@gmail.com June 5, 2024, 10:49 a.m. UTC | #1
Oops sorry for the resend

Hello, 

I don't know if this kind of modification should be accepted but it's how I 
managed handling of action_id for suricatta with Grub bootloader.

Best regards,
Vincent

Le mercredi 5 juin 2024 à 12:47:38 UTC+2, Vincent Prince a écrit :

> 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....@gmail.com>
> ---
> suricatta/server_hawkbit.c | 32 +++++++++++++++++++++++++++-----
> 1 file changed, 27 insertions(+), 5 deletions(-)
>
> 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;
> -- 
> 2.36.1
>
>
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;