From c0b3cf0676b6dbfa5c9f580af9f083eb0c0263f2 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sat, 11 Feb 2012 21:06:45 +0000 Subject: [PATCH] sh: Make 'hash' return 1 if at least one utility is not found. Reported by: lme --- bin/sh/exec.c | 20 ++++++++++++-------- tools/regression/bin/sh/builtins/hash4.0 | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 tools/regression/bin/sh/builtins/hash4.0 diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 82cb3ac9e1a3..f2e4c1db75ec 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -231,7 +231,9 @@ hashcmd(int argc __unused, char **argv __unused) int verbose; struct cmdentry entry; char *name; + int errors; + errors = 0; verbose = 0; while ((c = nextopt("rv")) != '\0') { if (c == 'r') { @@ -254,19 +256,21 @@ hashcmd(int argc __unused, char **argv __unused) && cmdp->cmdtype == CMDNORMAL) delete_cmd_entry(); find_command(name, &entry, DO_ERR, pathval()); - if (verbose) { - if (entry.cmdtype != CMDUNKNOWN) { /* if no error msg */ - cmdp = cmdlookup(name, 0); - if (cmdp != NULL) - printentry(cmdp, verbose); - else - outfmt(out2, "%s: not found\n", name); + if (entry.cmdtype == CMDUNKNOWN) + errors = 1; + else if (verbose) { + cmdp = cmdlookup(name, 0); + if (cmdp != NULL) + printentry(cmdp, verbose); + else { + outfmt(out2, "%s: not found\n", name); + errors = 1; } flushall(); } argptr++; } - return 0; + return errors; } diff --git a/tools/regression/bin/sh/builtins/hash4.0 b/tools/regression/bin/sh/builtins/hash4.0 new file mode 100644 index 000000000000..dec584c4538f --- /dev/null +++ b/tools/regression/bin/sh/builtins/hash4.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +exec 3>&1 +m=`hash nosuchtool 2>&1 >&3` +r=$? +[ "$r" != 0 ] && [ -n "$m" ]