From dc82a6f6007700dc5a0ed7e1813bb664d47aeacf Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 3 Jan 2010 15:01:38 +0000 Subject: [PATCH] sh: Send the "not found" message for builtin to redirected fd 2. --- bin/sh/eval.c | 16 +++++++---- tools/regression/bin/sh/builtins/builtin1.0 | 31 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 tools/regression/bin/sh/builtins/builtin1.0 diff --git a/bin/sh/eval.c b/bin/sh/eval.c index f2caafb0659e..30e05b8b6435 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -722,9 +722,10 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) break; if ((cmdentry.u.index = find_builtin(*argv, &cmdentry.special)) < 0) { - out2fmt_flush("%s: not found\n", *argv); - exitstatus = 127; - return; + cmdentry.u.index = BLTINCMD; + argv--; + argc++; + break; } if (cmdentry.u.index != BLTINCMD) break; @@ -944,12 +945,17 @@ prehash(union node *n) */ /* - * No command given, or a bltin command with no arguments. + * No command given, a bltin command with no arguments, or a bltin command + * with an invalid name. */ int -bltincmd(int argc __unused, char **argv __unused) +bltincmd(int argc, char **argv) { + if (argc > 1) { + out2fmt_flush("%s: not found\n", argv[1]); + return 127; + } /* * Preserve exitstatus of a previous possible redirection * as POSIX mandates diff --git a/tools/regression/bin/sh/builtins/builtin1.0 b/tools/regression/bin/sh/builtins/builtin1.0 new file mode 100644 index 000000000000..b6083858f671 --- /dev/null +++ b/tools/regression/bin/sh/builtins/builtin1.0 @@ -0,0 +1,31 @@ +# $FreeBSD$ + +failures=0 + +check() { + if ! eval "[ $* ]"; then + echo "Failed: $*" + : $((failures += 1)) + fi +} + +builtin : || echo "Bad return code at $LINENO" +builtin true || echo "Bad return code at $LINENO" +builtin ls 2>/dev/null && echo "Bad return code at $LINENO" +check '"$(builtin pwd)" = "$(pwd)"' +check '-z "$(builtin :)"' +check '-z "$(builtin true)"' +check '-z "$( (builtin nosuchtool) 2>/dev/null)"' +check '-z "$(builtin nosuchtool 2>/dev/null)"' +check '-z "$(builtin nosuchtool 2>/dev/null; :)"' +check '-z "$( (builtin ls) 2>/dev/null)"' +check '-z "$(builtin ls 2>/dev/null)"' +check '-z "$(builtin ls 2>/dev/null; :)"' +check '-n "$( (builtin nosuchtool) 2>&1)"' +check '-n "$(builtin nosuchtool 2>&1)"' +check '-n "$(builtin nosuchtool 2>&1; :)"' +check '-n "$( (builtin ls) 2>&1)"' +check '-n "$(builtin ls 2>&1)"' +check '-n "$(builtin ls 2>&1; :)"' + +exit $((failures > 0))