diff options
author | jilles <jilles@FreeBSD.org> | 2009-12-31 16:13:33 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2009-12-31 16:13:33 +0000 |
commit | 8e6aa134e5ad932e4809cecaf9117c734ef3a9c7 (patch) | |
tree | 5b0ca429ee15b88be553192b86c73d26bc2db531 | |
parent | 1aa8466f894833794eb1be74ffcc4095cca42764 (diff) | |
download | FreeBSD-src-8e6aa134e5ad932e4809cecaf9117c734ef3a9c7.zip FreeBSD-src-8e6aa134e5ad932e4809cecaf9117c734ef3a9c7.tar.gz |
sh: Allow command -pv and command -pV (lookup using _PATH_STDPATH).
-rw-r--r-- | bin/sh/eval.c | 2 | ||||
-rw-r--r-- | bin/sh/exec.c | 17 | ||||
-rw-r--r-- | bin/sh/exec.h | 2 | ||||
-rw-r--r-- | tools/regression/bin/sh/builtins/command6.0 | 15 | ||||
-rw-r--r-- | tools/regression/bin/sh/builtins/command6.0.stdout | 8 | ||||
-rw-r--r-- | tools/regression/bin/sh/builtins/command7.0 | 29 |
6 files changed, 66 insertions, 7 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index d5fb5ae..e54d19a 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -1023,7 +1023,7 @@ commandcmd(int argc, char **argv) if (cmd != -1) { if (argc != 1) error("wrong number of arguments"); - return typecmd_impl(2, argv - 1, cmd); + return typecmd_impl(2, argv - 1, cmd, path); } if (argc != 0) { old = handler; diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 2bdbab8..02cf91e 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -720,7 +720,7 @@ unsetfunc(const char *name) */ int -typecmd_impl(int argc, char **argv, int cmd) +typecmd_impl(int argc, char **argv, int cmd, const char *path) { struct cmdentry entry; struct tblentry *cmdp; @@ -729,6 +729,9 @@ typecmd_impl(int argc, char **argv, int cmd) int i; int error1 = 0; + if (path != pathval()) + clearcmdentry(0); + for (i = 1; i < argc; i++) { /* First look at the keywords */ for (pp = parsekwd; *pp; pp++) @@ -761,17 +764,17 @@ typecmd_impl(int argc, char **argv, int cmd) } else { /* Finally use brute force */ - find_command(argv[i], &entry, 0, pathval()); + find_command(argv[i], &entry, 0, path); } switch (entry.cmdtype) { case CMDNORMAL: { if (strchr(argv[i], '/') == NULL) { - const char *path = pathval(); + const char *path2 = path; char *name; int j = entry.u.index; do { - name = padvance(&path, argv[i]); + name = padvance(&path2, argv[i]); stunalloc(name); } while (--j >= 0); if (cmd == TYPECMD_SMALLV) @@ -821,6 +824,10 @@ typecmd_impl(int argc, char **argv, int cmd) break; } } + + if (path != pathval()) + clearcmdentry(0); + return error1; } @@ -831,5 +838,5 @@ typecmd_impl(int argc, char **argv, int cmd) int typecmd(int argc, char **argv) { - return typecmd_impl(argc, argv, TYPECMD_TYPE); + return typecmd_impl(argc, argv, TYPECMD_TYPE, pathval()); } diff --git a/bin/sh/exec.h b/bin/sh/exec.h index 200ddea..32bf131 100644 --- a/bin/sh/exec.h +++ b/bin/sh/exec.h @@ -71,6 +71,6 @@ void deletefuncs(void); void addcmdentry(const char *, struct cmdentry *); void defun(const char *, union node *); int unsetfunc(const char *); -int typecmd_impl(int, char **, int); +int typecmd_impl(int, char **, int, const char *); int typecmd(int, char **); void clearcmdentry(int); diff --git a/tools/regression/bin/sh/builtins/command6.0 b/tools/regression/bin/sh/builtins/command6.0 new file mode 100644 index 0000000..2ba836e --- /dev/null +++ b/tools/regression/bin/sh/builtins/command6.0 @@ -0,0 +1,15 @@ +# $FreeBSD$ +PATH=/var/empty +command -pV ls +command -pV true +command -pV /bin/ls + +fun() { +} +command -pV fun +command -pV break +command -pV if +command -pV { + +alias foo=bar +command -pV foo diff --git a/tools/regression/bin/sh/builtins/command6.0.stdout b/tools/regression/bin/sh/builtins/command6.0.stdout new file mode 100644 index 0000000..4cb2b11 --- /dev/null +++ b/tools/regression/bin/sh/builtins/command6.0.stdout @@ -0,0 +1,8 @@ +ls is /bin/ls +true is a shell builtin +/bin/ls is /bin/ls +fun is a shell function +break is a special shell builtin +if is a shell keyword +{ is a shell keyword +foo is an alias for bar diff --git a/tools/regression/bin/sh/builtins/command7.0 b/tools/regression/bin/sh/builtins/command7.0 new file mode 100644 index 0000000..897a14c --- /dev/null +++ b/tools/regression/bin/sh/builtins/command7.0 @@ -0,0 +1,29 @@ +# $FreeBSD$ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +check '"$(PATH=/libexec command -V ld-elf.so.1)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(PATH=/libexec command -V ld-elf.so.1; :)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(PATH=/libexec command -pv ld-elf.so.1)" = ""' +check '"$(PATH=/libexec command -pv ld-elf.so.1; :)" = ""' + +PATH=/libexec:$PATH + +check '"$(command -V ld-elf.so.1)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(command -V ld-elf.so.1; :)" = "ld-elf.so.1 is /libexec/ld-elf.so.1"' +check '"$(command -pv ld-elf.so.1)" = ""' +check '"$(command -pv ld-elf.so.1; :)" = ""' + +PATH=/libexec + +check '"$(command -v ls)" = ""' +check '"$(command -pv ls)" = "/bin/ls"' + +exit $((failures > 0)) |