diff mbox series

[2/7] installer: factorize function for preparing env script

Message ID 20231009153152.416365-3-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series Introduce SWUpdate environment | expand

Commit Message

Stefano Babic Oct. 9, 2023, 3:31 p.m. UTC
This can be reused for vars that do not belong to the bootloader.
Extract the function as preparation for general purpose vars.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 core/installer.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/core/installer.c b/core/installer.c
index 768503fb..0088d1a3 100644
--- a/core/installer.c
+++ b/core/installer.c
@@ -155,10 +155,9 @@  static int extract_scripts(struct imglist *head)
 	return 0;
 }
 
-static int update_bootloader_env(struct swupdate_cfg *cfg, const char *script)
+static int prepare_var_script(struct dict *dict, const char *script)
 {
 	int fd;
-	int ret = 0;
 	struct dict_entry *bootvar;
 	char buf[MAX_BOOT_SCRIPT_LINE_LENGTH];
 
@@ -166,7 +165,7 @@  static int update_bootloader_env(struct swupdate_cfg *cfg, const char *script)
 	if (fd < 0)
 		return -1;
 
-	LIST_FOREACH(bootvar, &cfg->bootloader, next) {
+	LIST_FOREACH(bootvar, dict, next) {
 		char *key = dict_entry_get_key(bootvar);
 		char *value = dict_entry_get_value(bootvar);
 
@@ -181,6 +180,17 @@  static int update_bootloader_env(struct swupdate_cfg *cfg, const char *script)
 	}
 	close(fd);
 
+	return 0;
+}
+
+static int update_bootloader_env(struct swupdate_cfg *cfg, const char *script)
+{
+	int ret = 0;
+
+	ret = prepare_var_script(&cfg->bootloader, script);
+	if (ret)
+		return ret;
+
 	if ((ret = bootloader_apply_list(script)) < 0) {
 		ERROR("Bootloader-specific error %d updating its environment", ret);
 	}