From patchwork Sun May 3 20:12:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 467428 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 38A1E140285 for ; Mon, 4 May 2015 06:18:16 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 93EB34B989; Sun, 3 May 2015 22:17:02 +0200 (CEST) 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 HpL71-yFcs2w; Sun, 3 May 2015 22:17:02 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B792C4B9B8; Sun, 3 May 2015 22:15:55 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9EDB54B8BD for ; Sun, 3 May 2015 22:15:13 +0200 (CEST) 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 1dntY2tdmW1L for ; Sun, 3 May 2015 22:15:13 +0200 (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 ni.com (skprod2.natinst.com [130.164.80.23]) by theia.denx.de (Postfix) with ESMTPS id 133F84B8A2 for ; Sun, 3 May 2015 22:15:12 +0200 (CEST) Received: from us-aus-mgwout2.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod2.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t43KF5Vx025354; Sun, 3 May 2015 15:15:05 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout2.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015050315150500-652370 ; Sun, 3 May 2015 15:15:05 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Sun, 3 May 2015 15:12:44 -0500 Message-Id: <1430683982-9832-9-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1430683982-9832-1-git-send-email-joe.hershberger@ni.com> References: <1430286666-392-1-git-send-email-joe.hershberger@ni.com> <1430683982-9832-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 05/03/2015 03:15:05 PM, Serialize by Router on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 05/03/2015 03:15:05 PM, Serialize complete at 05/03/2015 03:15:05 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-05-03_03:, , signatures=0 Cc: Alexander Holler , Tom Rini , Joe Hershberger Subject: [U-Boot] [PATCH v3 08/26] env: Distinguish finer between source of env change X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" We already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ). Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- Changes in v3: None Changes in v2: None common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 6ca5a2e..f4c2523 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -208,12 +208,11 @@ DONE: * Set a new environment variable, * or replace or delete an existing one. */ -static int _do_env_set(int flag, int argc, char * const argv[]) +static int _do_env_set(int flag, int argc, char * const argv[], int env_flag) { int i, len; char *name, *value, *s; ENTRY e, *ep; - int env_flag = H_INTERACTIVE; debug("Initial value for argc=%d\n", argc); while (argc > 1 && **(argv + 1) == '-') { @@ -291,9 +290,9 @@ int setenv(const char *varname, const char *varvalue) return 1; if (varvalue == NULL || varvalue[0] == '\0') - return _do_env_set(0, 2, (char * const *)argv); + return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC); else - return _do_env_set(0, 3, (char * const *)argv); + return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC); } /** @@ -347,7 +346,7 @@ static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) return CMD_RET_USAGE; - return _do_env_set(flag, argc, argv); + return _do_env_set(flag, argc, argv, H_INTERACTIVE); } /* @@ -422,7 +421,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } /* Continue calling setenv code */ - return _do_env_set(flag, len, local_args); + return _do_env_set(flag, len, local_args, H_INTERACTIVE); } #endif @@ -588,6 +587,10 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, if (argc < 2) return CMD_RET_USAGE; + /* before import into hashtable */ + if (!(gd->flags & GD_FLG_ENV_READY)) + return 1; + /* Set read buffer to initial value or empty sting */ init_val = getenv(argv[1]); if (init_val) @@ -598,7 +601,16 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, if (cli_readline_into_buffer("edit: ", buffer, 0) < 0) return 1; - return setenv(argv[1], buffer); + if (buffer[0] == '\0') { + const char * const _argv[3] = { "setenv", argv[1], NULL }; + + return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE); + } else { + const char * const _argv[4] = { "setenv", argv[1], buffer, + NULL }; + + return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE); + } } #endif /* CONFIG_CMD_EDITENV */ #endif /* CONFIG_SPL_BUILD */ diff --git a/include/search.h b/include/search.h index 9701efb..343dbc3 100644 --- a/include/search.h +++ b/include/search.h @@ -120,5 +120,7 @@ extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *)); #define H_MATCH_SUBSTR (1 << 7) /* search for substring matches */ #define H_MATCH_REGEX (1 << 8) /* search for regular expression matches */ #define H_MATCH_METHOD (H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX) +#define H_PROGRAMMATIC (1 << 9) /* indicate that an import is from setenv() */ +#define H_ORIGIN_FLAGS (H_INTERACTIVE | H_PROGRAMMATIC) #endif /* search.h */