1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Export all variables assigned to while allexport is on (#431)

All variables that are assigned a value should be exported while
the allexport shell option is enabled. This works in most cases,
but variables assigned to with ${var:=foo} or $((var=123)) aren't
exported while allexport is on.

src/cmd/ksh93/sh/name.c:
- nv_putval(): This is the central assignment function; all forms
  of variable assignment end up here. So this is the best place
  to check for SH_ALLEXPORT and turn on the export attribute.
- nv_setlist(): Remove allexport handling, now redundant.

src/cmd/ksh93/bltins/read.c: sh_readline():
- Remove allexport handling, now redundant.

src/cmd/ksh93/sh/main.c: sh_main():
- nv_putval() is used to initialize PS4 and IFS using nv_putval();
  this is after an -a/--allexport specified on the ksh command
  line has been processed, so temporarily turn that off.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2022-02-03 21:52:53 -08:00 committed by Martijn Dekker
parent 0863a8eb29
commit 8e72608c1c
9 changed files with 85 additions and 17 deletions

View file

@ -142,8 +142,6 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
}
sh.fn_depth = sh.dot_depth = 0;
command = error_info.id;
if(nv_isnull(PS4NOD))
nv_putval(PS4NOD,e_traceprompt,NV_RDONLY);
path_pwd();
iop = (Sfio_t*)0;
if(sh_isoption(SH_POSIX))
@ -358,7 +356,15 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
sh_onoption(SH_EMACS);
#endif /* SHOPT_ESH */
}
/* (Re)set PS4 and IFS, but don't export these now even if allexport is on. */
i = (sh_isoption(SH_ALLEXPORT) != 0);
sh_offoption(SH_ALLEXPORT);
if(nv_isnull(PS4NOD))
nv_putval(PS4NOD,e_traceprompt,NV_RDONLY);
nv_putval(IFSNOD,(char*)e_sptbnl,NV_RDONLY);
if(i)
sh_onoption(SH_ALLEXPORT);
/* Start main execution loop. */
exfile(iop,fdin);
sh_done(0);
}

View file

@ -289,8 +289,6 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ)
flags |= NV_NOSCOPE;
#endif /* SHOPT_NAMESPACE */
flags &= ~(NV_TYPE|NV_ARRAY|NV_IARRAY);
if(sh_isoption(SH_ALLEXPORT))
flags |= NV_EXPORT;
if(sh.prefix)
{
flags &= ~(NV_IDENT|NV_EXPORT);
@ -1617,7 +1615,12 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
sh.argaddr = 0;
if(sh.subshell && !nv_local && !(flags&NV_RDONLY))
np = sh_assignok(np,1);
/* Export the variable if 'set -o allexport' is enabled */
if(sh_isoption(SH_ALLEXPORT))
{
flags |= NV_EXPORT;
nv_onattr(np,NV_EXPORT);
}
if(np->nvfun && np->nvfun->disc && !(flags&NV_NODISC) && !nv_isref(np))
{
/* This function contains disc */