From patchwork Mon Apr 2 18:26:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerlando Falauto X-Patchwork-Id: 150217 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 599B8B6FA3 for ; Tue, 3 Apr 2012 04:38:17 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8BF0728122; Mon, 2 Apr 2012 20:38:12 +0200 (CEST) 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 B8K3fT8bnnqS; Mon, 2 Apr 2012 20:38:12 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E5A2D280FE; Mon, 2 Apr 2012 20:38:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 81656280FE for ; Mon, 2 Apr 2012 20:38:07 +0200 (CEST) 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 RYn6H-nf8mpL for ; Mon, 2 Apr 2012 20:38:05 +0200 (CEST) X-Greylist: delayed 654 seconds by postgrey-1.27 at theia; Mon, 02 Apr 2012 20:38:04 CEST 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 4333C280FB for ; Mon, 2 Apr 2012 20:38:03 +0200 (CEST) Received: from mailrelay.de.keymile.net ([10.9.1.54]) by eSafe SMTP Relay 1333356266; Mon, 02 Apr 2012 20:27:14 +0200 Received: from chber1-10555x.ch.keymile.net (chber1-10555x.ch.keymile.net [172.31.40.82]) by mailrelay.de.keymile.net (8.12.2/8.12.2) with ESMTP id q32IQNjQ018466; Mon, 2 Apr 2012 20:26:31 +0200 (MEST) From: Gerlando Falauto To: u-boot@lists.denx.de Date: Mon, 2 Apr 2012 20:26:40 +0200 Message-Id: <1333391204-16318-3-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: marex@denx.de, holger.brunck@keymile.com, Gerlando Falauto Subject: [U-Boot] [PATCH v3 2/6] env: make himport_r() selective on variables 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 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 --- common/cmd_nvedit.c | 3 ++- common/env_common.c | 6 ++++-- include/search.h | 6 +++++- lib/hashtable.c | 27 ++++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index e762e76..59668a6 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -930,7 +930,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; } diff --git a/common/env_common.c b/common/env_common.c index c33d22d..a93c062 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -182,7 +182,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; @@ -207,7 +208,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; } diff --git a/include/search.h b/include/search.h index a4a5ef4..94d75fc 100644 --- a/include/search.h +++ b/include/search.h @@ -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 */ diff --git a/lib/hashtable.c b/lib/hashtable.c index abd61c8..0610e86 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -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;