diff mbox series

[2/3] hawkbit: check for validity of action_id

Message ID 20240415101906.45782-2-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series [1/3] BUG: hawkbit: check if details are sent via IPC | expand

Commit Message

Stefano Babic April 15, 2024, 10:19 a.m. UTC
The "swupdate-ipc sendtohawkbit" tool allows to send a feedback to the
Hawkbit server with external data. Commit d770ad59e introduces that
SWUpdate can persistently store the action-id between runs, and this
worked after a reboot when SWUpdate is started again.

This patch introduces the same feature when IPC is used. The action-id
in IPC can be set to 0 or -1 (invalid for Hawkbit), and SWUpdate will
then check if a valid action_id is in the environment.

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

--
2.34.1
diff mbox series

Patch

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index f1948c68..5199eefe 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -867,6 +867,7 @@  static void get_action_id_from_env(int *action_id)
 	 * Get the acction_id that corresponds to the done update if it was
 	 * stored.
 	 */
+	*action_id = -1;
 	char *action_str = swupdate_vars_get("action_id", NULL);
 	if (action_str) {
 		int tmp = ustrtoull(action_str, NULL, 10);
@@ -2023,11 +2024,12 @@  static server_op_res_t server_activation_ipc(ipc_message *msg)
 	int action_id = -1;
 	if (json_data) {
 		action_id = json_object_get_int(json_data);
-	} else {
+	}
+	if (action_id <= 0) { /* 0 is not a valid action id */
 		get_action_id_from_env(&action_id);
 	}

-	if (action_id < 0) {
+	if (action_id <= 0) {
 		ERROR("No action_id passed into JSON message and no action:_id in env");
 		return SERVER_EERR;
 	}