Commit Graph

408 Commits

Author SHA1 Message Date
tg ead77623d3 Fix most “set -x” problems (LP#1179287)
• “set -x” manually (cmdline too) snapshots fd#2 now
• “set -o inherit-xtrace” introduced; default still enabled
• reverted iodup printing to pre-R45 behaviour
• made Flag(FXTRACE) a proper state machine
2013-07-21 18:47:24 +00:00
tg bd795a83ae partial merge and full RCS ID sync with oksh
merged:
• new regression tests
• check.pl (tests/th) better tmpfile handling
• exec.c 1.50: POSIX specifies that for an AND/OR list,
  only the last command's exit status matters for "set -e"
• ksh.1 1.147: document the above
• eval.c 1.39: “Make $(< /nonexistent) have the same behaviour
  as $(cat /nonexistent) wrt. errors (do not unwind and do not
  treat this as fatal if set -e is used).”
  ‣ additionally make shf_open() return errno and actually show
    the error message from the system
• regression-39 test: remove the “maybe” marker
  ‣ but decide on correct POSIX behaviour

already been fixed in mksh:
• check.pl (tests/th) exit 1 if tests fail

not merged:
• main.c 1.52: run traps in unwind() before exiting;
  I’m pretty sure this is already working as-should in mksh
• eval.c 1.38: “Commands executed via `foo` or $( bar ) should
  not inherit "set -e" status.” As discussed in IRC, this is
  just plainly WRONG.
2013-07-21 18:36:03 +00:00
tg 8e6b0f712a support n̲o̲t̲ fork(2)ing for -T (by prepending the tty with ‘!’); especially useful on Linux since our own setsid(2) is more annoying; gets rid of the need for oneit_lite and similar hacks; WARNING: also removes chown/chmod on the tty! 2013-06-03 22:28:06 +00:00
tg 8256f266ff fix a number of warnings and other issues:
• sig_t detection was a bit insane, it is a function-pointer type after all
• fix uninitialised variable in c_select which led to mistakenly accepting
  invalid (nōn-numeric) input and acting, randomly, upon it
• keep SIGCHLD blocked in child after forking longer, for job list manip
• block SIGCHLD ifdef DEBUG_LEAKS to not run job foo during/after afreeall
• fix annoying ISO C90 vs. C99 (un)signed constant warning
2013-06-02 03:09:17 +00:00
tg f0f34eb7b6 • Allow setting both -o posix and -o sh (although only in the same
command; setting one still unsets the other at first)
• Change subst_exstat to be conformant unless -o sh is set and -o posix isn’t
• In lksh, make subst_exstat (newly) conformant if -o posix
• New MKSH_BINSHPOSIX to accompany MKSH_BINSHREDUCED
• Sync lksh manpage precisely
2013-05-02 20:21:45 +00:00
tg 0fb44301ef can test wraparound not in lksh 2013-04-27 18:56:41 +00:00
tg deb4a3bf20 Oh well… this looks well, is done done, and gcc-snapshot doesn’t complain:
• correct order of built-in commands; use POSIX special versus “all others”
  plus “keeps assignments” as distinction, no longer play POSIX regular vs.
  others game; sync manpage
• fix LP#1156707: map (( internally to “let]” which is no valid function
  name and so can’t be overridden but is unlikely to be used otherwhere
  and not strictly permitted (by POSIX) anyway
• we do not need -Wno-overflow any more, either
• bump to R45
2013-04-26 21:22:50 +00:00
tg 41ae60bb55 now that funsub() is a separate function, and we don’t have the clobber
issue from longjmp any more, and that I thought to rewind the fd, finally
implement ${ …;} on deleted-after-open tempfiles without the need to reopen
2013-03-29 17:33:07 +00:00
tg 1df0cb4093 as a more general solution to fd leak detection, just do CLOEXEC manually
(this also allows us to see “real” leaks)
2013-02-10 21:42:16 +00:00
tg f209a252bc when leak debugging, free everything even in builtins 2013-02-10 21:17:07 +00:00
tg 2b06709bf3 improve DEBUG_LEAKS handling and fix freeing some locs 2013-02-10 19:05:37 +00:00
tg 43a41932e7 make DEBUG_LEAKS safely free all resources before the main shell exits 2013-02-10 18:17:30 +00:00
tg ce1ab97541 for DEBUG_LEAKS, prevent “leaking” of fds, even if they’re close-on-exit 2013-02-10 17:55:57 +00:00
tg 5741127ab7 experimentally enable afreeall(APERM) too, LP#1106116 2013-02-10 17:43:07 +00:00
tg 59009ac78f call it DEBUG_LEAKS so Android can always enable it 2013-02-10 17:41:06 +00:00
tg cb93db360d call afreeall(AEDIT) upon close; related to LP#1106116 2013-02-10 17:38:15 +00:00
tg 7a2130b02a do not, ever, even in local-only debugging examples, create anything
in /tmp without the use of mkstemp(3) or similar!
2013-01-06 18:44:07 +00:00
tg d5ba31fd86 fix the set +e cases, too 2013-01-01 22:23:16 +00:00
tg 744f77c668 fix running the ERR and EXIT traps in case of set -e and/or eval (includes Debian #696823) 2013-01-01 20:45:04 +00:00
tg 12c662b6e2 thanks to ISC (Interactive) Unix, we now know a few samples of errnos
that get used, plus one for the realpath-1 regression test; also make
sys_siglist_decl detection nicer and poison strerror() with non-const
return value ifdef DEBUG, make it always const
2012-12-17 23:18:11 +00:00
tg c4e88acd83 Correct mistake when doing hashtable lookup collision resolution… oops 2012-12-07 23:46:38 +00:00
tg f654a3dea4 fix libFirm/cparser -Wsign-compare 2012-12-05 19:38:25 +00:00
tg 0f3071a8b2 MKSH_DISABLE_EXPERIMENTAL is a NOP again; use ${ precmd;} in dot.mkshrc 2012-11-30 20:19:16 +00:00
tg f63bcae02c … oh well, but MidnightBSD gcc picks on "" too, so just stick to NULL, it’s cheapest 2012-11-30 19:58:48 +00:00
tg 9a6ebef8ca The MidnightBSD/amd64 system compiler (Target: amd64-undermydesk-freebsd)
gcc version 4.2.1 20070719  [MidnightBSD] has stricter -Wformat checking
2012-11-30 19:51:25 +00:00
tg 77c4cb88e4 implement tty tracking and bump to R41 for feature completeness
• tty_fd is now never closed
• new tty_hasstate tracks tty_state (cf. thread around
  http://article.gmane.org/gmane.os.miros.mksh/79 and PLD bug)
• as users requested, importing COLUMNS or LINES from the environment
  now removes its special-ness as does unsetting it
• otherwise, setting COLUMNS or LINES is honoured until the next SIGWINCH
  arrives or change_winsz is otherwise run (e.g. before displaying the
  prompt in the interactive command line editing modes)
• SIGWINCH is now honoured before each reading of $COLUMNS and $LINES too
• change the Uhr to match – it no longer calls stty(1) ☺
2012-11-30 19:25:08 +00:00
tg 80e364b7ad use proper parenthesēs; int → bool; use same var (eno) for temp. errno 2012-11-30 19:02:10 +00:00
tg 007cf09db6 use EPOCHREALTIME as variable, somewhat compatible with “zmodload zsh/datetime”, as ormaaj belatedly found out 2012-11-26 22:49:51 +00:00
tg 13da062f92 add MKSH_UNIXTIME 2012-11-20 18:07:45 +00:00
tg 435bc124ef introduce $BASHPID for ormaaj from #ksh 2012-11-20 17:42:32 +00:00
tg 222d50f1af save some space for error-less error messages
inspired by a bugfix for posh for something that was not a bug in here
2012-11-12 18:28:40 +00:00
tg 5aa7842d33 who would’ve thought proper ^C handling be so hard? 2012-10-30 20:49:44 +00:00
tg 8caee45c60 int → bool 2012-10-30 20:13:20 +00:00
tg faa0a78df3 restore yyrecursive context in quitenv (LP#1069428) 2012-10-30 20:07:15 +00:00
tg fc27886680 when ^C’ing out of an interactive shell, also throw away the here documents (probably leaks, maybe not due to quitenv, but not much) 2012-10-30 20:07:00 +00:00
tg bfe7d78d40 bring back ${ foo;} sans dot.mkshrc patch, using a temporary file, and as experimental feature 2012-10-22 20:19:18 +00:00
tg 574c024635 introduce MKSH_DISABLE_EXPERIMENTAL and wrap the new feature introduced
in cid 1005084678C510CF7E4 in it
2012-10-22 16:53:22 +00:00
tg 31f24a4040 add some bounds, for a subsequent commit:
• all writers of exstat ensure the value is in [0; 0xFF]
• all readers of exstat AND it with 0xFF (not strictly needed thus)
• trap_exstat is “safe”, i.e. always either -1 or [0; 0xFF]
2012-10-21 21:39:06 +00:00
tg bebb2d2254 EXPERIMENTAL optimisation for “sh -c 'foo'” to equal “sh -c 'exit foo'” iff
several conditions are met as outlined below; for more background, refer to
http://www.FreeBSD.org/cgi/query-pr.cgi?pr=113860

We don’t yet optimise 「% sh -c '{ echo a; sleep 10;}&'; sleep 1; ps T」 so
the FreeBSD® sh approach cannot work for us, but scanning the “sh -c” argu‐
ment for disallowed characters and, if not, setting a flag that enables the
shell to exec the tree when parsed as TCOM *and not c_trap()* was possible.

Disallowed characters are currently C_QUOTE except space, that is:
Tab Newline " # $ & ' ( ) * ; < = > ? [ \ ] ` |

This should catch all cases of magic, variables, subshells, pipelines, etc.
2012-10-21 21:26:41 +00:00
tg 77f5b8f38d add split-screen debugging; close-on-exec the logfile 2012-10-21 17:16:45 +00:00
tg 9fbdef8e60 pure RCSID sync with OpenBSD, as we introduced SIGWINCH tracking earlier
XXX we could track whether tty_fd has already been successfully opened,
XXX the ttystate initialised, and then just never close it unless it is
XXX necessary, then we can keep COLUMNS/LINES accurate in scripts, even
2012-09-21 17:20:22 +00:00
tg eac85ffdf1 OpenBSD found out that "building argv for $* and $@" manipulates l->argv
in place which affects ps(1) output on BSD; create a new array and copy
the original parts from argv[] there without touching argv passed to main
2012-09-07 21:02:43 +00:00
tg aedb299057 note that some longjmp don’t handle 0 properly
cf. <500C1B2E.9030602@zytor.com>
2012-07-22 15:56:51 +00:00
tg 67714b270a dissolve the hashtab nonsense, ¾ is good, and mirkev will also use that 2012-07-01 15:38:09 +00:00
tg ea01d80833 hackish work-around the lexer to make alias definitions in mksh -c
work (Closes: #517009) and mention in the manpage why they sometimes
do not work (doing so for COMSUBs is not worth the effort)
2012-06-28 20:05:11 +00:00
tg b3b3aec17e CID 703478: probably can’t happen, but… 2012-06-24 20:15:47 +00:00
tg 29e36ed2a2 move x_mkraw() to main.c from edit.c in order to be able to skip the latter 2012-05-05 17:32:33 +00:00
tg 27387673a4 new MKSH_DISABLE_TTY_WARNING for ports that just can’t help it
TODO: add_cppflags this automatically in the TARGET_OS switch for some
2012-05-04 22:34:51 +00:00
tg e6ace01f12 last parts of Coherent patchkit: O_ACCMODE and termio 2012-05-04 22:18:27 +00:00
tg 7beac6668d provide for Coherent not having gettimeofday(2), imake style (bad, but this is not for others to use without a second thought anyway) 2012-05-04 21:47:04 +00:00
tg 2d31aca859 more int→bool while trying to let ^D output CR+LF (which shan’t be, oh my…) 2012-05-04 21:15:34 +00:00
tg 5780bc5eb7 new MKSH_NO_CMDLINE_EDITING to disable command line editing in its entirety
mainly for the Plan 9 port though it may also help the WinAPI variant,
other porting efforts, as well as a new project I cannot say yet
2012-05-04 20:49:08 +00:00
tg 5eea59ad57 rewrite maketemp() obsoleting tempnam(3) and mkstemp(3) external deps 2012-04-14 16:07:48 +00:00
tg 4a89ae1cd0 drop the need for strcasestr: just uppercase a copy and compare with uppercased 2012-04-06 12:59:28 +00:00
tg e67b98e21b use _setjmp/_longjmp on NeXTstep: its Intel port always restores the signal mask on siglongjmp, which we never have 2012-03-31 17:30:00 +00:00
tg b82db8764c only pull entropy from glibc pointer guard if glibc is actually there 2012-03-31 17:08:52 +00:00
tg 95a2c63096 • implement fcntl(2)-based advisory locking as an alternative iff flock(2)
is not found, from a suggestion by RT (LP: #912691)
• try harder (in a loop) to acquire a file lock if the locking mechanism
  documents EINTR is a possibility (fcntl always, flock on Linux not .Ox)
• use -std=c99 not -std=gnu99 if it must be at all
2012-03-27 22:36:53 +00:00
tg 87654270ab fix regression w.r.t. TTY and external programmes:
• release the TTY after the initial change_winsz()
• since we release it, we can skip initialising tty_state, too
2012-03-25 14:28:14 +00:00
tg 5dd5edea1a lewellyn found QNX also doesn’t have a struct timezone ⇒ just DROP it! 2012-03-24 22:11:41 +00:00
tg c6b498d4fe meh, hit a regression again 2012-03-23 22:36:23 +00:00
tg 24e8a6996b always keep x_cols and x_lins valid; check once at start including tty init
if we find any, but not later; do not check on every read

⇒ allows changing COLUMNS and LINES (independent of each other, or both)
  for script shells by passing them in an environment setting, even if
  we get a tty; interactive shells still check before each line is read…

reported by the PLD guys, thanks
2012-03-23 21:58:24 +00:00
tg c5cc22a13f efficient debug-to-file output (/tmp racy, but hey) 2012-03-23 19:38:12 +00:00
tg 4f043002be another int → bool 2012-03-23 18:58:15 +00:00
tg e141394a83 RCSID sync from oksh; reduce hash table #elements if !MKSH_SMALL to speed up 2012-03-03 21:30:59 +00:00
tg bc039caa9f no "struct timezone" on Minix3, despite its manpage 2012-03-03 21:13:50 +00:00
tg 68e73536a0 RCSID sync with OpenBSD 5.1 ksh (we did the same checks ages ago) 2012-02-11 22:45:04 +00:00
tg bee3bbaaf8 reduce stack usage a bit (several candidates for more, including $CC itself…) 2012-01-29 01:41:15 +00:00
tg c620f865c1 cid 1004E0F5C27271F5B00 broke integer-base handling of built-in parameters
mksh -c 'echo a=$RANDOM; RANDOM=0x12; echo b=$RANDOM' # behaviour changed
2011-11-08 22:07:15 +00:00
tg 9eaf6a8e12 remaining sync with oksh (pointless rcsid, no code diff) 2011-10-07 19:51:29 +00:00
tg 9782f6b4d1 • access(2) is broken in at least kFreeBSD 9.0 as “modern” OS, so bring
back the wrapper code as well as refactor most other code calling it
• apparently, names can’t end in ‘_’ or contain ‘__’ anywhere…
2011-09-07 15:24:22 +00:00
tg 577c918beb patch most of Jerker Bäck’s concerns out, unless not applicable 2011-08-27 18:06:52 +00:00
tg 5d9c88ceeb jg71 reported -DMKSH_ASSUME_UTF8=* breaks defining stristr 2011-08-27 17:30:07 +00:00
tg e03b485d75 ‣ merge from mksh R40-stable
move /etc/{,suid_}profile to /system/etc/ for Android (but do not make
the location of /etc configurable); rewrite manpage section about
/etc/{,suid_}profile, .profile, .mkshrc
2011-07-16 17:08:21 +00:00
tg 3ef67e3296 replace uses of OAAT hash in all its variants by NZAT (mksh internal) or NZAAT (all others) 2011-07-06 22:22:02 +00:00
tg 0739fa74a0 address "env RANDOM=1=2=3 mksh" DoS by integrifying more 2011-07-02 17:57:41 +00:00
tg e0fb8dc431 • rework hash table interna to avoid gcc-4.1 on Debian etch bug
• also improve behaviour with _a lot_ (>2²⁸) entries
• while here, improve comments and whitespace
2011-06-05 19:58:21 +00:00
tg ebb8bed911 fix segfault due to limit of hashtable entries (global variables) discovered by Jb_boin: unlimit to 2^30 minus epsilon 2011-06-04 16:42:31 +00:00
tg d1b8800ee8 • AIX: display OS version better (tested on 5.3 by cnuke@)
• IBM XL C: display version better (tested on V7.0 by cnuke@)
• do not 'IFS=: read nr name', Cygwin 1.7 dash fails it
• disable cd-pe, glob-range-3 on Cygwin (the former cannot
  succeed because the mv fails, the latter fails from 1.7 on)
• mark heredoc-tmpfile-8 as need-pass: no
• apply __attribute__ only to a function prototype, not to
  the body (even if static), since xlC fails that
• bump version to R40 (beta)
2011-05-29 16:31:42 +00:00
tg 61a8888213 always catch SIGALRM even in non-interactive shells to make sleep work 2011-04-17 12:24:44 +00:00
tg 6c45e3e764 avoid namespace conflicts with __attribute__(…) 2011-04-09 21:01:03 +00:00
tg e4e5229513 shut up valgrind, thanks wbx@ for prodding 2011-04-02 13:55:35 +00:00
tg e8ea9954aa • Implement http://austingroupbugs.net/view.php?id=367 and align things
a bit more with POSIX and the other shells

I considered http://austingroupbugs.net/view.php?id=253 but the use
of bi_errorf() is interesting, especially as it’s often enough a
noreturn function, and funnily enough, 'cd -P /foo' returns 0 while
'chdir -P /foo' fails (so idk where to put -e)…
2011-03-27 18:50:06 +00:00
tg 7d86eaba8c simplify code to use existing $PWD 2011-03-26 19:43:49 +00:00
tg e3ed074981 use existing code 2011-03-26 19:35:35 +00:00
tg 5239e8ea4c actually, we need the android lsmod to be a builtin not an alias… 2011-03-16 20:56:33 +00:00
tg 1c22b3cc48 oops 2011-03-16 20:43:34 +00:00
tg 79c6d6043e • introduce a virtual TARGET_OS=Android that just sets a check category
and switches to the TARGET_OS=Linux
• introduce android as regression test suite category
• add an android specific standard alias
• clean up redundant ‘-o sh’ arg in a few checks
2011-03-16 20:26:36 +00:00
tg af53a7d16a • speed optimisation: drop SF_FIRST flag, factor out skipping the
UTF-8 BOM instead (UTFMODE has a separate value now for activated
  during BOM skipping)
• parsing a COMSUB now skips UTF-8 BOM, too, but only temporarily
2011-03-13 16:03:54 +00:00
tg 2a3d4db123 lint is your friend 2011-03-13 01:20:25 +00:00
tg 0b6afea352 introduce macros for malloc, realloc, free to hide them from mksh
no code may henceforth use memory (de-)allocation functions directly
use these macros, porters can change them for abstraction
2011-03-05 21:43:18 +00:00
tg 6a941a3c39 fix UWIN: don’t close fd #3 (also, int→bool) 2011-02-27 19:29:32 +00:00
tg 0b57abd4d3 • add -u option (POSIX: unbuffered ⇒ nop) to the built-in cat
• PIPESTATUS now supported (like bash 2) whose last member
  may actually differ from $? since the latter may not be the
  result of a pipeline partial command
• add regression tests, documentation, etc.
2011-02-18 22:26:13 +00:00
tg a796512040 • more comment and int→bool cleanup, add and improve some comments
• in interactive mode, always look up {LC_{ALL,CTYPE},LANG} environment
  variables if setlocale/nl_langinfo(CODESET) doesn’t suffice
• add the ability to call any builtin (some don't make sense or wouldn't
  work) directly by analysing argv[0]
• for direct builtin calls, the {LC_{ALL,CTYPE},LANG} environment
  variables determine utf8-mode, even if MKSH_ASSUME_UTF8 was set
• when called as builtin, echo behaves POSIXish
• add domainname as alias for true on MirBSD only, to be able to link it
• sync mksh Makefiles with Build.sh output
• adjust manpage wrt release plans
• link some things to mksh now that we have callable builtins:
  bin/echo bin/kill bin/pwd bin/sleep (exact matches)
  bin/test bin/[ (were scripts before)
  bin/domainname=usr/bin/true usr/bin/false (move to /bin/ now)
• drop linked utilities and, except for echo and kill, their manpages
• adjust instbin and link a few more there as well
2011-02-11 01:18:23 +00:00
tg 865b267dbf drop suspend alias in Android too 2011-01-21 21:07:11 +00:00
tg cc31d86e3b • implement KSHEGID, KSHGID, KSHUID variables by suggestion of Richard K.
(KSHEUID aka USER_ID already exists)
• simplify, speed up LCG and $RANDOM handling again
2011-01-21 21:04:48 +00:00
tg 27dce9168a change behaviour of argument-less exit in traps to match SUSv4; Debian #599484 (original patch from Jonathan Nieder, thanks!) in a variant that appears to handle nested traps well 2010-11-01 17:29:05 +00:00
tg 667d792d6a • Address concerns of Chris Palmer from the Android security team
– possible integer overflows in memory allocation, mostly
    ‣ multiplication: all are checked now
    ‣ addition: reviewed them, most were “proven” or guessed to be
      “almost” impossible to run over (e.g. when we have a string
      whose length is taken it is assumed that the length will be
      more than only a few bytes below SIZE_MAX, since code and
      stack have to fit); some are checked now (e.g. when one of
      the summands is an off_t); most of the unchecked ones are
      annotated now
    ⇒ cost (MirBSD/i386 static): +76 .text
    ⇒ cost (Debian sid/i386): +779 .text  -4 .data
  – on Linux targets, setuid() setresuid() setresgid() can fail
    with EAGAIN; check for that and, if so, warn once and retry
    infinitely (other targets to be added later once we know that
    they are “insane”)
    ⇒ cost (Debian sid/i386): +192 .text (includes .rodata)
• setmode.c: Do overflow checking for realloc() too; switch back
  from calloc() to a checked malloc() for simplification while there
• define -DIN_MKSH and let setmode.c look a tad nicer while here
2010-09-14 21:26:19 +00:00
tg dcbfc48855 ┌──┤ apply Android patch from Jeff Hamilton:
│Don't alias 'stop' to 'kill -STOP'
│
│Android has already has a stop command used
│to stop the main runtime and the alias
│interferes with testing tools that expect
│stop to kill the runtime.
│
│Change-Id: I02b7efb9203dc39e97f63eb702a54ff79935b316

Although, this is closer to his first patchset and only takes
care of the alias, not the testsuite (which doesn’t run, at
least not out-of-the-box, nicely anyway) using #ifdef ANDROID.

We certainly want a more flexible testsuite…
2010-09-14 21:00:13 +00:00
tg 06c6be0a70 shave off another 468 bytes: we’re 300 bytes smaller than BEFORE the
cat builtin was added now… (also removed utf-8 from source files, in
favour of just ASCII)
2010-08-28 20:22:24 +00:00
tg 3747722db4 improve string pooling: saves 316 bytes in .text 2010-08-28 18:50:58 +00:00
tg 475cafb90e int → bool 2010-08-28 15:39:20 +00:00
tg 30046ffcf2 implement “live” SIGWINCH handling in the Emacs editing mode
for winstonw from IRC #!/bin/mksh
2010-07-04 17:45:17 +00:00
tg 4cbb5a9d46 to speed up mksh, get rid of arc4random(3) uses and use the LCG always;
depend on ASLR for seeding
2010-07-04 17:33:58 +00:00
tg 747b27a846 apply diff from manuel giraud via oksh to keep track of LINENO in a trap 2010-05-22 12:49:16 +00:00
tg 5abce90817 add MKSH_DEFAULT_TMPDIR 2010-04-20 17:28:20 +00:00
tg f41d5ba82f allow MKSHRC_PATH to change from 「"~/.mkshrc"」, for Android &c. 2010-03-27 20:36:26 +00:00
tg 4eb17f8752 remove some more of this ugliness 2010-01-29 09:34:31 +00:00
tg 0c94277ccb To solve the incompatibility issues between mksh-current, old mksh versions
and vendor pdksh versions, re-introduce FPOSIX alongside FSH. The semantics
are now:
‣ set -o posix ⇒
  • disable brace expansion and FSH when triggered
  • use Debian Policy 10.4 compliant non-XSI “echo” builtin
  • do not keep file descriptors > 2 to ksh
‣ set -o sh ⇒
  • set automatically #ifdef MKSH_BINSHREDUCED
  • disable brace expansion and FPOSIX when triggered
  • use Debian Policy 10.4 compliant non-XSI “echo” builtin
  • do not keep file descriptors > 2 to ksh
  • trigger MKSH_MIDNIGHTBSD01ASH_COMPAT mode if compiled in
  • make “set -- $(getopt ab:c "$@")” construct work

Note that the set/getopt one used to behave POSIXly only with FSH or
FPOSIX (depending on the mksh version) set and Bourne-ish with it not
set, so this changes default mksh behaviour to POSIX!
2010-01-28 15:18:51 +00:00
tg f3b3b4b1fb remove some debugging code 2010-01-25 14:38:04 +00:00
tg 1ac42c1c1c fix © year 2010-01-25 14:07:39 +00:00
tg 6115f5a91c • re-implement wcswidth-like behaviour for ${%foo} even in !UTFMODE
• merge the rest of branch tg-wcswidth-behaviour
• enhance test cases for wcswidth-like behaviour
• switch hash table collision resolution algorithm to Python’s as announced
• bump vsn
2010-01-01 17:44:10 +00:00
tg 8213a28403 llvm/clang scan-build is now content… 2009-12-05 17:43:50 +00:00
tg f7ef72cbd7 Kürzen! 2009-12-05 13:02:26 +00:00
tg fa3acb939b fix 'mksh -U -i' and 'mksh +U -i' 2009-11-28 15:38:30 +00:00
tg f0bec87228 • fix 「mksh -lT1」 (it was broken due to getpgrp() et al. being
moved to early)
• allow ‘-T’ for MKSH_SMALL too, the installer needs it

sync clog
2009-10-30 14:37:43 +00:00
tg eafe88aa74 • overhaul handling of special variables
• use a combination of the one-at-a-time hash and an LCG for handling
  the $RANDOM special if !HAVE_ARC4RANDOM instead of rand(3)/srand(3)
  and get rid of time(3) usage to reduce import footprint
• raise entropy state (mostly in the !HAVE_ARC4RANDOM case though…)
• simplify handling of the $RANDOM_SPECIAL generally
• tweak hash() to save a temp var for non-optimising compilers
• some int → mksh_ari_t and other type fixes
• general tweaking of code and comments
2009-10-17 21:16:05 +00:00
tg 33b9f8b666 * rename "set -o posix" (FPOSIX) to "set -o sh" (FSH) because it's not
just a "somewhat more POSIX" but also a "/bin/sh legacy kludge" mode
* consistently capitalise POSIX and SUSv3/SUSv4 (same as AT&T ksh) and
  Bourne shell
2009-10-02 18:08:37 +00:00
tg ff8b75f46f SUSv4 says that there be exit 127; the old code tried but failed, so it
was an actual programmatical bug…
2009-09-29 12:28:13 +00:00
tg c8955138ec • avoid calling arc4random_pushb for inheritance and other redundant items;
call it only if $RANDOM is indeed set (although pool extension would be a
  possibility we do have arc4random_atexit which does it nicely too)
• avoid calling setspec for int→str conversion just before execve()
2009-09-27 10:31:06 +00:00
tg a59d14b565 further optimise and simplify the handling of $RANDOM, reads and writes
to it are now either arc4random or rand/srand, but srand retains the old
state; set +o arc4random is no longer possible, but if it's there we use
arc4random(3), if not, we use rand(3) for $RANDOM reads; optimise special
variable handling too and fix a few consts and other minor things
2009-09-26 03:40:03 +00:00
tg b50b43e3bf get rid of "U getenv" 2009-09-26 01:08:27 +00:00
tg 1dfb13b603 change undef/def MKSH_NOVI into 0/1 MKSH_S_NOVI flag (with more to come:
MKSH_S_EDIT for small (Emacs) editing mode, MKSH_S_FEAT for all the dis-
abled language features), which can be set to 0 despite MKSH_SMALL being
defined to re-enable the Vi command line editing mode (which I wouldn't,
but fits into the general mastermind scheme)
2009-09-24 17:15:33 +00:00
tg 1a28786229 * shrink MKSH_SMALL even further by removing functionality like
some GNU bash extensions (suggested by cnuke@) and bind macros
* make the random cache more efficient (and the code potentially
  smaller, although we have a new implementation of the oaat hash
  function, alongside the old one, now) and pushb only if needed
  (i.e. state has changed or user has set $RANDOM, but not onfork)
2009-09-23 18:04:58 +00:00
tg 588921333e more of this:
• shell flags are now handled in one single place (sh_flags.h)
• sync comments (between enum and array) and manpage with reality
• FMONITOR is now no longer needed for Hartz IV shells
2009-09-20 16:40:58 +00:00
tg 9531e12b36 merge the nameref code, using mksh standard scoping as discussed 2009-09-06 17:42:15 +00:00
tg 3a288c105f a couple of overnight, phone call and code/doku read ideas:
• we must not set the item pointer to NULL, since subsequent ktscan()
  would stop there and not find any later occurrences
  possible resolution strategies:
  ‣ still keep tablep; store a dummy value (either (void *)-1 or, probably
    more portable, &ktenter or something like that) as is-free marker
    ⇒ retains benefit of keeping count of actually used entries
    ⇒ see below for further discussion
  ‣ don't keep tablep; revert back to setting entry->flag = 0
    ⇒ need to ktwalk() or ktsort() for getting number of entries
    ⇒ most simple code
  ‣ same but with a twist: make ktscan() set pp to the first one with
    !(entry->flag & DEFINED)¹ so that it can subsequently be re-used,
    or, more accurate, free’d and the entry pointer re-used
    ⇒ less chance of texpand()ing when not needed
  ‣ similar (from kabelaffe@): in ktsearch(), move the one we DID find
    to the first unused one
    ⇒ doesn’t need tablep or something, but has the overall best
      memory use
    ⇒ more complicated ktscan(): needs to check pointer for NULL, for
      dummyval, then entry->flag
    ⇒ makes lookup more expensive
    ⇒ benefit: self-optimising hash tables
    ⇒ loss: still need ktwalk() or ktsort()
• when afree()ing in ktremove(), …
  ① need to take FINUSE into account
• Python-2.5.4/Objects/dictnotes.txt talks about cache lines
  ‣ linear backward scan is much worse than linear forward scan
    (even if we have to calculate the upper C-array bound)
  ‣ dereferencing the entry pointer in ktscan() is a penalty
• Python-2.5.4/Objects/dictobject.c has a lot of comments and
  a rather interesting collision resolution algorithm, which
  seems to de-cluster better than linear search at not much
  more cost
• clib and libobjfw have unusable (for looking-at-for-ideas)
  hash table implementations

this is a no-op change breaking ifdef-out-d code; the most likely
to happen is to switch to the following scheme:
• keep tablep in struct tbl
• use a magic pointer value for ktremove’d entries, deallocate
  the struct tbl as soon as possible – if not FINUSE, immediately
  inside ktremove()
  ‣ memory gain, despite needing to have tablep around
• nuke ktdelete, so that all ops go through kt{enter,remove}
  ‣ gains us accurate fill information
  ‣ speed gain: ktscan() needs no longer dereference removed entries
  ‣ memory (ktsort) and speed (ktwalk) gain: removed entries are now
    ignored right from the beginning, so tstate->left and the size
    of the sorted array are accurate
  ‣ removed entries no longer can cause texpand() to be invoked
⇒ this does not give us self-optimising tables, but a speed and
  memory benefit plus, probably, simplicity of code; we accurately
  know how many non-deleted entries are in a keytab so we can cal-
  culate if we need to expand, how much space ktsort() is going to
  need, and, for when indexed arrays will be converted to use key-
  tabs instead of singly linked linear lists, ${#foo[*]} is fast
  (although ${!foo[*]}² and ${foo[*]}³ will need some tweaking and
  may run a little less quickly)
• shuffle code around, so that things like search/scan and garbage
  collection can be re-used
• use Python’s collision resolution algorithm ipv linear search

② the list of keys needs to be sorted, at least for indexed arrays⁴
③ this needs to be sorted by keys, at least for indexed arrays⁴
④ … but this is a nice-to-have for associative arrays⁵ as well
⑤ which we however do not have
2009-08-29 11:26:44 +00:00
tg 9b8d4023fa … but since I liked the bonus of having the hval stored so much, merge
it with the array index; var.c says that
│ 1244         /* The table entry is always [0] */
so that we can have a special flag and a union which stores hval for
the table index, the array index otherwise (coïncidentally *hint hint*
they have the same size)
2009-08-28 21:01:27 +00:00
tg bb7a720a00 for now, until we really use kt*() otherwise, ifdef out tablep/hval 2009-08-28 20:38:43 +00:00
tg 4ccdfc8508 much better solution: save tablep and hash value¹ in the struct tbl entry
① also saves time during texpand :D

XXX this doesn’t work well with the current indexed-array implementation
2009-08-28 20:30:59 +00:00
tg 7240c843ce this is a rather stupid diff: give ktsearch/ktenter the capability to
return information needed to do a real ktremove instead of the pseudo
ktdelete operation which merely unsets the DEFINED flag to mark it as
eligible for texpand garbage collection (even worse, !DEFINED entries
are still counted)
2009-08-28 19:57:43 +00:00
tg ca1f967a45 • use Jenkins’ one-at-a-time hash for mksh keytabs, as it has
much better avalanche and no known funnels
• improve comments
• fix some types (uint32_t for hash, size_t for sizes)
• optimise ktsort()

no functional change, I think
2009-08-28 18:54:01 +00:00
tg 0e1266ef90 While mksh R39 builds fine on MirOS #7s8E on my trusty sparc, pgcc 2.95.3
throws out quite some warnings – fix most of them except most emitted via
-Wconversion; work around some others; discard bogus warnings.

sync clog
2009-08-08 13:08:53 +00:00
tg 758dc5c6fe * improve CPPFLAGS vs #define handling again: do not touch CPPFLAGS from
Build.sh but use 'if defined(PRECOND) && !defined(TOBEDEFINED)'if possible
* for all of the source code, drop annotations "imake style" (if we check
  for specific OSes, bad, instead of using mirtoconf checks proper) and
  "conditions correct?" (if I'm not entirely sure if that #if catches all
  cases and no false positives) where I can see it by grepping immediately
* bump mksh patchlevel
* refresh Makefiles
2009-07-25 21:31:27 +00:00
tg cfe6688a36 in an interesting piece of self humour, remove the stop and suspend
aliases from shells requiring the Arbeitsamt to get a job ;-)
2009-07-25 20:52:41 +00:00
tg bcf4080793 improve MKSH_NOPWNAM handling, whether MKSH_SMALL or not; it will cause
the entire ~fac/ expansion code to be omitted
2009-07-25 20:26:33 +00:00
tg e1d8d7ed01 capitalise AT&T® 2009-06-11 12:42:21 +00:00
tg 0432f97ffe more KNF, mostly whitespace, this time more manual labour applying style(9) 2009-06-10 18:12:51 +00:00
tg 6b2ad96bac some rather mechanical KNF, now that style(9) clarified on the status
of sizeof() as a function-like unary operator; use parenthesēs around
sizeof and return args consistently too
2009-06-08 20:06:50 +00:00
tg 848e237b76 new feature: -DMKSH_ASSUME_UTF8=0 assumes utf-8 is *not* set and skips
environment inspection; useful for initrd and the likes
2009-06-07 22:28:05 +00:00
tg da5dc48cd0 implement an extension that an interactive mode input line, when
starting with an ‘!’ exclamation mark at the beginning of a com-
mand (PS1 not PS2), shall have the same effect as the predefined
“r” alias, to be compatible with csh and GNU bash’s “!string” to
«Execute last used command starting with string» – documentation
and feature request provided by wbx@ (Waldemar Brodkorb)
2009-05-27 19:52:38 +00:00
tg 361dee04f3 laffer1 agreed they will need -DMKSH_MIDNIGHTBSD01ASH_COMPAT in the
short term, but only for /bin/sh – thus recommend to also define
-DMKSH_BINSHREDUCED and make it dependent on FPOSIX
2009-05-16 21:00:52 +00:00
tg b6ce748064 • remove “#if 0” and “#ifdef notdef” style old debugging code
• expose “#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT” just in case they decide to
  require it and show it in the ksh version automatically
• sync the use of non-ASCII characters over files (unification)
2009-05-16 18:40:09 +00:00
tg b145ca5c9f • sync distrib/special/mksh/Makefile with bin/mksh/Build.sh and
fix the regression test’s results while here, which have been
  broken since cid 10049D9BE5254CE65B8
• get rid of separate copyright file which was intended for De-
  bian; track down commits in all files of oksh-mirbsd and mksh
  to get correct copyright years per-file, as is BSD custom
2009-05-16 16:59:42 +00:00
tg 8cc7fdb834 "evil" workaround to the alignment issues: embed an ALLOC_ITEM into
struct env (other structures defined have no "foreign type with pos-
sible alignment constraints" members) and take care of it while dea-
ling in a struct env instance
2009-04-07 19:43:28 +00:00
tg 398be9867a fix jobless mksh so much to make it work on Minix 3 2009-04-05 12:35:32 +00:00
tg efbdae7892 add (commented out) compatibility to MidnightBSD 0.1 /bin/sh – not
desired, because it defaces standards compliance

cf. https://www.mirbsd.org/permalinks/wlog-10_e20090329-tg-g10024.htm
2009-04-05 11:44:56 +00:00
tg b20f49adae patch from oksh (except manpage, I'll merge that later):
pass "xerrok" status across the execution call stack to more closely
match what both POSIX and [18]ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to &&' and ||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed !'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.
2009-03-22 17:47:38 +00:00
tg 0fe20ab25f sync with oksh (nop) 2009-03-22 17:31:17 +00:00
tg 32bc1dc40e sprinkle mksh_ari_t to limit arithmetics to 32 bit even
on Debian Lenny/amd64 (XXX need more verification; this
can be used for 64 bit arithmetics later too)

PPID, PGRP, RANDOM, USER_ID are now unsigned by default
2009-03-14 18:12:55 +00:00
tg 177b1b4cf9 always set COLUMNS and LINES; make use of the fact in dot.mkshrc 2008-12-29 21:34:22 +00:00