diff --git a/Makefile b/Makefile index 4ae8241..ce738af 100644 --- a/Makefile +++ b/Makefile @@ -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, # 2011, 2012 @@ -18,8 +18,13 @@ # 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 # 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 @@ -138,3 +143,15 @@ cats: ${MANALL} ${MANALL:S/.cat/.ps/} do_conversion_verbose "$$bn" "$$ext" "$$m" "$$bn.$$ext.htm"; \ rm -f "$$bn.$$ext.htm.gz"; gzip -n9 "$$bn.$$ext.htm"; \ 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" diff --git a/main.c b/main.c index 267aea6..2d39053 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #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; @@ -1291,14 +1291,20 @@ struct shf shf_iob[NSHF_IOB]; void initio(void) { +#ifdef DF + const char *lfp; +#endif + /* force buffer allocation */ shf_fdopen(1, SHF_WR, shl_stdout); shf_fdopen(2, SHF_WR, shl_out); shf_fdopen(2, SHF_WR, shl_spare); #ifdef DF - if ((shl_dbg_fd = open("/tmp/mksh-dbg.txt", - O_WRONLY | O_APPEND | O_CREAT, 0600)) == -1) - errorf("cannot open debug output file"); + if ((lfp = getenv("SDMKSH_PATH")) == NULL) + lfp = "/tmp/mksh-dbg.txt"; + + 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) { int nfd; @@ -1307,6 +1313,7 @@ initio(void) if ((shl_dbg_fd = nfd) == -1) errorf("cannot dup debug output file"); } + fcntl(shl_dbg_fd, F_SETFD, FD_CLOEXEC); shf_fdopen(shl_dbg_fd, SHF_WR, shl_dbg); DF("=== open ==="); #endif @@ -1773,11 +1780,15 @@ DF(const char *fmt, ...) { va_list args; struct timeval tv; + mirtime_mjd mjd; mksh_lockfd(shl_dbg_fd); mksh_TIME(tv); - shf_fprintf(shl_dbg, "[%d.%06d:%d] ", (int)tv.tv_sec, (int)tv.tv_usec, - (int)getpid()); + timet2mjd(&mjd, tv.tv_sec); + 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); shf_vfprintf(shl_dbg, fmt, args); va_end(args);