Patchwork [U-Boot,RFC,4/4] env: implement "env import -n var[, var...]"

login
register
mail settings
Submitter Gerlando Falauto
Date Sept. 30, 2011, 12:04 p.m.
Message ID <1317384298-27025-5-git-send-email-gerlando.falauto@keymile.com>
Download mbox | patch
Permalink /patch/117123/
State Changes Requested
Headers show

Comments

Gerlando Falauto - Sept. 30, 2011, 12:04 p.m.
Implemented selective importing of variables in
env import

Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>
---
 common/cmd_nvedit.c |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)
Mike Frysinger - Sept. 30, 2011, 9:52 p.m.
On Friday, September 30, 2011 08:04:58 Gerlando Falauto wrote:
> +					if (nvars >= MAX_NVARS)
> +					{

that brace needs to be cuddled
-mike

Patch

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 8636004..757a088 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -804,15 +804,18 @@  sep_err:
  *	size:	length of input data; if missing, proper '\0'
  *		termination is mandatory
  */
-static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+#define MAX_NVARS 16
+static int do_env_import(cmd_tbl_t *cmdtp, int __flag, int argc, char * const argv[])
 {
 	char	*cmd, *addr;
 	char	sep = '\n';
 	int	chk = 0;
 	int	fmt = 0;
-	int	del = 0;
+	int	flag = H_NOCLEAR;
 	size_t	size;
-
+	char	*vars[MAX_NVARS];
+	int	nvars = 0;
+	char 	*s;
 	cmd = *argv;
 
 	while (--argc > 0 && **++argv == '-') {
@@ -836,7 +839,24 @@  static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
 				sep = '\n';
 				break;
 			case 'd':
-				del = 1;
+				flag &= ~H_NOCLEAR;
+				break;
+			case 'f':
+				flag |= H_FORCE;
+				break;
+			case 'n':
+				s = *++argv;
+				argc--;
+				do {
+					if (nvars >= MAX_NVARS)
+					{
+						printf("No more than %d variables can be imported at a single time\n", MAX_NVARS);
+						return 1;
+					}
+					vars[nvars++] = strsep(&s, ",");
+					debug("Considering variable %s\n", vars[nvars-1]);
+				} while (s);
+				debug("Importing a total of %d variables\n", nvars);
 				break;
 			default:
 				return cmd_usage(cmdtp);
@@ -887,7 +907,8 @@  static int do_env_import(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
 		addr = (char *)ep->data;
 	}
 
-	if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
+	if (himport_ex(&env_htab, addr, size, sep, flag, 
+		       nvars, vars, NULL) == 0) {
 		error("Environment import failed: errno = %d\n", errno);
 		return 1;
 	}