Commit Graph

73 Commits

Author SHA1 Message Date
tg 62b28858d4 sync; fold oksh-seterror test into errexit-*; use print not printf 2009-03-22 18:28:35 +00:00
tg abba28e8b1 the missing part 2009-03-22 18:20:36 +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 d99541d7c8 revert previous commit for now. testscript which breaks:
H4sIAAAAAAACA31TTUvDQBC951c804DtIQ0iiFhSPHiwiCDqzUpIuhO6JN2ETSS16n93Np+GFiGE
zM6bN2/fTPQOro5xENYuEVLzBz9eaF6RlWupSpyHaXqzVuvyljbbDCRV0UR7WeLiHEtT4D2GCcUy
pdNFh4pkg4wGZCV8Z6opTPOw3GI+swoq4ZIVZxqkSv0JqRAiWkBkmAJNegHIGG9vcAWcSnjM6dTo
uby8vsL7+wLllhQQKKr4SoFv/8nbXE5pQcdpk4nlwH6AE7zer17uVs/BmHVftnUdxYh0yHbV3ghY
9wh2rQlBkdMm8PmIe57Bjfs7dTW9X/OoEG6lwzwnzYKA7+8jHpsJTuFN4+IjKhKZM6dpZ0xuQ2Nz
7bGB1F74zlebmzTm/PS+OB0GZz4HLcPgz+BeDxyS9S7YU6e3qZaQk5gZgRHvQtI59Eet7QwBWFnL
O/F+ej9Fpmg0ug7OHrnqHy2+7y8x6DGEG3E0Az41RuPlYfXEEx0psrl8PAUebzf6ZklabgD8V3SS
Z7Vo6xfOuQS6gQMAAA==

「mksh -o posix z」 failed in that it continues; 「mksh z」 correctly aborts
let’s see what the obsd people have to say herefore
2009-03-16 15:50:13 +00:00
tg e39c1f860d bring back the backed-out Debian patch if FPOSIX; test programmes fixed:
H4sIAAAAAAACAz1PywrDIBA8m68YgoT20EN7TMixX1F6yGNFIWhRSw2h/95VmuDB2XmsY2oDRVyo
Si1N2uHlMzQK0b8JHaImy4RQwxIITYPiUs4xqcyeGgdfrfumtWX5dMbGSHy0WQgP1PJa49lhdpkV
ynncYSxkOjjxd/V83dmcX9sQtFGRi0zORmO5042HbwnMzlIBqa9lAmfLVBIZ7XqpKBPDnDu+WXpi
wMhnOgQXYvUD+oKHAhUBAAA=

XXX OpenBSD has something different which may DTST or even DTRT (not break
XXX our make(1) wrt <bsd.subdir.mk>), check that
2009-03-16 15:14:23 +00:00
tg 31d1499219 * back out almost all of the memory allocator related changes, as aalloc
was hard to type and hard to fix, galloc is also hard to fix, and some
  things I learned will probably improve things more but make me use the
  original form as base (especially for space savings)
* let sizeofN die though, remove even more casts
* optimise, polish
* regen Makefiles
* sprinkle a few /* CONSTCOND */ while here
2008-12-13 17:02:18 +00:00
tg 8d5d720f08 get rid of tempting sizeofN macro 2008-11-12 00:55:32 +00:00
tg 4d3fc2413e switch to a (nmemb,size) API from a (nmemb*size) API
cost: text += (308, 256, 4, -100)
2008-11-12 00:54:52 +00:00
tg 88d7b7d08b • rewrite code to no longer use statements-as-expressions
• optimise a little
• Build.sh: remove HAVE_EXPSTMT test
• Build.sh, */Makefile: sort tests, regenerate
• mksh.hts: sync clog
2008-10-28 14:32:43 +00:00
tg f17b8b1c8b • alloc() can’t fail, afree() can take NULL
‣ macro afreechk() is superfluous
• get rid of macro afreechv() by re-doing the “don’t leak that much” code
• some KNF (mostly, whitespace and 80c) while here
2008-05-17 18:47:03 +00:00
tg 9b62cf15bf • more unsigned → unsigned int
• more int → bool
• more regression tests: check if the utf8-hack flag is really disabled
  at non-interactive startup, enabled at interactive startup, if the
  current locale is a UTF-8 one
