From patchwork Fri Nov 18 16:49:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerlando Falauto X-Patchwork-Id: 126451 X-Patchwork-Delegate: wd@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 38C5EB71E5 for ; Sat, 19 Nov 2011 03:50:27 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D0C5728B7E; Fri, 18 Nov 2011 17:50:08 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 789bt2qGhcNW; Fri, 18 Nov 2011 17:50:08 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1099428958; Fri, 18 Nov 2011 17:49:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9A86128421 for ; Fri, 18 Nov 2011 17:49:45 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k9AhzrZwMu2g for ; Fri, 18 Nov 2011 17:49:45 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.de.keymile.com (mail.de.keymile.com [195.8.104.1]) by theia.denx.de (Postfix) with SMTP id F40142893C for ; Fri, 18 Nov 2011 17:49:38 +0100 (CET) Received: from mailrelay.de.keymile.net ([10.9.1.54]) by eSafe SMTP Relay 1321520839; Fri, 18 Nov 2011 17:49:38 +0100 Received: from chber1-10555x.ch.keymile.net (chber1-10555x.ch.keymile.net [172.31.31.112]) by mailrelay.de.keymile.net (8.12.2/8.12.2) with ESMTP id pAIGn6jS017405; Fri, 18 Nov 2011 17:49:19 +0100 (MET) From: Gerlando Falauto To: u-boot@lists.denx.de Date: Fri, 18 Nov 2011 17:49:14 +0100 Message-Id: <1321634955-5561-5-git-send-email-gerlando.falauto@keymile.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1321634955-5561-1-git-send-email-gerlando.falauto@keymile.com> References: <1321634955-5561-1-git-send-email-gerlando.falauto@keymile.com> X-ESAFE-STATUS: [srvhellgate.de.keymile.net] Mail clean Cc: holger.brunck@keymile.com, Gerlando Falauto Subject: [U-Boot] [PATCH v1 4/5] env: check and apply changes on delete/destroy X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Signed-off-by: Gerlando Falauto --- common/cmd_nvedit.c | 2 +- include/search.h | 6 ++++-- lib/hashtable.c | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index d6ea25d..128b334 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -377,7 +377,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, NULL); return !rc; } diff --git a/include/search.h b/include/search.h index 2a59e03..7ad4261 100644 --- a/include/search.h +++ b/include/search.h @@ -70,7 +70,8 @@ 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, + apply_cb apply); /* * Search for entry matching ITEM.key in internal hash table. If @@ -95,7 +96,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, + apply_cb 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 22421f9..fa292e3 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -142,7 +142,8 @@ 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(*apply)(const char *, const char *, const char *, int)) { int i; @@ -156,7 +157,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 (apply != NULL) { + /* deletion is always forced */ + apply(ep->key, ep->data, NULL, H_FORCE); + } free((void *)ep->key); free(ep->data); } @@ -401,7 +405,8 @@ 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(*apply)(const char *, const char *, const char *, int)) { ENTRY e, *ep; int idx; @@ -417,7 +422,8 @@ int hdelete_r(const char *key, struct hsearch_data *htab) /* free used ENTRY */ debug("hdelete: DELETING key \"%s\"\n", key); - + if (apply != NULL) + apply(ep->key, ep->data, NULL, H_FORCE); free((void *)ep->key); free(ep->data); htab->table[idx].used = -1; @@ -681,7 +687,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, apply); } /* @@ -747,7 +753,7 @@ int himport_r(struct hsearch_data *htab, if (!process_var(name, nvars, vars)) continue; - if (hdelete_r(name, htab) == 0) + if (hdelete_r(name, htab, apply) == 0) debug("DELETE ERROR ##############################\n"); continue;