add split-screen debugging; close-on-exec the logfile

This commit is contained in:
tg 2012-10-21 17:16:45 +00:00
parent b3c7268f02
commit 77f5b8f38d
2 changed files with 37 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.103 2012/10/14 16:22:49 tg Exp $ # $MirOS: src/bin/mksh/Makefile,v 1.104 2012/10/21 17:16:44 tg Exp $
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 # 2011, 2012
@ -18,8 +18,13 @@
# of dealing in the work, even if advised of the possibility of such # of dealing in the work, even if advised of the possibility of such
# damage or existence of a defect, except proven that it results out # damage or existence of a defect, except proven that it results out
# of said person's immediate fault when using the work as intended. # of said person's immediate fault when using the work as intended.
#-
# use CPPFLAGS=-DDEBUG __CRAZY=Yes to check for certain more stuff .ifmake d
__CRAZY= Yes
MKC_DEBG= cpp
DEBUGFILE= Yes
NOMAN= Yes
.endif
.include <bsd.own.mk> .include <bsd.own.mk>
@ -138,3 +143,15 @@ cats: ${MANALL} ${MANALL:S/.cat/.ps/}
do_conversion_verbose "$$bn" "$$ext" "$$m" "$$bn.$$ext.htm"; \ do_conversion_verbose "$$bn" "$$ext" "$$m" "$$bn.$$ext.htm"; \
rm -f "$$bn.$$ext.htm.gz"; gzip -n9 "$$bn.$$ext.htm"; \ rm -f "$$bn.$$ext.htm.gz"; gzip -n9 "$$bn.$$ext.htm"; \
done done
.ifmake d
. ifmake obj || depend || all || install || regress || test-build
d:
. else
d: all
. endif
.endif
dr:
p=$$(realpath ${PROG:Q}) && cd ${.CURDIR:Q} && exec ${MKSH} \
${BSDSRCDIR:Q}/contrib/hosted/tg/sdmksh "$$p"

23
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.228 2012/09/21 17:20:21 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.229 2012/10/21 17:16:45 tg Exp $");
extern char **environ; extern char **environ;
@ -1291,14 +1291,20 @@ struct shf shf_iob[NSHF_IOB];
void void
initio(void) initio(void)
{ {
#ifdef DF
const char *lfp;
#endif
/* force buffer allocation */ /* force buffer allocation */
shf_fdopen(1, SHF_WR, shl_stdout); shf_fdopen(1, SHF_WR, shl_stdout);
shf_fdopen(2, SHF_WR, shl_out); shf_fdopen(2, SHF_WR, shl_out);
shf_fdopen(2, SHF_WR, shl_spare); shf_fdopen(2, SHF_WR, shl_spare);
#ifdef DF #ifdef DF
if ((shl_dbg_fd = open("/tmp/mksh-dbg.txt", if ((lfp = getenv("SDMKSH_PATH")) == NULL)
O_WRONLY | O_APPEND | O_CREAT, 0600)) == -1) lfp = "/tmp/mksh-dbg.txt";
errorf("cannot open debug output file");
if ((shl_dbg_fd = open(lfp, O_WRONLY | O_APPEND | O_CREAT, 0600)) == -1)
errorf("cannot open debug output file %s", lfp);
if (shl_dbg_fd < FDBASE) { if (shl_dbg_fd < FDBASE) {
int nfd; int nfd;
@ -1307,6 +1313,7 @@ initio(void)
if ((shl_dbg_fd = nfd) == -1) if ((shl_dbg_fd = nfd) == -1)
errorf("cannot dup debug output file"); errorf("cannot dup debug output file");
} }
fcntl(shl_dbg_fd, F_SETFD, FD_CLOEXEC);
shf_fdopen(shl_dbg_fd, SHF_WR, shl_dbg); shf_fdopen(shl_dbg_fd, SHF_WR, shl_dbg);
DF("=== open ==="); DF("=== open ===");
#endif #endif
@ -1773,11 +1780,15 @@ DF(const char *fmt, ...)
{ {
va_list args; va_list args;
struct timeval tv; struct timeval tv;
mirtime_mjd mjd;
mksh_lockfd(shl_dbg_fd); mksh_lockfd(shl_dbg_fd);
mksh_TIME(tv); mksh_TIME(tv);
shf_fprintf(shl_dbg, "[%d.%06d:%d] ", (int)tv.tv_sec, (int)tv.tv_usec, timet2mjd(&mjd, tv.tv_sec);
(int)getpid()); shf_fprintf(shl_dbg, "[%02u:%02u:%02u (%u) %u.%06u] ",
(unsigned)mjd.sec / 3600, ((unsigned)mjd.sec / 60) % 60,
(unsigned)mjd.sec % 60, (unsigned)getpid(),
(unsigned)tv.tv_sec, (unsigned)tv.tv_usec);
va_start(args, fmt); va_start(args, fmt);
shf_vfprintf(shl_dbg, fmt, args); shf_vfprintf(shl_dbg, fmt, args);
va_end(args); va_end(args);