From 6a5d0cf1c0a39abcf664e579d4844baf976be409 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 8 Jan 1999 20:25:06 +0000 Subject: bug fixes from pdksh-unstable-5.2.13.5; some of which we already had. --- bin/ksh/BUG-REPORTS | 36 ++++++++++++++++++++++-- bin/ksh/CONTRIBUTORS | 4 ++- bin/ksh/ChangeLog | 49 +++++++++++++++++++++++++++++++- bin/ksh/NEWS | 8 +++++- bin/ksh/NOTES | 16 ++++++++++- bin/ksh/c_ksh.c | 6 ++-- bin/ksh/c_sh.c | 26 +++++++++++++---- bin/ksh/c_ulimit.c | 4 +-- bin/ksh/config.h | 9 +++++- bin/ksh/edit.c | 5 ++-- bin/ksh/eval.c | 4 +-- bin/ksh/exec.c | 4 +-- bin/ksh/io.c | 66 ++++++++++++++++++++++++++++++++++++++++++- bin/ksh/jobs.c | 10 +++++-- bin/ksh/main.c | 24 ++++++++++++---- bin/ksh/misc.c | 73 ++++++++++++++++++++++++++++++++---------------- bin/ksh/proto.h | 11 ++++++-- bin/ksh/sh.h | 12 +++++++- bin/ksh/shf.h | 7 ++++- bin/ksh/tests/regress.t | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ bin/ksh/tests/version.t | 2 +- bin/ksh/trap.c | 23 +++++++++++---- bin/ksh/var.c | 13 ++++++++- bin/ksh/version.c | 4 +-- bin/ksh/vi.c | 5 ++-- 25 files changed, 421 insertions(+), 74 deletions(-) (limited to 'bin') diff --git a/bin/ksh/BUG-REPORTS b/bin/ksh/BUG-REPORTS index 739cd4272b6..4926186d0be 100644 --- a/bin/ksh/BUG-REPORTS +++ b/bin/ksh/BUG-REPORTS @@ -1,4 +1,4 @@ -$OpenBSD: BUG-REPORTS,v 1.7 1998/10/29 04:09:18 millert Exp $ +$OpenBSD: BUG-REPORTS,v 1.8 1999/01/08 20:24:54 millert Exp $ List of reported problems (problems reported and fixed before 5.0.4 not included). Unresolved problems (may or may not still exist) marked by *, @@ -88,8 +88,12 @@ problems believed to be fixed marked by x. * pdksh 5.2.12, - : MAILCHECK isn't preserved from the envirnment on startup. -* pdksh 5.2.13, (reported by Dmitri Kulginov): "trap exit 1" does not set a - trap for HUP (exit is mistaken as a signal name, not a command). +* pdksh 5.2.12, (reported by Michael Staats): emacs: file completion does + not complete as much as possible when file is ~/something (will list + possible completions but won't fill in to the first difference). + Happens since code doesn't distinguish between globbing and ~ (needs + special case to strip & replace a leading ~ during the completion + process). --------------------- put fixed problems below this line --------------------- @@ -1293,3 +1297,29 @@ x pdksh 5.2.13, - (reported by Clifford Wolf): sys_siglist[] doesn't [see Mail.XXX] [fixed in 5.2.14: trap.c(inittrap): check for null sys_siglist entries.] +x pdksh 5.2.13, - (reported with fix by Todd C. Miller): waitfor in jobs.c + can cause core dump if j_lookup fails. + [fixed in 5.2.14: jobs.c(waitfor): return if j_lookup fails] + +x pdksh 5.2.13, - (reported by Martin Bond): if shell is started several + times in quick succession, echo $RANDOM produces the same results. + [fixed in 5.2.14: main.c(main): seed RANDOM using time, pid, ppid] + +x pdksh 5.2.13, - (reported by Martin Bond): repeating "echo `echo $RANDOM`" + will always produce the same number. + [fixed in 5.2.14: call var.c(change_random) from jobs.c(exchild)] + +x pdksh 5.2.13, hpux 10.x (reported by Mike Kelly): pwd will dump core if + current directory is not readable. + [fixed in 5.2.14: config test & code to work around hpux C library bug] + +x pdksh 5.2.13, linux (reported by Mike Jetzer): getwd warning from linker + [fixed in 5.2.14: configure.in/misc.c: check for getcwd, use it over getwd] + +x pdksh 5.2.13, (reported by Dmitri Kulginov): "trap exit 1" does not set a + trap for HUP (exit is mistaken as a signal name, not a command). + [fixed in 5.2.14: c_sh.c(c_trap): use case sensitive lookup for first arg] + +x pdksh 5.2.13, (reported by Mark Funkenhauser): eval "$(false)" does not + result in $? being set to 1 (is 0). + [fixed in 5.2.14: c_sh.c(c_eval): set exstat to subst_exstat before shell()] diff --git a/bin/ksh/CONTRIBUTORS b/bin/ksh/CONTRIBUTORS index cdd9d88982b..801a81c1be3 100644 --- a/bin/ksh/CONTRIBUTORS +++ b/bin/ksh/CONTRIBUTORS @@ -1,4 +1,4 @@ -$OpenBSD: CONTRIBUTORS,v 1.5 1998/10/29 04:09:19 millert Exp $ +$OpenBSD: CONTRIBUTORS,v 1.6 1999/01/08 20:24:56 millert Exp $ This is a partial history of this shell gleened from old change logs and readmes (most of which are still in the misc directory) and the source @@ -116,3 +116,5 @@ Other contributors: * Theo de Raadt (): allow ". /dev/null". * Eric Youngdale (): flag field incorrectly changed in exec.c(flushcom). + * Todd. C Miller (Todd C. Miller ): fix + for coredump in jobs. diff --git a/bin/ksh/ChangeLog b/bin/ksh/ChangeLog index ebdf9ce28ad..0e2987437c9 100644 --- a/bin/ksh/ChangeLog +++ b/bin/ksh/ChangeLog @@ -1,3 +1,50 @@ +Wed Dec 16 15:02:48 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * io.c(kshdebug_init_,kshdebug_printf_,kshdebug_dump_), + sh.h(kshdebug_init,kshdebug_printf,kshdebug_dump): + new macros/functions. + +Wed Dec 16 12:12:23 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * c_sh.c(c_eval): set exstat to substs_exstat to propogate + substition exit status if resulting command is empty + (based on fix from Mark Funkenhauser). + +Tue Dec 15 15:50:34 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * main.c(initcom[]): PPID no longer read only. + +Mon Dec 14 17:09:52 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * trap.c(gettrap): added igncase argument; changed all calls. + * c_sh.c(c_trap): use case sensitive compare for first gettrap(). + (fix "trap exit 1"). + +Thu Dec 10 12:24:53 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * configure.in: added test for getcwd. + * aclocal.m4(KSH_OS_TYPE): added case for hpux; added test for + bug in hpux getcwd (dumps core if . is not readable). + * config.h.in: added HAVE_HPUX_GETWD_BUG define. + * aclocal.m4,configure.in: remove AC_C_CROSS or change to AC_PROG_CC. + * misc.c(ksh_get_wd): added code to handle bug in hpux getwd; + changed precedence of getcwd vs getwd (use getcwd if available: + getwd causes warnings under linux). + +Tue Dec 8 17:17:47 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * main.c(main): seed RANDOM using time, pid, ppid (was just time). + +Tue Nov 24 17:17:12 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * c_ulimit.c(c_ulimit): improve setrlimit error message for EPERM + (fix from Todd C. Miller). + +Thu Nov 19 18:09:59 NST 1998 Michael Rendell (michael@panda.cs.mun.ca) + + * jobs.c(waitfor): if j_lookup fails, always return + (fix from Todd C. Miller). + Fri Oct 23 19:59:25 NDT 1998 Michael Rendell (michael@lenny.cs.mun.ca) * jobs.c(JF_SAVEDTTYPGRP,j_resume,j_waitj): added save_ttypgrp @@ -243,7 +290,7 @@ Wed Oct 30 11:23:17 NST 1996 Michael Rendell (michael@panda.cs.mun.ca) * exec.c(comexec): case CFUNC: set $0 to kshname if non-function function. -$OpenBSD: ChangeLog,v 1.7 1998/10/29 04:09:19 millert Exp $ +$OpenBSD: ChangeLog,v 1.8 1999/01/08 20:24:56 millert Exp $ Tue Oct 29 11:34:58 NST 1996 Michael Rendell (michael@panda.cs.mun.ca) diff --git a/bin/ksh/NEWS b/bin/ksh/NEWS index ca5e579a118..be0253f5f2c 100644 --- a/bin/ksh/NEWS +++ b/bin/ksh/NEWS @@ -1,6 +1,11 @@ Version 5.2.14pre * bug fixes + * eval: if given empty command, exist status is that of last command + substitution (if any). + * trap: if first argument is "exit", it is taken as a command not a signal. + * pwd: config test & code to work around bug in hpux 10.x getcwd(). + * RANDOM: seed based on both time and pid; different sequence in sub shells. * typeset -f: now pretty-prints $(..) and $((..)) correctly. * fixed bug in memory allocation which can lead to core dumps. * set -o: no longer prints options that have no names. @@ -10,6 +15,7 @@ Version 5.2.14pre * variable substitution: ${#array[*]} now prints number of set elements in the array (used to print largest index, not what ksh88 did). * job control: resuming suspended gnu su no longer hoses su'd shell. + * job control: fixed possible core dump when waiting for jobs. Version 5.2.13 @@ -38,7 +44,7 @@ Version 5.2.13 * editing: completion after "cmd " now completes files (was command). -$OpenBSD: NEWS,v 1.7 1998/10/29 04:09:19 millert Exp $ +$OpenBSD: NEWS,v 1.8 1999/01/08 20:24:56 millert Exp $ Version 5.2.12 diff --git a/bin/ksh/NOTES b/bin/ksh/NOTES index 906129eef42..fa009dcadd6 100644 --- a/bin/ksh/NOTES +++ b/bin/ksh/NOTES @@ -1,4 +1,4 @@ -$OpenBSD: NOTES,v 1.5 1998/10/29 04:09:19 millert Exp $ +$OpenBSD: NOTES,v 1.6 1999/01/08 20:24:57 millert Exp $ General features of at&t ksh88 that are not (yet) in pdksh: - exported aliases and functions (not in ksh93). @@ -36,6 +36,13 @@ Known bugs (see also BUG-REPORTS and PROJECTS files): in pdksh (ie, the read is done in a separate process in pdksh). Misc: +Known problems not caused by ksh: + - after stoping a job, emacs/vi is not re-entered. Hitting return + prints the prompt and everything is fine again. Problem (often + involving a pager like less) is related to order of process + scheduling (shell runs before `stop'ed (sub) processes have had a chance + to clean up the screen/terminal). + Known differences between pdksh & at&t ksh (that may change) - vi: - `^U': at&t: kills only what has been inserted, pdksh: kills to @@ -191,6 +198,13 @@ Known differences between pdksh & at&t ksh (that are not likely to change) at&t ksh (and sh) don't. Eg., pdksh likes while false ; do done but ksh88 doesn't like it. + - pdksh bumps RANDOM in parent after a fork, at&t ksh bumps it in both + parent and child: + RANDOM=1 + echo child: `echo $RANDOM` + echo parent: $RANDOM + will produce "child: 16838 parent: 5758" in pdksh, while at&t ksh + will produce "child: 5758 parent: 5758". Oddities in ksh (pd & at&t): - array references inside (())/$(()) are strange: diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c index b0d10945dbf..36057aed1fd 100644 --- a/bin/ksh/c_ksh.c +++ b/bin/ksh/c_ksh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_ksh.c,v 1.9 1998/10/29 04:09:19 millert Exp $ */ +/* $OpenBSD: c_ksh.c,v 1.10 1999/01/08 20:24:57 millert Exp $ */ /* * built-in Korn commands: c_* @@ -1177,7 +1177,7 @@ c_kill(wp) /* assume old style options if -digits or -UPPERCASE */ if ((p = wp[1]) && *p == '-' && (digit(p[1]) || isupper(p[1]))) { - if (!(t = gettrap(p + 1))) { + if (!(t = gettrap(p + 1, TRUE))) { bi_errorf("bad signal `%s'", p + 1); return 1; } @@ -1191,7 +1191,7 @@ c_kill(wp) lflag = 1; break; case 's': - if (!(t = gettrap(builtin_opt.optarg))) { + if (!(t = gettrap(builtin_opt.optarg, TRUE))) { bi_errorf("bad signal `%s'", builtin_opt.optarg); return 1; diff --git a/bin/ksh/c_sh.c b/bin/ksh/c_sh.c index 5db3d587240..bde71828b35 100644 --- a/bin/ksh/c_sh.c +++ b/bin/ksh/c_sh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_sh.c,v 1.8 1998/10/29 04:09:20 millert Exp $ */ +/* $OpenBSD: c_sh.c,v 1.9 1999/01/08 20:24:57 millert Exp $ */ /* * built-in Bourne commands @@ -433,6 +433,15 @@ c_eval(wp) */ s = pushs(SWORDS, ATEMP); s->u.strv = wp + builtin_opt.optind; + /* + * Handle case where command is empty due to failed + * command substitution, eg, eval "$(false)". + * In this case, shell() will not set/change exstat (cause + * compiled tree is empty), so will use this value. subst_exstat + * is cleared in execute(), so should be 0 if there were no + * substitutions. + */ + exstat = subst_exstat; return shell(s, FALSE); } @@ -475,13 +484,18 @@ c_trap(wp) return 0; } - s = (gettrap(*wp) == NULL) ? *wp++ : NULL; /* get command */ + /* + * Use case sensitive lookup for first arg so the + * command 'exit' isn't confused with the pseudo-signal + * 'EXIT'. + */ + s = (gettrap(*wp, FALSE) == NULL) ? *wp++ : NULL; /* get command */ if (s != NULL && s[0] == '-' && s[1] == '\0') s = NULL; /* set/clear traps */ while (*wp != NULL) { - p = gettrap(*wp++); + p = gettrap(*wp++, TRUE); if (p == NULL) { bi_errorf("bad signal %s", wp[-1]); return 1; @@ -496,16 +510,18 @@ c_exitreturn(wp) char **wp; { int how = LEXIT; + int n; char *arg; if (ksh_getopt(wp, &builtin_opt, null) == '?') return 1; arg = wp[builtin_opt.optind]; - if (arg != NULL && !getn(arg, &exstat)) { + if (arg != NULL && !getn(arg, &n)) { exstat = 1; warningf(TRUE, "%s: bad number", arg); - } + } else + exstat = n; if (wp[0][0] == 'r') { /* return */ struct env *ep; diff --git a/bin/ksh/c_ulimit.c b/bin/ksh/c_ulimit.c index 0faf8fbfa66..8ac133a81b8 100644 --- a/bin/ksh/c_ulimit.c +++ b/bin/ksh/c_ulimit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_ulimit.c,v 1.6 1998/11/24 04:32:47 millert Exp $ */ +/* $OpenBSD: c_ulimit.c,v 1.7 1999/01/08 20:24:57 millert Exp $ */ /* ulimit -- handle "ulimit" builtin @@ -231,7 +231,7 @@ c_ulimit(wp) bi_errorf("exceeds allowable limit"); else bi_errorf("bad limit: %s", - strerror(errno)); + strerror(errno)); return 1; } } else { diff --git a/bin/ksh/config.h b/bin/ksh/config.h index 4c08c1194a8..218f526aaae 100644 --- a/bin/ksh/config.h +++ b/bin/ksh/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.3 1998/06/25 19:01:49 millert Exp $ */ +/* $OpenBSD: config.h,v 1.4 1999/01/08 20:24:58 millert Exp $ */ /* config.h. Generated automatically by configure. */ /* config.h.in. Generated automatically from configure.in by autoheader. */ @@ -195,6 +195,10 @@ /* Default PATH (see comments in configure.in for more details) */ #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb" +/* Define if your C library's getwd/getcwd function dumps core in unreadable + * directories. */ +/* #undef HPUX_GETWD_BUG */ + /* Include ksh features? (see comments in configure.in for more details) */ /* #define KSH 1 */ @@ -247,6 +251,9 @@ /* Define if you have the flock function. */ #define HAVE_FLOCK 1 +/* Define if you have the getcwd function. */ +#define HAVE_GETCWD 1 + /* Define if you have the getgroups function. */ /* #undef HAVE_GETGROUPS */ diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c index c0d3af2a38e..5112e077bd6 100644 --- a/bin/ksh/edit.c +++ b/bin/ksh/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.7 1998/06/25 19:01:50 millert Exp $ */ +/* $OpenBSD: edit.c,v 1.8 1999/01/08 20:24:58 millert Exp $ */ /* * Command line editing - common code @@ -292,9 +292,10 @@ x_mode(onoff) x_emacs_keys(&edchars); #endif } - } else + } else { /* TF_WAIT doesn't seem to be necessary when leaving xmode */ set_tty(tty_fd, &tty_state, TF_NONE); + } return prev; } diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c index 8508300fc09..56917f378b6 100644 --- a/bin/ksh/eval.c +++ b/bin/ksh/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.6 1998/10/29 04:09:20 millert Exp $ */ +/* $OpenBSD: eval.c,v 1.7 1999/01/08 20:24:58 millert Exp $ */ /* * Expansion - quoting, separation, substitution, globbing @@ -719,7 +719,7 @@ varsub(xp, sp, word, stypep, slenp) if (vp->flag & (ISSET|ARRAY)) zero_ok = 1; for (; vp; vp = vp->u.array) - if (vp->flag * ISSET) { + if (vp->flag & ISSET) { max = vp->index + 1; n++; } diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c index c7d410cd3fd..bf0f3975dd8 100644 --- a/bin/ksh/exec.c +++ b/bin/ksh/exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.c,v 1.13 1998/10/29 04:09:20 millert Exp $ */ +/* $OpenBSD: exec.c,v 1.14 1999/01/08 20:24:59 millert Exp $ */ /* * execute command tree @@ -104,7 +104,7 @@ execute(t, flags) if (t->type == TCOM) { /* Clear subst_exstat before argument expansion. Used by - * null commands (see comexec()) and by c_set(). + * null commands (see comexec() and c_eval()) and by c_set(). */ subst_exstat = 0; diff --git a/bin/ksh/io.c b/bin/ksh/io.c index e52ade63626..93c6b1f97af 100644 --- a/bin/ksh/io.c +++ b/bin/ksh/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.5 1998/06/25 19:02:00 millert Exp $ */ +/* $OpenBSD: io.c,v 1.6 1999/01/08 20:24:59 millert Exp $ */ /* * shell buffered IO and formatted output @@ -179,6 +179,69 @@ shprintf(fmt, va_alist) va_end(va); } +#ifdef KSH_DEBUG +static struct shf *kshdebug_shf; + +void +kshdebug_init_() +{ + if (kshdebug_shf) + shf_close(kshdebug_shf); + kshdebug_shf = shf_open("/tmp/ksh-debug.log", + O_WRONLY|O_APPEND|O_CREAT, 0600, + SHF_WR|SHF_MAPHI); + if (kshdebug_shf) { + shf_fprintf(kshdebug_shf, "\nNew shell[pid %d]\n", getpid()); + shf_flush(kshdebug_shf); + } +} + +/* print to debugging log */ +void +# ifdef HAVE_PROTOTYPES +kshdebug_printf_(const char *fmt, ...) +# else +kshdebug_printf_(fmt, va_alist) + const char *fmt; + va_dcl +# endif +{ + va_list va; + + if (!kshdebug_shf) + return; + SH_VA_START(va, fmt); + shf_fprintf(kshdebug_shf, "[%d] ", getpid()); + shf_vfprintf(kshdebug_shf, fmt, va); + va_end(va); + shf_flush(kshdebug_shf); +} + +void +kshdebug_dump_(str, mem, nbytes) + const char *str; + const void *mem; + int nbytes; +{ + int i, j; + int nprow = 16; + + if (!kshdebug_shf) + return; + shf_fprintf(kshdebug_shf, "[%d] %s:\n", getpid(), str); + for (i = 0; i < nbytes; i += nprow) { + char c = '\t'; + for (j = 0; j < nprow && i + j < nbytes; j++) { + shf_fprintf(kshdebug_shf, "%c%02x", + c, ((const unsigned char *) mem)[i + j]); + c = ' '; + } + shf_fprintf(kshdebug_shf, "\n"); + } + shf_flush(kshdebug_shf); +} +#endif /* KSH_DEBUG */ + /* test if we can seek backwards fd (returns 0 or SHF_UNBUF) */ int can_seek(fd) @@ -199,6 +262,7 @@ initio() shf_fdopen(2, SHF_WR, shl_out); shf_fdopen(2, SHF_WR, shl_spare); /* force buffer allocation */ initio_done = 1; + kshdebug_init(); } /* A dup2() with error checking */ diff --git a/bin/ksh/jobs.c b/bin/ksh/jobs.c index 800d0c00293..31397fed61a 100644 --- a/bin/ksh/jobs.c +++ b/bin/ksh/jobs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: jobs.c,v 1.10 1998/11/19 19:59:09 millert Exp $ */ +/* $OpenBSD: jobs.c,v 1.11 1999/01/08 20:24:59 millert Exp $ */ /* * Process and job control @@ -643,6 +643,8 @@ exchild(t, flags, close_fd) } /* shell (parent) stuff */ + /* Ensure next child gets a (slightly) different $RANDOM sequence */ + change_random(); if (!(flags & XPIPEO)) { /* last process in a job */ #ifdef TTY_PGRP /* YYY: Is this needed? (see also YYY above) @@ -899,8 +901,9 @@ j_resume(cp, bg) } /* See comment in j_waitj regarding saved_ttypgrp. */ if (ttypgrp_ok && tcsetpgrp(tty_fd, (j->flags & JF_SAVEDTTYPGRP) ? j->saved_ttypgrp : j->pgrp) < 0) { - if (j->flags & JF_SAVEDTTY) + if (j->flags & JF_SAVEDTTY) { set_tty(tty_fd, &tty_state, TF_NONE); + } sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0); bi_errorf("1st tcsetpgrp(%d, %d) failed: %s", @@ -921,8 +924,9 @@ j_resume(cp, bg) if (!bg) { j->flags &= ~JF_FG; # ifdef TTY_PGRP - if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) + if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) { set_tty(tty_fd, &tty_state, TF_NONE); + } if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) { warningf(TRUE, "fg: 2nd tcsetpgrp(%d, %d) failed: %s", diff --git a/bin/ksh/main.c b/bin/ksh/main.c index 42f5c3c6e84..3fc6446d80f 100644 --- a/bin/ksh/main.c +++ b/bin/ksh/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.11 1998/10/29 04:09:21 millert Exp $ */ +/* $OpenBSD: main.c,v 1.12 1999/01/08 20:25:00 millert Exp $ */ /* * startup, main loop, enviroments and error handling @@ -37,10 +37,22 @@ static const char version_param[] = #endif /* KSH */ ; +/* +MAILCHECK: + typeset -i MAILCHECK + : "${MAILCHECK=600}" +SECONDS: + typeset -i SECONDS + initialize seconds to $SECONDS +TMOUT: + typeset -i + do setspec +*/ + static const char *const initcoms [] = { "typeset", "-x", "SHELL", "PATH", "HOME", NULL, "typeset", "-r", version_param, NULL, - "typeset", "-ri", "PPID", NULL, + "typeset", "-i", "PPID", NULL, "typeset", "-i", "OPTIND=1", #ifdef KSH "MAILCHECK=600", "RANDOM", "SECONDS=0", "TMOUT=0", @@ -94,6 +106,7 @@ main(argc, argv) int restricted, errexit; char **wp; struct env env; + pid_t ppid; #ifdef MEM_DEBUG chmem_set_defaults("ct", 1); @@ -241,9 +254,10 @@ main(argc, argv) if (current_wd[0] || pwd != null) setstr(pwd_v, current_wd); } - setint(global("PPID"), (long) getppid()); + ppid = getppid(); + setint(global("PPID"), (long) ppid); #ifdef KSH - setint(global("RANDOM"), (long) time((time_t *)0)); + setint(global("RANDOM"), (long) (time((time_t *)0) * kshpid * ppid)); #endif /* KSH */ setstr(global(version_param), ksh_version); @@ -596,8 +610,6 @@ shell(s, toplevel) t = compile(s); if (t != NULL && t->type == TEOF) { if (wastty && Flag(FIGNOREEOF) && --attempts > 0) { - shellf("pgrp=%d, ttypgrp=%d\n", - getpgrp(), tcgetpgrp(0)); shellf("Use `exit' to leave ksh\n"); s->type = SSTDIN; } else if (wastty && !really_exit diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c index daf44c8279e..00b13c3ffd6 100644 --- a/bin/ksh/misc.c +++ b/bin/ksh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.8 1998/10/29 04:09:21 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.9 1999/01/08 20:25:01 millert Exp $ */ /* * Miscellaneous functions @@ -1265,17 +1265,63 @@ reset_nonblock(fd) # define MAXPATHLEN PATH #endif /* MAXPATHLEN */ +#ifdef HPUX_GETWD_BUG +# include "ksh_dir.h" + +/* + * Work around bug in hpux 10.x C library - getwd/getcwd dump core + * if current directory is not readable. Done in macro 'cause code + * is needed in GETWD and GETCWD cases. + */ +# define HPUX_GETWD_BUG_CODE \ + { \ + DIR *d = ksh_opendir("."); \ + if (!d) \ + return (char *) 0; \ + closedir(d); \ + } +#else /* HPUX_GETWD_BUG */ +# define HPUX_GETWD_BUG_CODE +#endif /* HPUX_GETWD_BUG */ + /* Like getcwd(), except bsize is ignored if buf is 0 (MAXPATHLEN is used) */ char * ksh_get_wd(buf, bsize) char *buf; int bsize; { -#ifdef HAVE_GETWD +#ifdef HAVE_GETCWD + char *b; + char *ret; + + /* Before memory allocated */ + HPUX_GETWD_BUG_CODE + + /* Assume getcwd() available */ + if (!buf) { + bsize = MAXPATHLEN; + b = alloc(MAXPATHLEN + 1, ATEMP); + } else + b = buf; + + ret = getcwd(b, bsize); + + if (!buf) { + if (ret) + ret = aresize(b, strlen(b) + 1, ATEMP); + else + afree(b, ATEMP); + } + + return ret; +#else /* HAVE_GETCWD */ extern char *getwd ARGS((char *)); char *b; int len; + /* Before memory allocated */ + HPUX_GETWD_BUG_CODE + if (buf && bsize > MAXPATHLEN) b = buf; else @@ -1300,26 +1346,5 @@ ksh_get_wd(buf, bsize) } return b; -#else /* HAVE_GETWD */ - char *b; - char *ret; - - /* Assume getcwd() available */ - if (!buf) { - bsize = MAXPATHLEN; - b = alloc(MAXPATHLEN + 1, ATEMP); - } else - b = buf; - - ret = getcwd(b, bsize); - - if (!buf) { - if (ret) - ret = aresize(b, strlen(b) + 1, ATEMP); - else - afree(b, ATEMP); - } - - return ret; -#endif /* HAVE_GETWD */ +#endif /* HAVE_GETCWD */ } diff --git a/bin/ksh/proto.h b/bin/ksh/proto.h index 1df62843b7f..42f2b72990e 100644 --- a/bin/ksh/proto.h +++ b/bin/ksh/proto.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.h,v 1.5 1998/10/29 04:09:21 millert Exp $ */ +/* $OpenBSD: proto.h,v 1.6 1999/01/08 20:25:01 millert Exp $ */ /* * prototypes for PD-KSH @@ -112,6 +112,12 @@ void shellf ARGS((const char *fmt, ...)) GCC_FUNC_ATTR(format(printf, 1, 2)); void shprintf ARGS((const char *fmt, ...)) GCC_FUNC_ATTR(format(printf, 1, 2)); +#ifdef KSH_DEBUG +void kshdebug_init_ ARGS((void)); +void kshdebug_printf_ ARGS((const char *fmt, ...)) + GCC_FUNC_ATTR(format(printf, 1, 2)); +void kshdebug_dump_ ARGS((const char *str, const void *mem, int nbytes)); +#endif /* KSH_DEBUG */ int can_seek ARGS((int fd)); void initio ARGS((void)); int ksh_dup2 ARGS((int ofd, int nfd, int errok)); @@ -222,7 +228,7 @@ void inittraps ARGS((void)); #ifdef KSH void alarm_init ARGS((void)); #endif /* KSH */ -Trap * gettrap ARGS((const char *name)); +Trap * gettrap ARGS((const char *name, int igncase)); RETSIGTYPE trapsig ARGS((int i)); void intrcheck ARGS((void)); int fatal_trap_check ARGS((void)); @@ -263,6 +269,7 @@ char *skip_wdvarname ARGS((const char *s, int aok)); int is_wdvarname ARGS((const char *s, int aok)); int is_wdvarassign ARGS((const char *s)); char ** makenv ARGS((void)); +void change_random ARGS((void)); int array_ref_len ARGS((const char *cp)); char * arrayname ARGS((const char *str)); void set_array ARGS((const char *var, int reset, char **vals)); diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h index 89955883d66..2a92122f8a2 100644 --- a/bin/ksh/sh.h +++ b/bin/ksh/sh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sh.h,v 1.6 1998/06/25 19:02:19 millert Exp $ */ +/* $OpenBSD: sh.h,v 1.7 1999/01/08 20:25:02 millert Exp $ */ /* * Public Domain Bourne/Korn shell @@ -379,6 +379,16 @@ EXTERN Area aperm; /* permanent object space */ # include "chmem.h" /* a debugging front end for malloc et. al. */ #endif /* MEM_DEBUG */ +#ifdef KSH_DEBUG +# define kshdebug_init() kshdebug_init_() +# define kshdebug_printf(a) kshdebug_printf_ a +# define kshdebug_dump(a) kshdebug_dump_ a +#else /* KSH_DEBUG */ +# define kshdebug_init() +# define kshdebug_printf(a) +# define kshdebug_dump(a) +#endif /* KSH_DEBUG */ + /* * parsing & execution environment diff --git a/bin/ksh/shf.h b/bin/ksh/shf.h index 2069d3248b8..b4be5a73d67 100644 --- a/bin/ksh/shf.h +++ b/bin/ksh/shf.h @@ -1,4 +1,7 @@ -/* $OpenBSD: shf.h,v 1.1 1996/08/14 06:19:11 downsj Exp $ */ +/* $OpenBSD: shf.h,v 1.2 1999/01/08 20:25:02 millert Exp $ */ + +#ifndef SHF_H +# define SHF_H /* * Shell file I/O routines @@ -79,3 +82,5 @@ int shf_fprintf ARGS((struct shf *shf, const char *fmt, ...)); int shf_snprintf ARGS((char *buf, int bsize, const char *fmt, ...)); char *shf_smprintf ARGS((const char *fmt, ...)); int shf_vfprintf ARGS((struct shf *, const char *fmt, va_list args)); + +#endif /* SHF_H */ diff --git a/bin/ksh/tests/regress.t b/bin/ksh/tests/regress.t index cf99d21aaeb..763891f839c 100644 --- a/bin/ksh/tests/regress.t +++ b/bin/ksh/tests/regress.t @@ -962,3 +962,77 @@ expected-stdout: --- +name: regression-56 +description: + Check eval vs substitution exit codes + (this is what ksh88 does) +stdin: + eval $(false) + echo A $? + eval ' $(false)' + echo B $? + eval " $(false)" + echo C $? + eval "eval $(false)" + echo D $? + eval 'eval '"$(false)" + echo E $? + IFS="$IFS:" + eval $(echo :; false) + echo F $? +expected-stdout: + A 1 + B 1 + C 1 + D 0 + E 0 + F 1 +--- + +name: regression-57 +description: + Check if typeset output is correct for + uninitialized array elements. +stdin: + typeset -i xxx[4] + echo A + typeset -i | grep xxx | sed 's/^/ /' + echo B + typeset | grep xxx | sed 's/^/ /' + + xxx[1]=2+5 + echo M + typeset -i | grep xxx | sed 's/^/ /' + echo N + typeset | grep xxx | sed 's/^/ /' +expected-stdout: + A + xxx + B + typeset -i xxx + M + xxx[1]=7 + N + typeset -i xxx +--- + +name: regression-58 +description: + Check if trap exit is ok (exit not mistaken for signal name) +stdin: + trap 'echo hi' exit + trap exit 1 +expected-stdout: + hi +--- + +name: regression-59 +description: + Check if ${#array[*]} is calculated correctly. +stdin: + a[12]=hi + a[8]=there + echo ${#a[*]} +expected-stdout: + 2 +--- diff --git a/bin/ksh/tests/version.t b/bin/ksh/tests/version.t index 048544b88d4..f3dabcb445a 100644 --- a/bin/ksh/tests/version.t +++ b/bin/ksh/tests/version.t @@ -4,5 +4,5 @@ description: stdin: echo $KSH_VERSION expected-stdout: - @(#)PD KSH v5.2.13 97/10/27 + @(#)PD KSH v5.2.13.5 98/12/18 --- diff --git a/bin/ksh/trap.c b/bin/ksh/trap.c index c2118b541e7..df6d9b63dd8 100644 --- a/bin/ksh/trap.c +++ b/bin/ksh/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.8 1998/12/21 05:53:27 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.9 1999/01/08 20:25:02 millert Exp $ */ /* * signal handling @@ -84,8 +84,9 @@ alarm_catcher(sig) #endif /* KSH */ Trap * -gettrap(name) +gettrap(name, igncase) const char *name; + int igncase; { int i; register Trap *p; @@ -98,10 +99,20 @@ gettrap(name) return NULL; } for (p = sigtraps, i = SIGNALS+1; --i >= 0; p++) - if (p->name && (strcasecmp(p->name, name) == 0 || - (strlen(name) > 3 && !strncasecmp("SIG", p->name, 3) && - !strcasecmp(p->name, name + 3)))) - return p; + if (p->name) { + if (igncase) { + if (p->name && (!strcasecmp(p->name, name) || + (strlen(name) > 3 && !strncasecmp("SIG", + p->name, 3) && + !strcasecmp(p->name, name + 3)))) + return p; + } else { + if (p->name && (!strcmp(p->name, name) || + (strlen(name) > 3 && !strncmp("SIG", + p->name, 3) && !strcmp(p->name, name + 3)))) + return p; + } + } return NULL; } diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 5f6ec98832a..c985a1144e8 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.7 1998/06/25 19:02:27 millert Exp $ */ +/* $OpenBSD: var.c,v 1.8 1999/01/08 20:25:02 millert Exp $ */ #include "sh.h" #include "ksh_time.h" @@ -843,6 +843,17 @@ makenv() return (char **) XPclose(env); } +/* + * Called after a fork in parent to bump the random number generator. + * Done to ensure children will not get the same random number sequence + * if the parent doesn't use $RANDOM. + */ +void +change_random() +{ + rand(); +} + /* * handle special variables with side effects - PATH, SECONDS. */ diff --git a/bin/ksh/version.c b/bin/ksh/version.c index e0595b5bf29..ef44a10ce87 100644 --- a/bin/ksh/version.c +++ b/bin/ksh/version.c @@ -1,4 +1,4 @@ -/* $OpenBSD: version.c,v 1.7 1998/10/29 04:09:21 millert Exp $ */ +/* $OpenBSD: version.c,v 1.8 1999/01/08 20:25:03 millert Exp $ */ /* * value of $KSH_VERSION (or $SH_VERSION) @@ -7,4 +7,4 @@ #include "sh.h" const char ksh_version [] = - "@(#)PD KSH v5.2.13.4 98/10/28"; + "@(#)PD KSH v5.2.13.5 98/12/18"; diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index 81950b224a3..0dfef7ea4f4 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.5 1997/06/19 13:58:49 kstailey Exp $ */ +/* $OpenBSD: vi.c,v 1.6 1999/01/08 20:25:03 millert Exp $ */ /* * vi command editing @@ -208,8 +208,9 @@ x_vi(buf, len) vi_macro_reset(); c = x_getc(); } - } else + } else { c = x_getc(); + } if (c == -1) break; if (state != VLIT) { -- cgit v1.2.3