DEBUG mode changes only. NFC (NC) for any normally compiled shell.

Mostly adding DEBUG mode tracing (when appropriate verbose tracing
is enabled generally) whenever a shell (including sushell) process
exits, so shells that the tracing should indicate why ehslls that
vanish did that.

Note for future investigators: if the relevant tracing is enabled,
and a (sub-)shell still simply seems to have vanished without trace,
the likely cause is that it was killed by a signal - and of those,
the most common that occurs is SIGPIPE.
This commit is contained in:
kre 2021-11-10 15:26:34 +00:00
parent 806c442792
commit b8bee70d9c
5 changed files with 30 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: error.c,v 1.43 2019/02/04 11:16:41 kre Exp $ */
/* $NetBSD: error.c,v 1.44 2021/11/10 15:26:34 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: error.c,v 1.43 2019/02/04 11:16:41 kre Exp $");
__RCSID("$NetBSD: error.c,v 1.44 2021/11/10 15:26:34 kre Exp $");
#endif
#endif /* not lint */
@ -221,6 +221,7 @@ exerror(int cond, const char *msg, ...)
void
sh_exit(int rval)
{
VTRACE(DBG_ERRS|DBG_PROCS|DBG_CMDS, ("sh_exit(%d)\n", rval));
exerrno = rval & 255;
exraise(EXEXEC);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: eval.c,v 1.182 2021/04/04 13:24:07 kre Exp $ */
/* $NetBSD: eval.c,v 1.183 2021/11/10 15:26:34 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.182 2021/04/04 13:24:07 kre Exp $");
__RCSID("$NetBSD: eval.c,v 1.183 2021/11/10 15:26:34 kre Exp $");
#endif
#endif /* not lint */
@ -1131,6 +1131,12 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
*/
SHELL_FORKED();
if (setjmp(jmploc.loc)) {
VTRACE(DBG_EVAL|DBG_ERRS|
DBG_PROCS|DBG_CMDS|DBG_TRAP,
("vfork child exit exception:%d "
"exitstatus:%d exerrno:%d\n",
exception, exitstatus, exerrno));
if (exception == EXSHELLPROC) {
/*
* We can't progress with the

View File

@ -1,4 +1,4 @@
/* $NetBSD: expand.c,v 1.139 2021/09/10 22:11:03 rillig Exp $ */
/* $NetBSD: expand.c,v 1.140 2021/11/10 15:26:34 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
#else
__RCSID("$NetBSD: expand.c,v 1.139 2021/09/10 22:11:03 rillig Exp $");
__RCSID("$NetBSD: expand.c,v 1.140 2021/11/10 15:26:34 kre Exp $");
#endif
#endif /* not lint */
@ -148,6 +148,7 @@ expandhere(union node *arg, int fd)
{
int len;
VTRACE(DBG_EXPAND|DBG_REDIR, ("expandhere() fd=%d\n", fd));
herefd = fd;
expandarg(arg, NULL, 0);
len = rmescapes(stackblock());
@ -193,8 +194,9 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
argstr(arg->narg.text, flag);
if (arglist == NULL) {
STACKSTRNUL(expdest);
CTRACE(DBG_EXPAND, ("expandarg: no arglist, done (%d) \"%s\"\n",
expdest - stackblock(), stackblock()));
CTRACE(DBG_EXPAND,
("expandarg: no arglist, done[%d] (len %d) \"%s\"\n",
back_exitstatus, expdest - stackblock(), stackblock()));
return; /* here document expanded */
}
STPUTC('\0', expdest);
@ -698,7 +700,8 @@ expbackq(union node *cmd, int quoted, int flag)
back_exitstatus = waitforjob(in.jp);
if (quoted == 0)
recordregion(startloc, dest - stackblock(), 0);
CTRACE(DBG_EXPAND, ("evalbackq: size=%d: \"%.*s\"\n",
CTRACE(DBG_EXPAND, ("evalbackq: [%d] size=%d: \"%.*s\"\n",
back_exitstatus,
(int)((dest - stackblock()) - startloc),
(int)((dest - stackblock()) - startloc),
stackblock() + startloc));

View File

@ -1,4 +1,4 @@
/* $NetBSD: redir.c,v 1.69 2021/09/15 20:21:47 kre Exp $ */
/* $NetBSD: redir.c,v 1.70 2021/11/10 15:26:34 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: redir.c,v 1.69 2021/09/15 20:21:47 kre Exp $");
__RCSID("$NetBSD: redir.c,v 1.70 2021/11/10 15:26:34 kre Exp $");
#endif
#endif /* not lint */
@ -480,7 +480,7 @@ openhere(const union node *redir)
xwrite(pip[1], redir->nhere.doc->narg.text, len);
else
expandhere(redir->nhere.doc, pip[1]);
VTRACE(DBG_PROCS|DBG_REDIR, ("wrote here doc. exiting\n"));
VTRACE(DBG_PROCS|DBG_REDIR, ("wrote here doc. exiting(0)\n"));
_exit(0);
}
VTRACE(DBG_REDIR, ("openhere (closing %d)", pip[1]));

View File

@ -1,4 +1,4 @@
/* $NetBSD: trap.c,v 1.55 2020/08/20 23:09:56 kre Exp $ */
/* $NetBSD: trap.c,v 1.56 2021/11/10 15:26:34 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95";
#else
__RCSID("$NetBSD: trap.c,v 1.55 2020/08/20 23:09:56 kre Exp $");
__RCSID("$NetBSD: trap.c,v 1.56 2021/11/10 15:26:34 kre Exp $");
#endif
#endif /* not lint */
@ -908,8 +908,14 @@ exitshell_savedstatus(void)
sigaddset(&sigs, s);
sigprocmask(SIG_UNBLOCK, &sigs, NULL);
VTRACE(DBG_ERRS|DBG_PROCS|DBG_CMDS|DBG_TRAP,
("exitshell_savedstatus(): pid %d Death by signal %d\n",
getpid(), s));
kill(getpid(), s);
}
VTRACE(DBG_ERRS|DBG_PROCS|DBG_CMDS|DBG_TRAP,
("exitshell_savedstatus(): pid %d exiting(%d)\n",
getpid(), exiting_status));
_exit(exiting_status);
/* NOTREACHED */
}