ash: respect -p flag when command builtin is run with -v/-V

The command builtin should only check the default path, not $PATH,
when the -p flag is used along with -v/-V.

Based on commits 65ae84b (by Harald van Dijk) and 29ee27d (by Herbert
Xu) from git://git.kernel.org/pub/scm/utils/dash/dash.git).

function                                             old     new   delta
commandcmd                                            72      87     +15
describe_command                                     437     450     +13
typecmd                                               84      86      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 30/0)               Total: 30 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston 2015-08-03 13:47:33 +01:00 committed by Denys Vlasenko
parent e2f32c02b1
commit 3f221113a5
3 changed files with 10 additions and 4 deletions

View File

@ -7812,14 +7812,15 @@ findkwd(const char *s)
* Locate and print what a word is... * Locate and print what a word is...
*/ */
static int static int
describe_command(char *command, int describe_command_verbose) describe_command(char *command, const char *path, int describe_command_verbose)
{ {
struct cmdentry entry; struct cmdentry entry;
struct tblentry *cmdp; struct tblentry *cmdp;
#if ENABLE_ASH_ALIAS #if ENABLE_ASH_ALIAS
const struct alias *ap; const struct alias *ap;
#endif #endif
const char *path = pathval();
path = path ? path : pathval();
if (describe_command_verbose) { if (describe_command_verbose) {
out1str(command); out1str(command);
@ -7919,7 +7920,7 @@ typecmd(int argc UNUSED_PARAM, char **argv)
verbose = 0; verbose = 0;
} }
while (argv[i]) { while (argv[i]) {
err |= describe_command(argv[i++], verbose); err |= describe_command(argv[i++], NULL, verbose);
} }
return err; return err;
} }
@ -7933,6 +7934,7 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
VERIFY_BRIEF = 1, VERIFY_BRIEF = 1,
VERIFY_VERBOSE = 2, VERIFY_VERBOSE = 2,
} verify = 0; } verify = 0;
const char *path = NULL;
while ((c = nextopt("pvV")) != '\0') while ((c = nextopt("pvV")) != '\0')
if (c == 'V') if (c == 'V')
@ -7943,9 +7945,11 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
else if (c != 'p') else if (c != 'p')
abort(); abort();
#endif #endif
else
path = bb_default_path;
/* Mimic bash: just "command -v" doesn't complain, it's a nop */ /* Mimic bash: just "command -v" doesn't complain, it's a nop */
if (verify && (*argptr != NULL)) { if (verify && (*argptr != NULL)) {
return describe_command(*argptr, verify - VERIFY_BRIEF); return describe_command(*argptr, path, verify - VERIFY_BRIEF);
} }
return 0; return 0;

View File

@ -0,0 +1 @@
recho: not found

View File

@ -0,0 +1 @@
command -p -V recho