• make the mksh-local multibyte handling functions globally accessible,
  change their names, syntax and semantics a little (XXX more work needed)
• optimise
• utf_wctomb: src → dst, as we’re writing to that char array (pasto?)
• edit.c:x_e_getmbc(): if the second byte of a 2- or 3-byte multibyte
  sequence is invalid utf-8, ungetc it (not possible for the 3rd byte yet)
• edit.c:x_zotc3(): easier (and faster) handling of UTF-8
• implement, document and test for base-1 numbers: they just get the
  ASCII (8-bit) or Unicode (UTF-8) value of the octet(s) after the ‘1#’,
  or do the same as print \x## or \u#### (depending on the utf8-hack flag),
  plus support the PUA assignment of EF80‥EFFF for the MirBSD encoding “hack”
  (print doesn’t, as it has \x## and \u#### to distinguish, but we cannot use
  base-0 numbers which I had planned to use for raw octets first, as they are
  used internally): http://thread.gmane.org/gmane.os.miros.general/7938
• as an application example, add a hexdumper to the regression tests ☺
2008-04-19 22:15:06 +00:00
tg 7ddf56dbbc • new ksh_mbswidth
• fix: when printing menus (tab expansion, for instance), honour width of
  the multibyte characters printed
• some int→bool while here
2008-04-19 17:21:55 +00:00
tg 954352cae3 some more code “folding”
should decrease size
2008-04-01 22:20:20 +00:00
tg e8d61a1d99 • unify ksh_dup2() usage, use bool where appropriate
• apply diff from mirbsdksh-1.11:
  #ifdef DUP2_BROKEN
  /* Ultrix systems like to preserve the close-on-exec flag */
  ‣ XXX we do #ifdef __ultrix here (imake-style) instead of mirtoconfing it
    (but does anyone know of any other OS with the same problem? plus we’d
    see it as we now know the symptoms)
• remove ultrix Build.hs warn=' but might work…' in the hope it DOES
2008-04-01 20:40:22 +00:00
tg 84e78bcfb6 clean up 2007-10-25 13:27:00 +00:00
tg c1c939e340 • fix memory leaks found by coverity
from netbsd via oksh
  we had the NULL pointer deref already fixed
• avoid a bogus not-setting the return value of edit.c:x_file_glob()
  introduced by the above change in oksh
• escape ? as well (but not ] because that’s wrong)
  reminded by cbiere@netbsd via oksh
• Unsetting a non-existent variable is not an error. See
  http://www.opengroup.org/onlinepubs/009695399/utilities/unset.html
  report from Arkadiusz Miskiewicz; fixed based on
  http://cvs.pld-linux.org diff via oksh but modified slightly
• Be more smart waiting for input for non-interactive scripts.  Fix
  based on a diff from debian:  see their bug#296446 (via oksh)
  modified slightly
  this also fixes cnuke@’s “mksh busy loop” problem, for which I never
  received a bug report, but the Debian bug page contains a set of two
  scripts to reproduce this before (and no longer after) this commit
• some KNF
• bump version
2007-09-09 18:06:42 +00:00
tg e37577de42 fix another errexit bug: unwind() is __dead, so the pseudo-signal was never
delivered to the process
• regression test by Clint Pachl, verified against Debian ksh93 by me
• place to fix it in the code discovered by Otto Moerbeek
2007-07-24 11:22:04 +00:00
tg b09b3621e2 • we had an unused variable leftover
• make warning-free for both gcc and xlC
2007-07-22 14:01:50 +00:00
tg cf5fc9eac2 some null/NUL 2007-07-22 13:38:26 +00:00
tg 979406bba7 • support IBM xlC on AIX
• fix all bugs it could find ☺
2007-07-22 13:34:52 +00:00
tg f280b66d0a make sure ELF, a.out, COFF, MZ/PE and gzip binaries aren't executed via sh
should save us some error messages
2007-06-15 21:22:40 +00:00
tg 3dcf22a319 ok, icc _did_ track down a few ones, and I fixed errno abuse a little too
however, bad S/N ratio

