]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
env: make himport_r() selective on variables
authorGerlando Falauto <gerlando.falauto@keymile.com>
Fri, 24 Aug 2012 00:11:38 +0000 (00:11 +0000)
committerTom Rini <trini@ti.com>
Tue, 18 Sep 2012 19:01:52 +0000 (12:01 -0700)
Add 2 new arguments to himport_r():

 o "nvars", "vars": number and list of variables to take into account
   (0 means ALL)

NOTE: This patch does not change the current behaviour.

Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>
Reviewed-by: Marek Vasut <marex@denx.de>
common/cmd_nvedit.c
common/env_common.c
include/search.h
lib/hashtable.c

index 86518d43705a48ea7167be7ceff4b8ab6a0d50f1..c601b3ac272cbc9afa4e0079292f17d0e8213630 100644 (file)
@@ -914,7 +914,8 @@ static int do_env_import(cmd_tbl_t *cmdtp, int flag,
                addr = (char *)ep->data;
        }
 
-       if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
+       if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
+                       0, NULL) == 0) {
                error("Environment import failed: errno = %d\n", errno);
                return 1;
        }
index 911a6afd1bf94733de179f127711dda622eb5b4a..c5cefd8a50d6591d1d4b110b444033d30af4dd3a 100644 (file)
@@ -196,7 +196,8 @@ void set_default_env(const char *s)
        }
 
        if (himport_r(&env_htab, (char *)default_environment,
-                       sizeof(default_environment), '\0', 0) == 0)
+                       sizeof(default_environment), '\0', 0,
+                       0, NULL) == 0)
                error("Environment import failed: errno = %d\n", errno);
 
        gd->flags |= GD_FLG_ENV_READY;
@@ -221,7 +222,8 @@ int env_import(const char *buf, int check)
                }
        }
 
-       if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0)) {
+       if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', 0,
+                       0, NULL)) {
                gd->flags |= GD_FLG_ENV_READY;
                return 1;
        }
index a4a5ef4956b8c295221a4db32f94bde725725799..94d75fc65c26fa4022a87b2631073a2c2cc844b4 100644 (file)
@@ -94,9 +94,13 @@ extern ssize_t hexport_r(struct hsearch_data *__htab,
                     const char __sep, char **__resp, size_t __size,
                     int argc, char * const argv[]);
 
+/*
+ * nvars: length of vars array
+ * vars: array of strings (variable names) to import (nvars == 0 means all)
+ */
 extern int himport_r(struct hsearch_data *__htab,
                     const char *__env, size_t __size, const char __sep,
-                    int __flag);
+                    int __flag, int nvars, char * const vars[]);
 
 /* Flags for himport_r() */
 #define        H_NOCLEAR       (1 << 0) /* do not clear hash table before importing */
index abd61c891861ee6c2c011beaac051c645e1222e6..0610e867d08b5f9f8b55e2352068c2b8ff86c5a0 100644 (file)
@@ -603,6 +603,24 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep,
  * himport()
  */
 
+/* Check whether variable name is amongst vars[] */
+static int is_var_in_set(const char *name, int nvars, char * const vars[])
+{
+       int i = 0;
+
+       /* No variables specified means process all of them */
+       if (nvars == 0)
+               return 1;
+
+       for (i = 0; i < nvars; i++) {
+               if (!strcmp(name, vars[i]))
+                       return 1;
+       }
+       debug("Skipping non-listed variable %s\n", name);
+
+       return 0;
+}
+
 /*
  * Import linearized data into hash table.
  *
@@ -639,7 +657,8 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep,
  */
 
 int himport_r(struct hsearch_data *htab,
-             const char *env, size_t size, const char sep, int flag)
+               const char *env, size_t size, const char sep, int flag,
+               int nvars, char * const vars[])
 {
        char *data, *sp, *dp, *name, *value;
 
@@ -726,6 +745,8 @@ int himport_r(struct hsearch_data *htab,
                        *dp++ = '\0';   /* terminate name */
 
                        debug("DELETE CANDIDATE: \"%s\"\n", name);
+                       if (!is_var_in_set(name, nvars, vars))
+                               continue;
 
                        if (hdelete_r(name, htab) == 0)
                                debug("DELETE ERROR ##############################\n");
@@ -743,6 +764,10 @@ int himport_r(struct hsearch_data *htab,
                *sp++ = '\0';   /* terminate value */
                ++dp;
 
+               /* Skip variables which are not supposed to be processed */
+               if (!is_var_in_set(name, nvars, vars))
+                       continue;
+
                /* enter into hash table */
                e.key = name;
                e.data = value;