From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 7/7] env: delete selected vars not present in imported env
Date: Mon, 27 Aug 2012 12:02:19 +0200 [thread overview]
Message-ID: <201208271202.19485.marex@denx.de> (raw)
In-Reply-To: <1346053980-5514-1-git-send-email-gerlando.falauto@keymile.com>
Dear Gerlando Falauto,
> When variables explicitly specified on the command line are not present
> in the imported env, delete them from the running env.
> If the variable is also missing from the running env, issue a warning.
>
> Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>
Looks reasonable ...
Reviewed-by: Marek Vasut <marex@denx.de>
> ---
> Changes from v4:
> - renamed is_var_in_set to drop_var_from_set
> - removed leading double underscore from vars[] variable name
> ---
> lib/hashtable.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 42 insertions(+), 8 deletions(-)
>
> diff --git a/lib/hashtable.c b/lib/hashtable.c
> index f3f47de..670a704 100644
> --- a/lib/hashtable.c
> +++ b/lib/hashtable.c
> @@ -607,22 +607,32 @@ 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[])
> +/*
> + * Check whether variable 'name' is amongst vars[],
> + * and remove all instances by setting the pointer to NULL
> + */
> +static int drop_var_from_set(const char *name, int nvars, char * vars[])
> {
> int i = 0;
> + int res = 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;
> + if (vars[i] == NULL)
> + continue;
> + /* If we found it, delete all of them */
> + if (!strcmp(name, vars[i])) {
> + vars[i] = NULL;
> + res = 1;
> + }
> }
> - debug("Skipping non-listed variable %s\n", name);
> + if (!res)
> + debug("Skipping non-listed variable %s\n", name);
>
> - return 0;
> + return res;
> }
>
> /*
> @@ -665,6 +675,8 @@ int himport_r(struct hsearch_data *htab,
> int nvars, char * const vars[], int do_apply)
> {
> char *data, *sp, *dp, *name, *value;
> + char *localvars[nvars];
> + int i;
>
> /* Test for correct arguments. */
> if (htab == NULL) {
> @@ -681,6 +693,10 @@ int himport_r(struct hsearch_data *htab,
> memcpy(data, env, size);
> dp = data;
>
> + /* make a local copy of the list of variables */
> + if (nvars)
> + memcpy(localvars, vars, sizeof(vars[0]) * nvars);
> +
> if ((flag & H_NOCLEAR) == 0) {
> /* Destroy old hash table if one exists */
> debug("Destroy Hash Table: %p table = %p\n", htab,
> @@ -749,7 +765,7 @@ 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))
> + if (!drop_var_from_set(name, nvars, localvars))
> continue;
>
> if (hdelete_r(name, htab, do_apply) == 0)
> @@ -769,7 +785,7 @@ int himport_r(struct hsearch_data *htab,
> ++dp;
>
> /* Skip variables which are not supposed to be processed */
> - if (!is_var_in_set(name, nvars, vars))
> + if (!drop_var_from_set(name, nvars, localvars))
> continue;
>
> /* enter into hash table */
> @@ -809,6 +825,24 @@ int himport_r(struct hsearch_data *htab,
> debug("INSERT: free(data = %p)\n", data);
> free(data);
>
> + /* process variables which were not considered */
> + for (i = 0; i < nvars; i++) {
> + if (localvars[i] == NULL)
> + continue;
> + /*
> + * All variables which were not deleted from the variable list
> + * were not present in the imported env
> + * This could mean two things:
> + * a) if the variable was present in current env, we delete it
> + * b) if the variable was not present in current env, we notify
> + * it might be a typo
> + */
> + if (hdelete_r(localvars[i], htab, do_apply) == 0)
> + printf("WARNING: '%s' neither in running nor in imported
env!\n",
> localvars[i]); + else
> + printf("WARNING: '%s' not in imported env, deleting it!
\n",
> localvars[i]); + }
> +
> debug("INSERT: done\n");
> return 1; /* everything OK */
> }
next prev parent reply other threads:[~2012-08-27 10:02 UTC|newest]
Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-18 16:49 [U-Boot] [PATCH v1 0/5] env: handle special variables and selective env default Gerlando Falauto
2011-11-18 16:49 ` [U-Boot] [PATCH v1 1/5] serial: cosmetic checkpatch compliance Gerlando Falauto
2011-11-18 20:04 ` Mike Frysinger
2011-12-05 21:47 ` Wolfgang Denk
2011-11-18 16:49 ` [U-Boot] [PATCH v1 2/5] serial: constify serial_assign() Gerlando Falauto
2011-11-18 20:03 ` Mike Frysinger
2011-12-05 21:48 ` Wolfgang Denk
2011-11-18 16:49 ` [U-Boot] [PATCH v1 3/5] env: unify logic to check and apply changes Gerlando Falauto
2011-12-07 1:50 ` Simon Glass
2011-11-18 16:49 ` [U-Boot] [PATCH v1 4/5] env: check and apply changes on delete/destroy Gerlando Falauto
2011-11-18 16:49 ` [U-Boot] [PATCH v1 5/5] env: make "env default" selective, check and apply Gerlando Falauto
2011-12-07 13:30 ` [U-Boot] [PATCH v2 0/3] env: handle special variables and selective env default Gerlando Falauto
2011-12-07 13:30 ` [U-Boot] [PATCH v2 1/3] env: unify logic to check and apply changes Gerlando Falauto
2011-12-07 22:02 ` Simon Glass
2011-12-08 5:45 ` Mike Frysinger
2011-12-12 9:32 ` Gerlando Falauto
2011-12-12 12:18 ` Wolfgang Denk
2011-12-12 13:38 ` Gerlando Falauto
2011-12-12 13:50 ` Wolfgang Denk
2011-12-12 16:24 ` Simon Glass
2012-03-29 20:19 ` Marek Vasut
2012-03-30 13:00 ` Gerlando Falauto
2012-03-30 13:08 ` Marek Vasut
2012-03-30 13:22 ` Gerlando Falauto
2012-03-30 13:55 ` Marek Vasut
2012-03-30 14:03 ` Gerlando Falauto
2012-03-30 14:28 ` Marek Vasut
2012-03-30 17:00 ` Gerlando Falauto
2011-12-07 13:30 ` [U-Boot] [PATCH v2 2/3] env: check and apply changes on delete/destroy Gerlando Falauto
2011-12-07 22:02 ` Simon Glass
2011-12-12 9:32 ` Gerlando Falauto
2011-12-12 13:08 ` Wolfgang Denk
2011-12-12 13:52 ` Gerlando Falauto
2011-12-12 19:19 ` Wolfgang Denk
2011-12-07 13:30 ` [U-Boot] [PATCH v2 3/3] env: make "env default" selective, check and apply Gerlando Falauto
2011-12-07 22:02 ` Simon Glass
2011-12-12 9:33 ` Gerlando Falauto
2011-12-12 13:10 ` Wolfgang Denk
2012-03-29 20:25 ` Marek Vasut
2012-03-30 13:00 ` Gerlando Falauto
2012-03-30 13:09 ` Marek Vasut
2012-03-30 13:25 ` Gerlando Falauto
2012-04-02 18:26 ` [U-Boot] [PATCH v3 0/6] env: handle special variables and selective env default Gerlando Falauto
2012-08-09 20:17 ` Wolfgang Denk
2012-08-09 22:19 ` Gerlando Falauto
2012-08-09 22:26 ` Wolfgang Denk
2012-08-10 8:53 ` Holger Brunck
2012-08-10 18:08 ` Wolfgang Denk
2012-08-13 7:23 ` Holger Brunck
2012-08-13 10:11 ` Wolfgang Denk
2012-08-24 10:18 ` Gerlando Falauto
2012-08-24 15:11 ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 1/6] env: unify logic to check and apply changes Gerlando Falauto
2012-04-02 18:56 ` Marek Vasut
2012-04-02 20:39 ` Gerlando Falauto
2012-04-02 20:50 ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 2/6] env: make himport_r() selective on variables Gerlando Falauto
2012-04-02 18:57 ` Marek Vasut
2012-04-02 20:43 ` Gerlando Falauto
2012-04-04 7:41 ` Simon Glass
2012-04-02 18:26 ` [U-Boot] [PATCH v3 3/6] env: add check/apply logic to himport_r() Gerlando Falauto
2012-04-02 19:00 ` Marek Vasut
2012-04-02 19:01 ` Marek Vasut
2012-04-02 20:44 ` Gerlando Falauto
2012-04-02 20:51 ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 4/6] env: check and apply changes on delete/destroy Gerlando Falauto
2012-04-02 19:01 ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 5/6] env: make "env default" selective, check and apply Gerlando Falauto
2012-04-02 19:04 ` Marek Vasut
2012-04-02 18:26 ` [U-Boot] [PATCH v3 6/6] env: delete selected vars not present in imported env Gerlando Falauto
2012-04-02 19:06 ` Marek Vasut
2012-04-02 20:45 ` Gerlando Falauto
2012-04-02 21:00 ` Marek Vasut
2012-08-24 10:11 ` [U-Boot] [PATCH v4 0/7] env: handle special variables and selective env default Gerlando Falauto
2012-08-24 10:11 ` [U-Boot] [PATCH v4 1/7] env: cosmetic: drop assignment i = iomux_doenv() Gerlando Falauto
2012-08-24 14:44 ` Marek Vasut
2012-09-18 19:05 ` [U-Boot] [U-Boot, v4, " Tom Rini
2012-08-24 10:11 ` [U-Boot] [PATCH v4 2/7] env: unify logic to check and apply changes Gerlando Falauto
2012-08-24 14:48 ` Marek Vasut
2012-08-24 10:11 ` [U-Boot] [PATCH v4 3/7] env: make himport_r() selective on variables Gerlando Falauto
2012-08-24 14:50 ` Marek Vasut
2012-08-24 10:11 ` [U-Boot] [PATCH v4 4/7] env: add check/apply logic to himport_r() Gerlando Falauto
2012-08-24 14:52 ` Marek Vasut
2012-08-24 10:11 ` [U-Boot] [PATCH v4 5/7] env: check and apply changes on delete/destroy Gerlando Falauto
2012-08-24 14:53 ` Marek Vasut
2012-08-24 10:11 ` [U-Boot] [PATCH v4 6/7] env: make "env default" selective, check and apply Gerlando Falauto
2012-08-24 14:56 ` Marek Vasut
2012-08-24 15:10 ` Gerlando Falauto
2012-08-24 21:10 ` Marek Vasut
2012-08-27 7:36 ` Gerlando Falauto
2012-08-27 9:57 ` Marek Vasut
2012-09-02 11:58 ` Wolfgang Denk
2012-08-24 10:11 ` [U-Boot] [PATCH v4 7/7] env: delete selected vars not present in imported env Gerlando Falauto
2012-08-24 14:58 ` Marek Vasut
2012-08-24 15:16 ` Gerlando Falauto
2012-08-24 21:12 ` Marek Vasut
2012-08-27 7:45 ` Gerlando Falauto
2012-09-02 12:01 ` Wolfgang Denk
2012-09-03 7:34 ` Gerlando Falauto
2012-08-27 7:53 ` [U-Boot] [PATCH v5 " Gerlando Falauto
2012-08-27 10:02 ` Marek Vasut [this message]
2012-09-02 11:59 ` [U-Boot] [PATCH v4 0/7] env: handle special variables and selective env default Wolfgang Denk
2012-09-02 16:13 ` Marek Vasut
2012-09-03 7:33 ` Gerlando Falauto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201208271202.19485.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.