diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-01-23 13:31:56 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-01-23 17:33:11 +0800 |
commit | e61e64c785de0809fb69cd160e8317f2de25793e (patch) | |
tree | a4f4fdbc5ed1a314e341bd26922b096a75eec4c1 /lib/pb-config | |
parent | f66b0807cace1cfda192810861ba6309bf6fa9fe (diff) | |
download | petitboot-e61e64c785de0809fb69cd160e8317f2de25793e.zip petitboot-e61e64c785de0809fb69cd160e8317f2de25793e.tar.gz |
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>
Diffstat (limited to 'lib/pb-config')
-rw-r--r-- | lib/pb-config/storage-powerpc-nvram.c | 40 |
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); |