Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Complete implementation of the noexec option (-n) inc...
details: https://anonhg.NetBSD.org/src/rev/4d67d4428baa
branches: trunk
changeset: 814033:4d67d4428baa
user: christos <christos%NetBSD.org@localhost>
date: Mon Feb 29 23:51:36 2016 +0000
description:
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)
diffstat:
bin/sh/eval.c | 40 ++++++++++++++++++++++++++--------------
bin/sh/main.c | 9 ++++++---
2 files changed, 32 insertions(+), 17 deletions(-)
diffs (172 lines):
diff -r 5d2b5965cd58 -r 4d67d4428baa bin/sh/eval.c
--- a/bin/sh/eval.c Mon Feb 29 23:50:59 2016 +0000
+++ b/bin/sh/eval.c Mon Feb 29 23:51:36 2016 +0000
@@ -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 @@
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 @@
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 @@
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 @@
for (;;) {
evaltree(n->nbinary.ch1, EV_TESTED);
+ if (nflag)
+ break;
if (evalskip) {
skipping: if (evalskip == SKIPCONT && --skipcount <= 0) {
evalskip = SKIPNONE;
@@ -394,7 +401,9 @@
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 @@
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 @@
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 @@
result->buf = NULL;
result->nleft = 0;
result->jp = NULL;
- if (n == NULL) {
+ if (nflag || n == NULL) {
goto out;
}
#ifdef notyet
diff -r 5d2b5965cd58 -r 4d67d4428baa bin/sh/main.c
--- a/bin/sh/main.c Mon Feb 29 23:50:59 2016 +0000
+++ b/bin/sh/main.c Mon Feb 29 23:51:36 2016 +0000
@@ -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 @@
#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 @@
showjobs(out2, SHOW_CHANGED);
chkmail(0);
flushout(&errout);
+ nflag = 0;
}
n = parsecmd(inter);
TRACE(("cmdloop: "); showtree(n));
@@ -275,8 +276,10 @@
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");
}
Home |
Main Index |
Thread Index |
Old Index