Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh NFC - DEBUG changes, update this to new TRACE method.
details: https://anonhg.NetBSD.org/src/rev/da534f414e53
branches: trunk
changeset: 354459:da534f414e53
user: kre <kre%NetBSD.org@localhost>
date: Sat Jun 17 11:53:24 2017 +0000
description:
NFC - DEBUG changes, update this to new TRACE method.
KNF - white space and comment formatting.
diffstat:
bin/sh/eval.c | 134 +++++++++++++++++++++++++++++----------------------------
1 files changed, 68 insertions(+), 66 deletions(-)
diffs (truncated from 313 to 300 lines):
diff -r 9cc09b5286dc -r da534f414e53 bin/sh/eval.c
--- a/bin/sh/eval.c Sat Jun 17 10:48:09 2017 +0000
+++ b/bin/sh/eval.c Sat Jun 17 11:53:24 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.147 2017/06/17 10:46:34 kre Exp $ */
+/* $NetBSD: eval.c,v 1.148 2017/06/17 11:53:24 kre 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.147 2017/06/17 10:46:34 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.148 2017/06/17 11:53:24 kre Exp $");
#endif
#endif /* not lint */
@@ -179,29 +179,29 @@
int
evalcmd(int argc, char **argv)
{
- char *p;
- char *concat;
- char **ap;
+ char *p;
+ char *concat;
+ char **ap;
- if (argc > 1) {
- p = argv[1];
- if (argc > 2) {
- STARTSTACKSTR(concat);
- ap = argv + 2;
- for (;;) {
- while (*p)
- STPUTC(*p++, concat);
- if ((p = *ap++) == NULL)
- break;
- STPUTC(' ', concat);
- }
- STPUTC('\0', concat);
- p = grabstackstr(concat);
- }
- evalstring(p, builtin_flags & EV_TESTED);
- } else
+ if (argc > 1) {
+ p = argv[1];
+ if (argc > 2) {
+ STARTSTACKSTR(concat);
+ ap = argv + 2;
+ for (;;) {
+ while (*p)
+ STPUTC(*p++, concat);
+ if ((p = *ap++) == NULL)
+ break;
+ STPUTC(' ', concat);
+ }
+ STPUTC('\0', concat);
+ p = grabstackstr(concat);
+ }
+ evalstring(p, builtin_flags & EV_TESTED);
+ } else
exitstatus = 0;
- return exitstatus;
+ return exitstatus;
}
@@ -219,7 +219,7 @@
setinputstring(s, 1, line_number);
while ((n = parsecmd(0)) != NEOF) {
- TRACE(("evalstring: "); showtree(n));
+ XTRACE(DBG_EVAL, ("evalstring: "), showtree(n));
if (nflag == 0)
evaltree(n, flag | EV_MORE);
popstackmark(&smark);
@@ -243,7 +243,8 @@
do_etest = false;
if (n == NULL || nflag) {
- TRACE(("evaltree(%s) called\n", n == NULL ? "NULL" : "-n"));
+ VTRACE(DBG_EVAL, ("evaltree(%s) called\n",
+ n == NULL ? "NULL" : "-n"));
if (nflag == 0)
exitstatus = 0;
goto out;
@@ -251,13 +252,8 @@
#ifndef SMALL
displayhist = 1; /* show history substitutions done with fc */
#endif
-#ifdef NODETYPENAME
- TRACE(("pid %d, evaltree(%p: %s(%d), %#x) called\n",
+ CTRACE(DBG_EVAL, ("pid %d, evaltree(%p: %s(%d), %#x) called\n",
getpid(), n, NODETYPENAME(n->type), n->type, flags));
-#else
- TRACE(("pid %d, evaltree(%p: %d, %#x) called\n",
- getpid(), n, n->type, flags));
-#endif
switch (n->type) {
case NSEMI:
evaltree(n->nbinary.ch1, (sflags & EV_TESTED) |
@@ -345,7 +341,7 @@
flushout(&output);
break;
}
-out:
+ out:
if (pendingsigs)
dotrap();
if ((flags & EV_EXIT) != 0 || (eflag && exitstatus != 0 && do_etest))
@@ -361,14 +357,11 @@
loopnest++;
status = 0;
-#ifdef NODETYPENAME
- TRACE(("evalloop %s: ", NODETYPENAME(n->type)));
-#else
- TRACE(("evalloop %s: ", n->type == NWHILE ? "while" : "until"));
-#endif
- TRACE((""); showtree(n->nbinary.ch1));
- TRACE(("evalloop do: "); showtree(n->nbinary.ch2));
- TRACE(("evalloop done\n"));
+ CTRACE(DBG_EVAL, ("evalloop %s:", NODETYPENAME(n->type)));
+ VXTRACE(DBG_EVAL, (" "), showtree(n->nbinary.ch1));
+ VXTRACE(DBG_EVAL, ("evalloop do: "), showtree(n->nbinary.ch2));
+ VTRACE(DBG_EVAL, ("evalloop done\n"));
+ CTRACE(DBG_EVAL, ("\n"));
for (;;) {
evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE);
@@ -455,7 +448,7 @@
}
loopnest--;
exitstatus = status;
-out:
+ out:
popstackmark(&smark);
}
@@ -579,7 +572,7 @@
int prevfd;
int pip[2];
- TRACE(("evalpipe(0x%lx) called\n", (long)n));
+ CTRACE(DBG_EVAL, ("evalpipe(%p) called\n", n));
pipelen = 0;
for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
pipelen++;
@@ -613,7 +606,8 @@
}
if (n->npipe.backgnd == 0) {
exitstatus = waitforjob(jp);
- TRACE(("evalpipe: job done exit status %d\n", exitstatus));
+ CTRACE(DBG_EVAL, ("evalpipe: job done exit status %d\n",
+ exitstatus));
} else
exitstatus = 0;
INTON;
@@ -673,9 +667,9 @@
result->jp = jp;
INTON;
}
-out:
+ out:
popstackmark(&smark);
- TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
+ CTRACE(DBG_EVAL, ("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
result->fd, result->buf, result->nleft, result->jp));
}
@@ -773,7 +767,7 @@
vforked = 0;
/* First expand the arguments. */
- TRACE(("evalcommand(%p, %d) called\n", cmd, flags));
+ CTRACE(DBG_EVAL, ("evalcommand(%p, %d) called\n", cmd, flags));
setstackmark(&smark);
back_exitstatus = 0;
@@ -824,7 +818,7 @@
argv = stalloc(sizeof (char *) * (argc + 1));
for (sp = arglist.list ; sp ; sp = sp->next) {
- TRACE(("evalcommand arg: %s\n", sp->text));
+ VTRACE(DBG_EVAL, ("evalcommand arg: %s\n", sp->text));
*argv++ = sp->text;
}
*argv = NULL;
@@ -950,7 +944,8 @@
switch (pid = vfork()) {
case -1:
serrno = errno;
- TRACE(("Vfork failed, errno=%d\n", serrno));
+ VTRACE(DBG_EVAL, ("vfork() failed, errno=%d\n",
+ serrno));
INTON;
error("Cannot vfork (%s)", strerror(serrno));
break;
@@ -961,9 +956,11 @@
SHELL_FORKED();
if (setjmp(jmploc.loc)) {
if (exception == EXSHELLPROC) {
- /* We can't progress with the vfork,
- * so, set vforked = 2 so the parent
- * knows, and _exit();
+ /*
+ * We can't progress with the
+ * vfork, so, set vforked = 2
+ * so the parent knows,
+ * and _exit();
*/
vforked = 2;
_exit(0);
@@ -978,23 +975,32 @@
break;
default:
VFORK_UNDO();
- handler = savehandler; /* restore from vfork(2) */
+ /* restore from vfork(2) */
+ handler = savehandler;
poplocalvars();
localvars = savelocalvars;
if (vforked == 2) {
vforked = 0;
(void)waitpid(pid, NULL, 0);
- /* We need to progress in a normal fork fashion */
+ /*
+ * We need to progress in a
+ * normal fork fashion
+ */
goto normal_fork;
}
+ /*
+ * Here the child has left home,
+ * getting on with its life, so
+ * so must we...
+ */
vforked = 0;
forkparent(jp, cmd, mode, pid);
goto parent;
}
VFORK_END
} else {
-normal_fork:
+ normal_fork:
#endif
if (forkshell(jp, cmd, mode) != 0)
goto parent; /* at end of routine */
@@ -1016,9 +1022,7 @@
/* Execute the command. */
switch (cmdentry.cmdtype) {
case CMDFUNCTION:
-#ifdef DEBUG
- trputs("Shell function: "); trargs(argv);
-#endif
+ VXTRACE(DBG_EVAL, ("Shell function: "), trargs(argv));
redirect(cmd->ncmd.redirect, flags & EV_MORE ? REDIR_PUSH : 0);
saveparam = shellparam;
shellparam.malloc = 0;
@@ -1088,9 +1092,7 @@
case CMDBUILTIN:
case CMDSPLBLTIN:
-#ifdef DEBUG
- trputs("builtin command: "); trargs(argv);
-#endif
+ VXTRACE(DBG_EVAL, ("builtin command: "), trargs(argv));
mode = (cmdentry.u.bltin == execcmd) ? 0 : REDIR_PUSH;
if (flags == EV_BACKCMD) {
memout.nleft = 0;
@@ -1104,7 +1106,8 @@
handler = &jmploc;
temp_path = 0;
if (!setjmp(jmploc.loc)) {
- /* We need to ensure the command hash table isn't
+ /*
+ * We need to ensure the command hash table isn't
* corrupted by temporary PATH assignments.
* However we must ensure the 'local' command works!
*/
@@ -1167,9 +1170,7 @@
break;
default:
-#ifdef DEBUG
- trputs("normal command: "); trargs(argv);
-#endif
+ VXTRACE(DBG_EVAL, ("normal command: "), trargs(argv));
redirect(cmd->ncmd.redirect,
(vforked ? REDIR_VFORK : 0) | REDIR_KEEP);
if (!vforked)
@@ -1181,7 +1182,8 @@
}
goto out;
-parent: /* parent process gets here (if we forked) */
+ parent: /* parent process gets here (if we forked) */
Home |
Main Index |
Thread Index |
Old Index