Module Name: src Committed By: kre Date: Wed Nov 10 15:26:34 UTC 2021
Modified Files: src/bin/sh: error.c eval.c expand.c redir.c trap.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/bin/sh/error.c cvs rdiff -u -r1.182 -r1.183 src/bin/sh/eval.c cvs rdiff -u -r1.139 -r1.140 src/bin/sh/expand.c cvs rdiff -u -r1.69 -r1.70 src/bin/sh/redir.c cvs rdiff -u -r1.55 -r1.56 src/bin/sh/trap.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/error.c diff -u src/bin/sh/error.c:1.43 src/bin/sh/error.c:1.44 --- src/bin/sh/error.c:1.43 Mon Feb 4 11:16:41 2019 +++ src/bin/sh/error.c Wed Nov 10 15:26:34 2021 @@ -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); } Index: src/bin/sh/eval.c diff -u src/bin/sh/eval.c:1.182 src/bin/sh/eval.c:1.183 --- src/bin/sh/eval.c:1.182 Sun Apr 4 13:24:07 2021 +++ src/bin/sh/eval.c Wed Nov 10 15:26:34 2021 @@ -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, s */ 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 Index: src/bin/sh/expand.c diff -u src/bin/sh/expand.c:1.139 src/bin/sh/expand.c:1.140 --- src/bin/sh/expand.c:1.139 Fri Sep 10 22:11:03 2021 +++ src/bin/sh/expand.c Wed Nov 10 15:26:34 2021 @@ -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 arglis 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, in 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)); Index: src/bin/sh/redir.c diff -u src/bin/sh/redir.c:1.69 src/bin/sh/redir.c:1.70 --- src/bin/sh/redir.c:1.69 Wed Sep 15 20:21:47 2021 +++ src/bin/sh/redir.c Wed Nov 10 15:26:34 2021 @@ -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])); Index: src/bin/sh/trap.c diff -u src/bin/sh/trap.c:1.55 src/bin/sh/trap.c:1.56 --- src/bin/sh/trap.c:1.55 Thu Aug 20 23:09:56 2020 +++ src/bin/sh/trap.c Wed Nov 10 15:26:34 2021 @@ -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 */ }