Module Name: src
Committed By: christos
Date: Mon Feb 29 23:51:36 UTC 2016
Modified Files:
src/bin/sh: eval.c main.c
Log Message:
Complete implementation of the noexec option (-n) including
disabling noexec, if the shell is interactive, each time that
a new command is about to be read. Also correct the -I
(ignoreeof) option so that it only applies to interactive shells,
as required by posix. (from kre)
To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/bin/sh/eval.c
cvs rdiff -u -r1.60 -r1.61 src/bin/sh/main.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.114 src/bin/sh/eval.c:1.115
--- src/bin/sh/eval.c:1.114 Sat Feb 27 13:34:12 2016
+++ src/bin/sh/eval.c Mon Feb 29 18:51:36 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.114 2016/02/27 18:34:12 christos Exp $ */
+/* $NetBSD: eval.c,v 1.115 2016/02/29 23:51:36 christos Exp $ */
/*-
* Copyright (c) 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#else
-__RCSID("$NetBSD: eval.c,v 1.114 2016/02/27 18:34:12 christos Exp $");
+__RCSID("$NetBSD: eval.c,v 1.115 2016/02/29 23:51:36 christos Exp $");
#endif
#endif /* not lint */
@@ -243,37 +243,38 @@ evaltree(union node *n, int flags)
bool do_etest;
do_etest = false;
- if (n == NULL) {
- TRACE(("evaltree(NULL) called\n"));
- exitstatus = 0;
+ if (n == NULL || nflag) {
+ TRACE(("evaltree(%s) called\n", n == NULL ? "NULL" : "-n"));
+ if (nflag == 0)
+ exitstatus = 0;
goto out;
}
#ifndef SMALL
displayhist = 1; /* show history substitutions done with fc */
#endif
#ifdef NODETYPENAME
- TRACE(("pid %d, evaltree(%p: %s(%d), %d) called\n",
+ TRACE(("pid %d, evaltree(%p: %s(%d), %#x) called\n",
getpid(), n, NODETYPENAME(n->type), n->type, flags));
#else
- TRACE(("pid %d, evaltree(%p: %d, %d) called\n",
+ TRACE(("pid %d, evaltree(%p: %d, %#x) called\n",
getpid(), n, n->type, flags));
#endif
switch (n->type) {
case NSEMI:
evaltree(n->nbinary.ch1, flags & EV_TESTED);
- if (evalskip)
+ if (nflag || evalskip)
goto out;
evaltree(n->nbinary.ch2, flags);
break;
case NAND:
evaltree(n->nbinary.ch1, EV_TESTED);
- if (evalskip || exitstatus != 0)
+ if (nflag || evalskip || exitstatus != 0)
goto out;
evaltree(n->nbinary.ch2, flags);
break;
case NOR:
evaltree(n->nbinary.ch1, EV_TESTED);
- if (evalskip || exitstatus == 0)
+ if (nflag || evalskip || exitstatus == 0)
goto out;
evaltree(n->nbinary.ch2, flags);
break;
@@ -292,7 +293,7 @@ evaltree(union node *n, int flags)
break;
case NIF: {
evaltree(n->nif.test, EV_TESTED);
- if (evalskip)
+ if (nflag || evalskip)
goto out;
if (exitstatus == 0)
evaltree(n->nif.ifpart, flags);
@@ -329,7 +330,11 @@ evaltree(union node *n, int flags)
do_etest = !(flags & EV_TESTED);
break;
default:
+#ifdef NODETYPENAME
+ out1fmt("Node type = %d(%s)\n", n->type, NODETYPENAME(n->type));
+#else
out1fmt("Node type = %d\n", n->type);
+#endif
flushout(&output);
break;
}
@@ -360,6 +365,8 @@ evalloop(union node *n, int flags)
for (;;) {
evaltree(n->nbinary.ch1, EV_TESTED);
+ if (nflag)
+ break;
if (evalskip) {
skipping: if (evalskip == SKIPCONT && --skipcount <= 0) {
evalskip = SKIPNONE;
@@ -394,7 +401,9 @@ evalfor(union node *n, int flags)
union node *argp;
struct strlist *sp;
struct stackmark smark;
- int status = 0;
+ int status;
+
+ status = nflag ? exitstatus : 0;
setstackmark(&smark);
arglist.lastp = &arglist.list;
@@ -410,6 +419,8 @@ evalfor(union node *n, int flags)
setvar(n->nfor.var, sp->text, 0);
evaltree(n->nfor.body, flags & EV_TESTED);
status = exitstatus;
+ if (nflag)
+ break;
if (evalskip) {
if (evalskip == SKIPCONT && --skipcount <= 0) {
evalskip = SKIPNONE;
@@ -577,7 +588,8 @@ evalpipe(union node *n)
if (n->npipe.backgnd == 0) {
exitstatus = waitforjob(jp);
TRACE(("evalpipe: job done exit status %d\n", exitstatus));
- }
+ } else
+ exitstatus = 0;
INTON;
}
@@ -602,7 +614,7 @@ evalbackcmd(union node *n, struct backcm
result->buf = NULL;
result->nleft = 0;
result->jp = NULL;
- if (n == NULL) {
+ if (nflag || n == NULL) {
goto out;
}
#ifdef notyet
Index: src/bin/sh/main.c
diff -u src/bin/sh/main.c:1.60 src/bin/sh/main.c:1.61
--- src/bin/sh/main.c:1.60 Sat Feb 27 13:34:12 2016
+++ src/bin/sh/main.c Mon Feb 29 18:51:36 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.60 2016/02/27 18:34:12 christos Exp $ */
+/* $NetBSD: main.c,v 1.61 2016/02/29 23:51:36 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
#if 0
static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95";
#else
-__RCSID("$NetBSD: main.c,v 1.60 2016/02/27 18:34:12 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.61 2016/02/29 23:51:36 christos Exp $");
#endif
#endif /* not lint */
@@ -268,6 +268,7 @@ cmdloop(int top)
showjobs(out2, SHOW_CHANGED);
chkmail(0);
flushout(&errout);
+ nflag = 0;
}
n = parsecmd(inter);
TRACE(("cmdloop: "); showtree(n));
@@ -275,8 +276,10 @@ cmdloop(int top)
if (n == NEOF) {
if (!top || numeof >= 50)
break;
+ if (nflag)
+ break;
if (!stoppedjobs()) {
- if (!Iflag)
+ if (iflag && !Iflag)
break;
out2str("\nUse \"exit\" to leave shell.\n");
}