On Wed, Feb 16, 2011 at 9:52 PM, David Korn <[email protected]> wrote:
> tracked aliases were added for ksh88 and for compatibility the the Bourne
> shell they were not on by default.
>
> The POSIX standard allows the shell to remember the location of commands
> until PATH is assigned to. So, in ksh93 while I left the trackall option in,
> for backward compatibility with ksh88, I made the default track aliases and
> ignored the option.
>
> As far as I remember, the only case I do not remember the location of
> a command that I look up is with whence -a.
>
> Now I should either make this clear in the documentation, or implement
> disabling tracked aliases as you have done.
>
> Can you give me a reason why you believe that it should be possible
> to disable tracked aliases?

Thank you for your response. The default currently does track aliases,
but never uses them. Only whence has access to the tracked aliases due
to:

if(!(flag&1) && (np=nv_search(name,shp->track_tree,0)) &&
!nv_isattr(np,NV_NOALIAS) && (pp=(Pathcomp_t*)np->nvalue.cp))
{
...
}

in path_search() inside path.c since whence is the only call that is
made with flag=2. Other calls with flag=0 I believe are for function
searches only and hence do not even make it to this condition due to
the if (flag) immediately outside.

As a result there is an inconsistency in what whence says will happen
and what actually happens, since whence tells you that an alias will
be used and an alias is never really used. Besides, whence keeps
saying that foo is a tracked alias for /path/to/foo even when it
really isn't just yet.

Toggling tracked aliases is a useful feature to have for compatibility
across shells. The test case I presented earlier is a good case for
disabling aliases with the PATH set the way it is. In the last
invocation of min_script.ksh, I want the script from the current
directory to run, but due to tracked aliases, that would not happen.

It is a useful feature when we know about the directory tree we're
getting into and want the flexibility to call scripts inside the
directory tree strictly based on PATH. On the other hand, I would like
to have tracked aliases enabled in cases where I don't know the
directory tree I am working in and I want to be sure that my script
(possibly outside the tree) is always executed even if there happens
to be a script/executable with the same name in the directory tree. It
is a different thing that currently this is all a bit messed up with
whence saying something and exec doing something else.

Beside that, while testing for this patch, I also triggered a corner
case crash in regression testing, for which I had included a fix in my
patch. Here is the relevant hunk from the patch:

diff -pruN a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c
--- a/src/cmd/ksh93/sh/xec.c    2011-02-09 00:38:15.000000000 +0530
+++ b/src/cmd/ksh93/sh/xec.c    2011-02-16 19:30:09.527538550 +0530
@@ -1137,7 +1137,7 @@ int sh_exec(register const Shnode_t *t,
                                                if(!shp->namespace || 
!(np=sh_fsearch(shp,com0,0)))
 #endif /* SHOPT_NAMESPACE */
                                                        
np=nv_search(com0,shp->fun_tree,0);
-                                               if(!np && !np->nvalue.ip)
+                                               if(!np || !np->nvalue.ip)
                                                {
                                                        Namval_t 
*mp=nv_search(com0,shp->bltin_tree,0);
                                                        if(mp)

-- 
Siddhesh Poyarekar
http://siddhesh.in
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to