NFC - DEBUG changes, update this to new TRACE method.
KNF - white space and comment formatting.
This commit is contained in:
parent
9cda1315ff
commit
200131770d
|
@ -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 */
|
||||
|
||||
|
@ -219,7 +219,7 @@ evalstring(char *s, int flag)
|
|||
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 @@ evaltree(union node *n, int flags)
|
|||
|
||||
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 @@ evaltree(union node *n, int flags)
|
|||
#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) |
|
||||
|
@ -361,14 +357,11 @@ evalloop(union node *n, int flags)
|
|||
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);
|
||||
|
@ -579,7 +572,7 @@ evalpipe(union node *n)
|
|||
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 @@ evalpipe(union node *n)
|
|||
}
|
||||
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;
|
||||
|
@ -675,7 +669,7 @@ evalbackcmd(union node *n, struct backcmd *result)
|
|||
}
|
||||
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 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
|
|||
|
||||
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 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
|
|||
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 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
|
|||
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 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
|
|||
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,16 +975,25 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
|
|||
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;
|
||||
|
@ -1016,9 +1022,7 @@ normal_fork:
|
|||
/* 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 @@ normal_fork:
|
|||
|
||||
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 @@ normal_fork:
|
|||
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 @@ normal_fork:
|
|||
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)
|
||||
|
@ -1182,6 +1183,7 @@ normal_fork:
|
|||
goto out;
|
||||
|
||||
parent: /* parent process gets here (if we forked) */
|
||||
|
||||
exitstatus = 0; /* if not altered just below */
|
||||
if (mode == FORK_FG) { /* argument to fork */
|
||||
exitstatus = waitforjob(jp);
|
||||
|
|
Loading…
Reference in New Issue