sh: Make 'hash' return 1 if at least one utility is not found.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sun, 15 Jul 2012 07:31:52 +0000 (00:31 -0700)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 15 Jul 2012 07:31:52 +0000 (00:31 -0700)
Obtained-from: FreeBSD 231535

bin/sh/exec.c
tools/regression/bin/sh/builtins/hash4.0 [new file with mode: 0644]

index bf252fb..202a74b 100644 (file)
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  *
  * @(#)exec.c  8.4 (Berkeley) 6/8/95
- * $FreeBSD: src/bin/sh/exec.c,v 1.53 2012/01/01 22:17:12 jilles Exp $
+ * $FreeBSD: src/bin/sh/exec.c,v 1.55 2012/02/11 21:06:45 jilles Exp $
  */
 
 #include <sys/types.h>
@@ -228,7 +228,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') {
@@ -251,19 +253,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 (file)
index 0000000..5650500
--- /dev/null
@@ -0,0 +1,6 @@
+# $FreeBSD: src/tools/regression/bin/sh/builtins/hash4.0,v 1.1 2012/02/11 21:06:45 jilles Exp $
+
+exec 3>&1
+m=`hash nosuchtool 2>&1 >&3`
+r=$?
+[ "$r" != 0 ] && [ -n "$m" ]