diff mbox series

[V2,02/11] Store globally namespace for swupdate_vars

Message ID 20231017140657.95860-3-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
Namespace (see also libubootenv) for SWUpdate's own variable is defined
in configuration file. At the moment, SWUpdate will support to write
just into a single namespace. Most processes do not need to know it, and
it is ok to define a default mechanism to retrieve the namespace. This
patch adds a singleton for namespace.

AWupdate will store the selected namespace at the startup and will use
it in calls where the namespace is not set.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 core/swupdate.c      |  6 ++++++
 core/swupdate_vars.c | 10 ++++++++++
 2 files changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index 50a34fec..1625ca95 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -50,6 +50,7 @@ 
 #include "bootloader.h"
 #include "versions.h"
 #include "hw-compatibility.h"
+#include "swupdate_vars.h"
 
 #ifdef CONFIG_SYSTEMD
 #include <systemd/sd-daemon.h>
@@ -318,6 +319,11 @@  static int read_globals_settings(void *elem, void *data)
 				"preupdatecmd", sw->preupdatecmd);
 	GET_FIELD_STRING(LIBCFG_PARSER, elem,
 				"namespace-vars", sw->namespace_for_vars);
+	if (strlen(sw->namespace_for_vars)) {
+		if (!swupdate_set_default_namespace(sw->namespace_for_vars))
+			WARN("Default Namaspace for SWUpdate vars cannot be set, possible side-effects");
+	}
+
 	get_field(LIBCFG_PARSER, elem, "verbose", &sw->verbose);
 	get_field(LIBCFG_PARSER, elem, "loglevel", &sw->loglevel);
 	get_field(LIBCFG_PARSER, elem, "syslog", &sw->syslog_enabled);
diff --git a/core/swupdate_vars.c b/core/swupdate_vars.c
index 5d2f95ab..4dd97ff7 100644
--- a/core/swupdate_vars.c
+++ b/core/swupdate_vars.c
@@ -101,3 +101,13 @@  int swupdate_vars_apply_list(const char *filename, const char *namespace)
 
 	return ret;
 }
+
+bool swupdate_set_default_namespace(const char *namespace)
+{
+	if (namespace_default)
+		free(namespace_default);
+
+	namespace_default = strdup(namespace);
+
+	return namespace_default != NULL;
+}