side effect bonus: smaller code size now
2007-06-06 23:28:17 +00:00
tg a3e012c69b dead code removal 2007-05-13 18:49:00 +00:00
tg 0989f7da67 Fix for Coverity CID#2: false bug, but still a problem.
Analysis:
internal_errorf(int, fmt, ...) was only a __dead function if the int argument
was non-0, which the Prevent probably was unable to follow. Change all uses of
internal_errorf(0, fmt, ...) to internal_warningf(fmt, ...); change the pro-
totype of internal_errorf() to internal_errorf(fmt, ...) and all remaining
uses remove the non-0 int argument; add __dead to internal_errorf() proto;
flesh out guts of internal_errorf() and internal_warningf() into a new local
function for optimisation purposes.

Some whitespace cleanup and dead code removal (return after internal_errorf(1))
2007-05-13 17:51:24 +00:00
tg 0dba495c4b • MKSH_SMALL users want to trade off size vs functionality,
they thusly don't deserve shebang processing
• fix a comment (spelling; technical correctness)
2007-04-18 00:59:20 +00:00
tg 12b2011a96 also accept a carriage return as end of shebang line;
helps to at least not get messages like
| sysop@odem2k:~/mb $ ./foo.sh
| : No such file or directory
| 127|sysop@odem2k:~/mb $ _
if you forgot to convert CR-LF into LF (of course only if the
kernel fails with ENOEXEC – an ENOENT would not help in these
cases), but of course other things will fail
2007-04-17 21:26:34 +00:00
tg 2785ce3de4 • (re)implement shebang execution file parsing; this makes the “and which
do not start with a "#!shell" sequence” part of mksh(1) true again; this
  was probably lost in mksh R21 or so when I decided/saw that our kernel
  always parses shebang lines (code written myself, not taken from pdksh
  again or MirBSD kernel, but verified against both)
• bom+shebang execution now works, no need setting EXECSHELL in the test
• bump version
2007-04-15 12:09:57 +00:00
tg 83c2ee87f4 • remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char *
• enhance and stylify comments
• a little KNF and simplifications
• #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr
  that take and return a non-const char *, and fix the violations
• new cstrchr, cstrstr (take and give const char *)
• new vstrchr, vstrstr (take const or not, give boolean value)
• new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP)
• new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-")
• replace the only use of strrchr with inlined code to shrink
• minor man page fixes
• Minix 3 signames are autogenerated with gcc
• rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway,
  only strlcpy(3), and shorten it
• dot.mkshrc: move MKSH=… down to the export line
  to not disturb the PS1 visual impression ☺
• dot.mkshrc: Lstripcom(): optimise
• bump version

¹) side effect from creating API-correct cstrchr, cstrstr, etc.
   uses goto so it must be better ☻

tested on mirbsd-current via both Makefile and Build.sh
2007-03-04 03:04:28 +00:00
tg 62b347a1b0 merge the const branch +- a few 2007-03-04 00:13:17 +00:00
tg ddd2dac47d * support old environments without libgen.h (ancient GNU/Linux)
and stdbool.h (ancient GNU/Linux; NetBSD® 1.6.1)
* __dead must come after, not before, to accomodate gcc 2.7.2.3
2007-01-17 22:51:47 +00:00
tg a712de8e63 ok, -rHEAD shall be unbroken 2007-01-15 00:18:47 +00:00
tg 87f681b488 * revert some of the const-warning cleanup which must be done
with different means (reads, tricky magical kludgery)
  YES, THIS BREAKS -rHEAD, I KNOW.
* while here, fix spelling
2007-01-12 10:18:22 +00:00
tg 5891915f1b * Scan for __attribute__((...)) in general (the earliest was 2.5,
where we had 'noreturn' etc. but no '__noreturn__')
* Scan for __attribute__((bounded)) and __attribute__((used))
  if we have __attribute__((noreturn))
* To be able to scan if certain attributes give warnings,
  scan for -Werror with a simple programme which hopefully triggers none
* Convert __attribute__((unused)) to __unused, noreturn -> __dead
* Unify other attributes
* Clean up typography a little more
2007-01-12 01:49:29 +00:00
tg 151d913115 remove all but these __CRAZY=Yes build warnings:
main.c: In function 'main':
 main.c:208: warning: cast discards qualifiers from pointer target type
 main.c:329: warning: cast discards qualifiers from pointer target type

