Date: Thu, 31 Dec 2009 16:13:33 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r201343 - in head: bin/sh tools/regression/bin/sh/builtins Message-ID: <200912311613.nBVGDXL8043978@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Thu Dec 31 16:13:33 2009 New Revision: 201343 URL: http://svn.freebsd.org/changeset/base/201343 Log: sh: Allow command -pv and command -pV (lookup using _PATH_STDPATH). Added: head/tools/regression/bin/sh/builtins/command6.0 (contents, props changed) head/tools/regression/bin/sh/builtins/command6.0.stdout (contents, props changed) head/tools/regression/bin/sh/builtins/command7.0 (contents, props changed) Modified: head/bin/sh/eval.c head/bin/sh/exec.c head/bin/sh/exec.h Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Thu Dec 31 15:03:33 2009 (r201342) +++ head/bin/sh/eval.c Thu Dec 31 16:13:33 2009 (r201343) @@ -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; Modified: head/bin/sh/exec.c ============================================================================== --- head/bin/sh/exec.c Thu Dec 31 15:03:33 2009 (r201342) +++ head/bin/sh/exec.c Thu Dec 31 16:13:33 2009 (r201343) @@ -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 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 } 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 break; } } + + if (path != pathval()) + clearcmdentry(0); + return error1; } @@ -831,5 +838,5 @@ typecmd_impl(int argc, char **argv, int int typecmd(int argc, char **argv) { - return typecmd_impl(argc, argv, TYPECMD_TYPE); + return typecmd_impl(argc, argv, TYPECMD_TYPE, pathval()); } Modified: head/bin/sh/exec.h ============================================================================== --- head/bin/sh/exec.h Thu Dec 31 15:03:33 2009 (r201342) +++ head/bin/sh/exec.h Thu Dec 31 16:13:33 2009 (r201343) @@ -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); Added: head/tools/regression/bin/sh/builtins/command6.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/command6.0 Thu Dec 31 16:13:33 2009 (r201343) @@ -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 Added: head/tools/regression/bin/sh/builtins/command6.0.stdout ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/command6.0.stdout Thu Dec 31 16:13:33 2009 (r201343) @@ -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 Added: head/tools/regression/bin/sh/builtins/command7.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/command7.0 Thu Dec 31 16:13:33 2009 (r201343) @@ -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))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912311613.nBVGDXL8043978>