diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-07-22 11:51:34 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-07-25 10:15:45 +0200 |
commit | e844f9c60d1e13f28bdb1ed95102df1e6df44faa (patch) | |
tree | 983a79b19f84c816948a8900154bae49f83526ed | |
parent | 04d6b35b5d9a9ce5583ed04e8c7b6cf37d86fed0 (diff) | |
download | barebox-e844f9c60d1e13f28bdb1ed95102df1e6df44faa.tar.gz barebox-e844f9c60d1e13f28bdb1ed95102df1e6df44faa.tar.xz |
nv: Allow wildcards when removing NV vars
With this patch 'nv -r' can also take "*" and "?" wildcards for nv
variables. This makes it easier to remove multiple nv variables.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/Kconfig | 1 | ||||
-rw-r--r-- | common/globalvar.c | 18 |
2 files changed, 11 insertions, 8 deletions
diff --git a/common/Kconfig b/common/Kconfig index a85ee8daca..027b8da100 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -169,6 +169,7 @@ config NVVAR default y if !SHELL_NONE depends on GLOBALVAR depends on ENV_HANDLING + select FNMATCH help Non volatile environment variables begin with "nv.". They behave like global variables above, but their values are saved in the environment diff --git a/common/globalvar.c b/common/globalvar.c index a2eaaa0223..44e6528f6c 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -10,6 +10,7 @@ #include <libfile.h> #include <generated/utsrelease.h> #include <envfs.h> +#include <fnmatch.h> static int nv_dirty; @@ -293,22 +294,23 @@ int nvvar_add(const char *name, const char *value) int nvvar_remove(const char *name) { - struct param_d *p; + struct param_d *p, *tmp; char *fname; if (!IS_ENABLED(CONFIG_NVVAR)) return -ENOSYS; - p = get_param_by_name(&nv_device, name); - if (!p) - return -ENOENT; + list_for_each_entry_safe(p, tmp, &nv_device.parameters, list) { + if (fnmatch(name, p->name, 0)) + continue; - fname = basprintf("/env/nv/%s", p->name); + fname = basprintf("/env/nv/%s", p->name); - dev_remove_param(p); + dev_remove_param(p); - unlink(fname); - free(fname); + unlink(fname); + free(fname); + } return 0; } |