diff mbox

[U-Boot,v3,4/6] env: check and apply changes on delete/destroy

Message ID 1333391204-16318-5-git-send-email-gerlando.falauto@keymile.com
State Accepted
Commit 152874b65b8060e7b026933ce332a9687256e28c
Headers show

Commit Message

Gerlando Falauto April 2, 2012, 6:26 p.m. UTC
Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>
---
 common/cmd_nvedit.c |    2 +-
 include/search.h    |    5 +++--
 lib/hashtable.c     |   16 ++++++++++------
 3 files changed, 14 insertions(+), 9 deletions(-)

Comments

Marek Vasut April 2, 2012, 7:01 p.m. UTC | #1
Dear Gerlando Falauto,

> Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>

Looks ok

> ---
>  common/cmd_nvedit.c |    2 +-
>  include/search.h    |    5 +++--
>  lib/hashtable.c     |   16 ++++++++++------
>  3 files changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
> index fc6165f..091cd46 100644
> --- a/common/cmd_nvedit.c
> +++ b/common/cmd_nvedit.c
> @@ -375,7 +375,7 @@ int _do_env_set(int flag, int argc, char * const
> argv[])
> 
>  	/* Delete only ? */
>  	if (argc < 3 || argv[2] == NULL) {
> -		int rc = hdelete_r(name, &env_htab);
> +		int rc = hdelete_r(name, &env_htab, 0);
>  		return !rc;
>  	}
> 
> diff --git a/include/search.h b/include/search.h
> index 721c8ac..93e1cbc 100644
> --- a/include/search.h
> +++ b/include/search.h
> @@ -73,7 +73,7 @@ struct hsearch_data {
>  extern int hcreate_r(size_t __nel, struct hsearch_data *__htab);
> 
>  /* Destroy current internal hashing table.  */
> -extern void hdestroy_r(struct hsearch_data *__htab);
> +extern void hdestroy_r(struct hsearch_data *__htab, int do_apply);
> 
>  /*
>   * Search for entry matching ITEM.key in internal hash table.  If
> @@ -98,7 +98,8 @@ extern int hstrstr_r(const char *__match, int __last_idx,
> ENTRY ** __retval, struct hsearch_data *__htab);
> 
>  /* Search and delete entry matching ITEM.key in internal hash table. */
> -extern int hdelete_r(const char *__key, struct hsearch_data *__htab);
> +extern int hdelete_r(const char *__key, struct hsearch_data *__htab,
> +			int do_apply);
> 
>  extern ssize_t hexport_r(struct hsearch_data *__htab,
>  		     const char __sep, char **__resp, size_t __size,
> diff --git a/lib/hashtable.c b/lib/hashtable.c
> index 6cfba56..f3f47de 100644
> --- a/lib/hashtable.c
> +++ b/lib/hashtable.c
> @@ -142,7 +142,7 @@ int hcreate_r(size_t nel, struct hsearch_data *htab)
>   * be freed and the local static variable can be marked as not used.
>   */
> 
> -void hdestroy_r(struct hsearch_data *htab)
> +void hdestroy_r(struct hsearch_data *htab, int do_apply)
>  {
>  	int i;
> 
> @@ -156,7 +156,10 @@ void hdestroy_r(struct hsearch_data *htab)
>  	for (i = 1; i <= htab->size; ++i) {
>  		if (htab->table[i].used > 0) {
>  			ENTRY *ep = &htab->table[i].entry;
> -
> +			if (do_apply && htab->apply != NULL) {
> +				/* deletion is always forced */
> +				htab->apply(ep->key, ep->data, NULL, H_FORCE);
> +			}
>  			free((void *)ep->key);
>  			free(ep->data);
>  		}
> @@ -401,7 +404,7 @@ int hsearch_r(ENTRY item, ACTION action, ENTRY **
> retval, * do that.
>   */
> 
> -int hdelete_r(const char *key, struct hsearch_data *htab)
> +int hdelete_r(const char *key, struct hsearch_data *htab, int do_apply)
>  {
>  	ENTRY e, *ep;
>  	int idx;
> @@ -417,7 +420,8 @@ int hdelete_r(const char *key, struct hsearch_data
> *htab)
> 
>  	/* free used ENTRY */
>  	debug("hdelete: DELETING key \"%s\"\n", key);
> -
> +	if (do_apply && htab->apply != NULL)
> +		htab->apply(ep->key, ep->data, NULL, H_FORCE);
>  	free((void *)ep->key);
>  	free(ep->data);
>  	htab->table[idx].used = -1;
> @@ -682,7 +686,7 @@ int himport_r(struct hsearch_data *htab,
>  		debug("Destroy Hash Table: %p table = %p\n", htab,
>  		       htab->table);
>  		if (htab->table)
> -			hdestroy_r(htab);
> +			hdestroy_r(htab, do_apply);
>  	}
> 
>  	/*
> @@ -748,7 +752,7 @@ int himport_r(struct hsearch_data *htab,
>  			if (!is_var_in_set(name, nvars, vars))
>  				continue;
> 
> -			if (hdelete_r(name, htab) == 0)
> +			if (hdelete_r(name, htab, do_apply) == 0)
>  				debug("DELETE ERROR 
##############################\n");
> 
>  			continue;
diff mbox

Patch

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index fc6165f..091cd46 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -375,7 +375,7 @@  int _do_env_set(int flag, int argc, char * const argv[])
 
 	/* Delete only ? */
 	if (argc < 3 || argv[2] == NULL) {
-		int rc = hdelete_r(name, &env_htab);
+		int rc = hdelete_r(name, &env_htab, 0);
 		return !rc;
 	}
 
diff --git a/include/search.h b/include/search.h
index 721c8ac..93e1cbc 100644
--- a/include/search.h
+++ b/include/search.h
@@ -73,7 +73,7 @@  struct hsearch_data {
 extern int hcreate_r(size_t __nel, struct hsearch_data *__htab);
 
 /* Destroy current internal hashing table.  */
-extern void hdestroy_r(struct hsearch_data *__htab);
+extern void hdestroy_r(struct hsearch_data *__htab, int do_apply);
 
 /*
  * Search for entry matching ITEM.key in internal hash table.  If
@@ -98,7 +98,8 @@  extern int hstrstr_r(const char *__match, int __last_idx, ENTRY ** __retval,
 		    struct hsearch_data *__htab);
 
 /* Search and delete entry matching ITEM.key in internal hash table. */
-extern int hdelete_r(const char *__key, struct hsearch_data *__htab);
+extern int hdelete_r(const char *__key, struct hsearch_data *__htab,
+			int do_apply);
 
 extern ssize_t hexport_r(struct hsearch_data *__htab,
 		     const char __sep, char **__resp, size_t __size,
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 6cfba56..f3f47de 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -142,7 +142,7 @@  int hcreate_r(size_t nel, struct hsearch_data *htab)
  * be freed and the local static variable can be marked as not used.
  */
 
-void hdestroy_r(struct hsearch_data *htab)
+void hdestroy_r(struct hsearch_data *htab, int do_apply)
 {
 	int i;
 
@@ -156,7 +156,10 @@  void hdestroy_r(struct hsearch_data *htab)
 	for (i = 1; i <= htab->size; ++i) {
 		if (htab->table[i].used > 0) {
 			ENTRY *ep = &htab->table[i].entry;
-
+			if (do_apply && htab->apply != NULL) {
+				/* deletion is always forced */
+				htab->apply(ep->key, ep->data, NULL, H_FORCE);
+			}
 			free((void *)ep->key);
 			free(ep->data);
 		}
@@ -401,7 +404,7 @@  int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
  * do that.
  */
 
-int hdelete_r(const char *key, struct hsearch_data *htab)
+int hdelete_r(const char *key, struct hsearch_data *htab, int do_apply)
 {
 	ENTRY e, *ep;
 	int idx;
@@ -417,7 +420,8 @@  int hdelete_r(const char *key, struct hsearch_data *htab)
 
 	/* free used ENTRY */
 	debug("hdelete: DELETING key \"%s\"\n", key);
-
+	if (do_apply && htab->apply != NULL)
+		htab->apply(ep->key, ep->data, NULL, H_FORCE);
 	free((void *)ep->key);
 	free(ep->data);
 	htab->table[idx].used = -1;
@@ -682,7 +686,7 @@  int himport_r(struct hsearch_data *htab,
 		debug("Destroy Hash Table: %p table = %p\n", htab,
 		       htab->table);
 		if (htab->table)
-			hdestroy_r(htab);
+			hdestroy_r(htab, do_apply);
 	}
 
 	/*
@@ -748,7 +752,7 @@  int himport_r(struct hsearch_data *htab,
 			if (!is_var_in_set(name, nvars, vars))
 				continue;
 
-			if (hdelete_r(name, htab) == 0)
+			if (hdelete_r(name, htab, do_apply) == 0)
 				debug("DELETE ERROR ##############################\n");
 
 			continue;