mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix unsetting aliases in subshells
Aliases can now be correctly unset within subshell environments (such as ( ... ), $(command substitutions), etc), as well as non-subshell "shared" command substitutions (${ ...; }). Before, attempts to unset aliases within these were silently ignored. Prior discussion: https://github.com/att/ast/issues/108 Subshell alias trees are only referenced in a few places in the code, *and* have always been broken, so this commit gets rid of the whole notion of a subshell alias tree. Instead, there is now just one flat alias tree, and subshells fork into a separate process when aliases are set or unset within them. It is not really conceivable that this could be a performance-sensitive operation, or even a common one, so this is a clean fix with no downside. src/cmd/ksh93/include/defs.h: - Remove sh_subaliastree() definition. src/cmd/ksh93/sh/subshell.c: - Remove salias element (pointer to subshell alias tree) from subshell struct. - Remove sh_subaliastree() function. - sh_subshell(): Remove alias subshell tree cleanup. src/cmd/ksh93/bltins/typeset.c: - b_alias(): If in subshell, fork before setting alias. - b_unalias(): If in subshell, fork before unsetting alias. - unall(): Remove sh_subaliastree() call. src/cmd/ksh93/sh/name.c: - nv_open(): Remove sh_subaliastree() call. src/cmd/ksh93/tests/subshell.sh: - Add regression tests for unsetting or redefining aliases within subshells. (cherry picked from commit 12a15605b9521a2564a6e657905705a060e89095)
This commit is contained in:
parent
047cb3303c
commit
ec888867fd
6 changed files with 36 additions and 32 deletions
|
@ -197,6 +197,8 @@ int b_alias(int argc,register char *argv[],Shbltin_t *context)
|
|||
troot = tdata.sh->track_tree;
|
||||
}
|
||||
}
|
||||
if(context->shp->subshell && !context->shp->subshare)
|
||||
sh_subfork();
|
||||
return(setall(argv,flag,troot,&tdata));
|
||||
}
|
||||
|
||||
|
@ -1142,6 +1144,8 @@ int b_set(int argc,register char *argv[],Shbltin_t *context)
|
|||
int b_unalias(int argc,register char *argv[],Shbltin_t *context)
|
||||
{
|
||||
Shell_t *shp = context->shp;
|
||||
if(shp->subshell && !shp->subshare)
|
||||
sh_subfork();
|
||||
return(unall(argc,argv,shp->alias_tree,shp));
|
||||
}
|
||||
|
||||
|
@ -1161,11 +1165,7 @@ static int unall(int argc, char **argv, register Dt_t *troot, Shell_t* shp)
|
|||
struct checkpt buff;
|
||||
NOT_USED(argc);
|
||||
if(troot==shp->alias_tree)
|
||||
{
|
||||
name = sh_optunalias;
|
||||
if(shp->subshell)
|
||||
troot = sh_subaliastree(0);
|
||||
}
|
||||
else
|
||||
name = sh_optunset;
|
||||
while(r = optget(argv,name)) switch(r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue