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

Replace the hash alias with a proper builtin

This commit replaces the old hash alias with a proper builtin.
I based this builtin off of the code alias uses for handling
`alias -t --`, but with the hack for `--` removed as it has
no use in the new builtin. `alias -t --` will no longer work,
that hack is now gone.

While I was testing this builtin, I found a bug with hash tables
in non-forking subshells. If the hash table of a non-forking
subshell is changed, the parent shell's hash table is also changed.
As an example, running `(hash -r)` was resetting the parent shell's
hash table. The workaround is to force the subshell to fork if the
hash table will be changed.

src/cmd/ksh93/bltins/typeset.c:
 - Move the code for hash out of the alias builtin into a dedicated
   hash builtin. `alias -t --` is no longer supported.

src/cmd/ksh93/data/aliases.c:
 - Remove the old alias for hash from the table of predefined aliases.

src/cmd/ksh93/data/builtins.c:
 - Fix the broken entry for the hash builtin and add a man page for
   the new builtin.

src/cmd/ksh93/sh.1:
 - Replace the entry for the hash alias with a more detailed entry
   for the hash builtin.

src/cmd/ksh93/sh/name.c:
 - Force non-forking subshells to fork if the PATH is being reset
   to workaround a bug with the hash tree.

src/cmd/ksh93/tests/alias.sh:
 - Add a regression test for resetting a hash table, then adding
   a utility to the refreshed hash table.

src/cmd/ksh93/tests/subshell.sh:
 - Add regression tests for changing the hash table in subshells.

(cherry picked from commit d8428a833afe9270b61745ba3d6df355fe1d5499)
This commit is contained in:
Johnothan King 2020-06-10 04:00:35 -07:00 committed by Martijn Dekker
parent d1bd8f89b7
commit 102868f850
10 changed files with 121 additions and 32 deletions

View file

@ -33,7 +33,6 @@ const struct shtable2 shtab_aliases[] =
"compound", NV_NOFREE|BLT_DCL, "typeset -C",
"float", NV_NOFREE|BLT_DCL, "typeset -lE",
"functions", NV_NOFREE, "typeset -f",
"hash", NV_NOFREE, "alias -t --",
"history", NV_NOFREE, "hist -l",
"integer", NV_NOFREE|BLT_DCL, "typeset -li",
"nameref", NV_NOFREE|BLT_DCL, "typeset -n",

View file

@ -79,7 +79,7 @@ const struct shtable3 shtab_builtins[] =
"newgrp", NV_BLTIN|BLT_ENV|BLT_SPC, Bltin(login),
#endif /* _bin_newgrp || _usr_bin_newgrp */
"alias", NV_BLTIN|BLT_SPC, bltin(alias),
"hash", NV_BLTIN|BLT_SPC, bltin(alias),
"hash", NV_BLTIN, bltin(hash),
"enum", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(enum),
"eval", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_EXIT,bltin(eval),
"exit", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(return),
@ -377,7 +377,7 @@ USAGE_LICENSE
"definition, or an error occurred.]"
"}"
"[+SEE ALSO?\bsh\b(1), \bunalias\b(1)]"
"[+SEE ALSO?\bsh\b(1), \bhash(1), \bunalias\b(1)]"
;
const char sh_optbuiltin[] =
@ -929,6 +929,27 @@ _JOB_
"[+SEE ALSO?\bwait\b(1), \bps\b(1), \bfg\b(1), \bbg\b(1)]"
;
const char sh_opthash[] =
"[-1c?\n@(#)$Id: hash (ksh community) 2020-06-10 $\n]"
"[+NAME?hash - display the locations of recently used programs]"
"[+DESCRIPTION?The \bhash\b utility is used to display or modify "
"the hash table, which contains the locations of "
"recently used programs. When \bhash\b is given no arguments, "
"it will list all commands in the hash table. If \autility\a is "
"supplied, \bhash\b will add that utility to the hash table.]"
"[r?This option will empty the hash table. The effect of "
"this flag can also be achieved by resetting the value of \bPATH\b.]"
"\n"
"\n[utility...]\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Successful completion.]"
"[+>0?An error occured.]"
"}"
"[+SEE ALSO?\bsh\b(1), \balias\b(1)]"
;
const char sh_opthist[] =
"[-1cn?@(#)$Id: hist (AT&T Research) 2000-04-02 $\n]"
USAGE_LICENSE