aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2010-04-20 22:52:28 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2010-04-20 22:52:28 +0000
commitf08f4ed3740e0558812910493fe7b0e611f83ba0 (patch)
tree5d4741019ed49f5a1f4dc8852d706faa3a6c0f48
parenta6cd5bcfbf09411e540b34fd0c315612cb7371e1 (diff)
Notes
-rw-r--r--bin/sh/main.c2
-rw-r--r--bin/sh/var.c7
-rw-r--r--tools/regression/bin/sh/parameters/mail1.015
-rw-r--r--tools/regression/bin/sh/parameters/mail2.015
4 files changed, 38 insertions, 1 deletions
diff --git a/bin/sh/main.c b/bin/sh/main.c
index 6aa588faec83..42756e881bae 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -157,6 +157,8 @@ main(int argc, char *argv[])
out2str("sh: cannot determine working directory\n");
if (getpwd() != NULL)
setvar ("PWD", getpwd(), VEXPORT);
+ if (iflag)
+ chkmail(1);
if (argv[0] && argv[0][0] == '-') {
state = 1;
read_profile("/etc/profile");
diff --git a/bin/sh/var.c b/bin/sh/var.c
index 62382b21c500..3188b28f6156 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -335,8 +335,13 @@ setvareq(char *s, int flags)
/*
* We could roll this to a function, to handle it as
* a regular variable function callback, but why bother?
+ *
+ * Note: this assumes iflag is not set to 1 initially.
+ * As part of init(), this is called before arguments
+ * are looked at.
*/
- if (vp == &vmpath || (vp == &vmail && ! mpathset()))
+ if ((vp == &vmpath || (vp == &vmail && ! mpathset())) &&
+ iflag == 1)
chkmail(1);
if ((vp->flags & VEXPORT) && localevar(s)) {
change_env(s, 1);
diff --git a/tools/regression/bin/sh/parameters/mail1.0 b/tools/regression/bin/sh/parameters/mail1.0
new file mode 100644
index 000000000000..26308eadbdc4
--- /dev/null
+++ b/tools/regression/bin/sh/parameters/mail1.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+# Test that a non-interactive shell does not access $MAIL.
+
+goodfile=/var/empty/sh-test-goodfile
+mailfile=/var/empty/sh-test-mailfile
+T=$(mktemp sh-test.XXXXXX) || exit
+MAIL=$mailfile ktrace -i -f "$T" sh -c "[ -s $goodfile ]" 2>/dev/null
+if ! grep -q $goodfile "$T"; then
+ # ktrace problem
+ rc=0
+elif ! grep -q $mailfile "$T"; then
+ rc=0
+fi
+rm "$T"
+exit ${rc:-3}
diff --git a/tools/regression/bin/sh/parameters/mail2.0 b/tools/regression/bin/sh/parameters/mail2.0
new file mode 100644
index 000000000000..e3b7da341328
--- /dev/null
+++ b/tools/regression/bin/sh/parameters/mail2.0
@@ -0,0 +1,15 @@
+# $FreeBSD$
+# Test that an interactive shell accesses $MAIL.
+
+goodfile=/var/empty/sh-test-goodfile
+mailfile=/var/empty/sh-test-mailfile
+T=$(mktemp sh-test.XXXXXX) || exit
+ENV=$goodfile MAIL=$mailfile ktrace -i -f "$T" sh +m -i </dev/null >/dev/null 2>&1
+if ! grep -q $goodfile "$T"; then
+ # ktrace problem
+ rc=0
+elif grep -q $mailfile "$T"; then
+ rc=0
+fi
+rm "$T"
+exit ${rc:-3}