no warnings at autoconf time left either; will take care of these two later
(might revisit changes from this commit), maybe change declararion for the
builtins to have their argv[] be const strings, and go through strict type
and qualifier checking again. this'll further improve stability.

XXX these changes might have introduced (more?) memory leaks,
XXX someone who knows about these tools should verify with
XXX automatic memory usage analysers (valgrind?)

still passes testsuite
2006-11-12 14:58:16 +00:00
tg 2342fa1242 don't use setreuid(2) etc. stuff, like OpenBSD
only affects suid shell scripts, which are *ugh* anyway,
and I really have no idea what the old code did, when, why, etc.
262t 16d 2i
2006-11-10 06:16:25 +00:00
tg a1ff719ba4 thanks to the nice property of my reimplementation of getn to also
return a value in case of an error (0 or the partial result, which
is the full result in case of trailing junk even), using it to rid
atoi() is possible, saving 9t 4d 1i
2006-11-10 04:03:59 +00:00
tg c60dbdc6cb * change EXECSHELL to /bin/sh (we can override it via environment anyway,
and this is a sensible choice instead of ourselves)
* move this stuff from sh.h into exec.c where it belongs
* simplify set -o stuff

saves 8 bytes
2006-11-10 01:44:40 +00:00
tg 5e619e1ef3 style(9) 2006-08-01 13:43:28 +00:00
tg 7672b9b346 apply some fixes from OpenBSD and don't apply some others
but sync RCS IDs for easier future adaption:
* Simplify savefd() by removing the "noclose" flag and make noclose
  behavior the default. Almost all uses of savefd() are followed
  by an implicit or explicit close.
* fix typos
* might as well make ksh_getopt() match real getopt(), ie. get rid of that
  stupid EOF concept that was never true. adobriyan@gmail
* use SEEK_* for lseek()
* fix lint comments, no functional changes
* remove excessive optimization; from adobriyan@gmail
* only santa checks things twice; from adobriyan@gmail
* Interpret zero-filled numbers as decimal; PR 4213; from Alexey Dobriyan
2006-05-10 18:54:13 +00:00
tg 3f2912d717 * update to mksh R26c
* there is no comma in front of "which" in English, I was taught
2006-01-30 12:37:24 +00:00
tg 94ee3b388a sync with OpenBSD: remove unused code and vars; name clash with libc
compiles under MirBSD
2006-01-29 20:04:54 +00:00
tg 95cfad6339 * only have one $MirOS RCS ID per file to shrink source size
(this is an exception from normal use)
* bump to R26
2005-11-22 18:40:44 +00:00
tg f38d8299f9 Change interpretation of '\"' in here documents with substitution
according to SUSv3 and other modern shells (POSIX allows both).
Idea for the patch (add another lex state) from OpenBSD, but the
implementation differs slightly (and is better in quality).

Also add two testcases (/bin/sh passes both, old mksh only one),
and document the change in the manual page. Sync RCS IDs with OBSD.
2005-11-22 18:36:20 +00:00
tg 9b97d72d5e * move _all_ #include stuff into sh.h
* sort out #include stuff which isn't necessary on MirOS into compat.h
2005-10-25 19:53:29 +00:00
tg 7ee8296628 our test(1) promises we can do string1 < string2, and
our /bin/test uses mksh... so we pee (literally) on
POSIX and don't accept < and > only for [[ ... ]] operator
2005-10-08 19:31:00 +00:00
tg 3506838417 undo fix for Debian PR #71256 which turned to be bogus and break make(1) 2005-07-07 22:00:45 +00:00
tg 76c700b3a6 get rid of $PGRP
get rid of special bourne-shell emulating mode
2005-07-04 12:34:24 +00:00
tg e392a30930 get rid of special "POSIX"ish mode 2005-07-04 12:27:28 +00:00
tg 84dcd241c1 the new pdksh maintainer's patch is bogus
he didn't even run the testsuite

now, in not-rv_pass mode, traps are still executed
XXX look where this could break
2005-05-25 14:07:29 +00:00
tg d7c3f0a066 make setuid/setgid scripts and access() work again
by reverting some OpenBSD and applying some Debian diff
2005-05-25 13:46:02 +00:00