summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/sh/eval.c6
-rw-r--r--bin/sh/main.c10
-rw-r--r--tools/regression/bin/sh/builtins/dot2.021
-rw-r--r--tools/regression/bin/sh/builtins/exec2.025
4 files changed, 60 insertions, 2 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index a47d045..e2f66ed 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -1170,6 +1170,12 @@ truecmd(int argc __unused, char **argv __unused)
int
execcmd(int argc, char **argv)
{
+ /*
+ * Because we have historically not supported any options,
+ * only treat "--" specially.
+ */
+ if (argc > 1 && strcmp(argv[1], "--") == 0)
+ argc--, argv++;
if (argc > 1) {
struct strlist *sp;
diff --git a/bin/sh/main.c b/bin/sh/main.c
index ecbb12d..15ee9e7 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -314,14 +314,20 @@ find_dot_file(char *basename)
int
dotcmd(int argc, char **argv)
{
- char *fullname;
+ char *filename, *fullname;
if (argc < 2)
error("missing filename");
exitstatus = 0;
- fullname = find_dot_file(argv[1]);
+ /*
+ * Because we have historically not supported any options,
+ * only treat "--" specially.
+ */
+ filename = argc > 2 && strcmp(argv[1], "--") == 0 ? argv[2] : argv[1];
+
+ fullname = find_dot_file(filename);
setinputfile(fullname, 1);
commandname = fullname;
cmdloop(0);
diff --git a/tools/regression/bin/sh/builtins/dot2.0 b/tools/regression/bin/sh/builtins/dot2.0
new file mode 100644
index 0000000..ed6379b
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/dot2.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=
+failure() {
+ echo "Error at line $1" >&2
+ failures=x$failures
+}
+
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || exit
+trap 'rm -rf $T' 0
+cd $T || exit 3
+unset x
+echo 'x=2' >testscript
+. -- ./testscript
+[ "$x" = 2 ] || failure $LINENO
+cd / || exit 3
+x=1
+PATH=$T:$PATH . -- testscript
+[ "$x" = 2 ] || failure $LINENO
+
+test -z "$failures"
diff --git a/tools/regression/bin/sh/builtins/exec2.0 b/tools/regression/bin/sh/builtins/exec2.0
new file mode 100644
index 0000000..a04bf34
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/exec2.0
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+failures=
+failure() {
+ echo "Error at line $1" >&2
+ failures=x$failures
+}
+
+(
+ exec -- >/dev/null
+ echo bad
+)
+[ $? = 0 ] || failure $LINENO
+(
+ exec -- sh -c 'exit 42'
+ echo bad
+)
+[ $? = 42 ] || failure $LINENO
+(
+ exec -- /var/empty/nosuch
+ echo bad
+) 2>/dev/null
+[ $? = 127 ] || failure $LINENO
+
+test -z "$failures"
OpenPOWER on IntegriCloud