summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-01-23 13:31:56 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-01-23 17:33:11 +0800
commite61e64c785de0809fb69cd160e8317f2de25793e (patch)
treea4f4fdbc5ed1a314e341bd26922b096a75eec4c1
parentf66b0807cace1cfda192810861ba6309bf6fa9fe (diff)
downloadtalos-petitboot-e61e64c785de0809fb69cd160e8317f2de25793e.tar.gz
talos-petitboot-e61e64c785de0809fb69cd160e8317f2de25793e.zip
pb-config/powerpc: fix default option handling
Currently, we don't update nvram if an NVRAM parameter is set to the default. This means we can never revert a configuration to its default value. This change fixes the default setting behaviour; instead of checking for a default, we want to check if it's a default and the option is absent. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--lib/pb-config/storage-powerpc-nvram.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/pb-config/storage-powerpc-nvram.c b/lib/pb-config/storage-powerpc-nvram.c
index 4b4b878..e371976 100644
--- a/lib/pb-config/storage-powerpc-nvram.c
+++ b/lib/pb-config/storage-powerpc-nvram.c
@@ -434,6 +434,20 @@ static char *dns_config_str(void *ctx, const char **dns_servers, int n)
return str;
}
+static void update_string_config(struct powerpc_nvram_storage *nv,
+ const char *name, const char *value)
+{
+ const char *cur;
+
+ cur = get_param(nv, name);
+
+ /* don't set an empty parameter if it doesn't already exist */
+ if (!cur && !strlen(value))
+ return;
+
+ set_param(nv, name, value);
+}
+
static void update_network_config(struct powerpc_nvram_storage *nv,
struct config *config)
{
@@ -458,7 +472,7 @@ static void update_network_config(struct powerpc_nvram_storage *nv,
talloc_free(dns_str);
}
- set_param(nv, "petitboot,network", val);
+ update_string_config(nv, "petitboot,network", val);
talloc_free(val);
}
@@ -466,18 +480,24 @@ static void update_network_config(struct powerpc_nvram_storage *nv,
static int update_config(struct powerpc_nvram_storage *nv,
struct config *config, struct config *defaults)
{
- char *val;
+ char *tmp = NULL;
+ const char *val;
- if (config->autoboot_enabled != defaults->autoboot_enabled) {
+ if (config->autoboot_enabled == defaults->autoboot_enabled)
+ val = "";
+ else
val = config->autoboot_enabled ? "true" : "false";
- set_param(nv, "auto-boot?", val);
- }
+ update_string_config(nv, "auto-boot?", val);
- if (config->autoboot_timeout_sec != defaults->autoboot_timeout_sec) {
- val = talloc_asprintf(nv, "%d", config->autoboot_timeout_sec);
- set_param(nv, "petitboot,timeout", val);
- talloc_free(val);
- }
+ if (config->autoboot_timeout_sec == defaults->autoboot_timeout_sec)
+ val = "";
+ else
+ val = tmp = talloc_asprintf(nv, "%d",
+ config->autoboot_timeout_sec);
+
+ update_string_config(nv, "petitboot,timeout", val);
+ if (tmp)
+ talloc_free(tmp);
update_network_config(nv, config);
OpenPOWER on IntegriCloud