apps/nshlib/nsh_envcmds.c: Once an NSH variable has been promoted to an environment variable, subsequent set operations should act on the environment variable rather than creating a new NSH variable that shadows the environment variable.
This commit is contained in:
parent
ee01445aa2
commit
65e0b791b7
@ -76,7 +76,7 @@ static inline FAR const char *nsh_getwd(const char *wd)
|
||||
/* If no working directory is defined, then default to the home directory */
|
||||
|
||||
val = getenv(wd);
|
||||
if (!val)
|
||||
if (val == NULL)
|
||||
{
|
||||
val = g_home;
|
||||
}
|
||||
@ -399,12 +399,25 @@ int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
#endif /* CONFIG_NSH_DISABLESCRIPT */
|
||||
#ifdef NSH_HAVE_VARS
|
||||
{
|
||||
#if defined(CONFIG_NSH_VARS) && !defined(CONFIG_DISABLE_ENVIRON)
|
||||
FAR char *oldvalue;
|
||||
#endif
|
||||
|
||||
/* Trim whitespace from the value */
|
||||
|
||||
value = nsh_trimspaces(argv[ndx+1]);
|
||||
|
||||
#if defined(CONFIG_NSH_VARS)
|
||||
/* Set NSH variable (may shadow a environment variable) */
|
||||
#ifdef CONFIG_NSH_VARS
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
/* Check if the NSH variable has already been promoted to an group-
|
||||
* wide environment variable.
|
||||
*/
|
||||
|
||||
oldvalue = getenv(argv[ndx]);
|
||||
if (oldvalue == NULL)
|
||||
#endif
|
||||
{
|
||||
/* Set the NSH variable */
|
||||
|
||||
ret = nsh_setvar(vtbl, argv[ndx], value);
|
||||
if (ret < 0)
|
||||
@ -412,16 +425,24 @@ int cmd_set(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "nsh_setvar",
|
||||
NSH_ERRNO_OF(-ret));
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NSH_VARS */
|
||||
|
||||
#elif !defined(CONFIG_DISABLE_ENVIRON)
|
||||
#if !defined(CONFIG_DISABLE_ENVIRON)
|
||||
#ifdef CONFIG_NSH_VARS
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Set the environment variable */
|
||||
|
||||
ret = setenv(argv[ndx], value, TRUE);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "setenv", NSH_ERRNO);
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "setenv",
|
||||
NSH_ERRNO);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_ENVIRON */
|
||||
}
|
||||
#endif /* NSH_HAVE_VARS */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user