1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 19:52:20 +00:00
Commit graph

809 commits

Author SHA1 Message Date
Martijn Dekker
005d38f410 tests/leaks.sh: add procfs method for Linux
This allows faster testing for memory leaks on Linux if
ksh is compiled without vmalloc.
2021-01-28 21:59:27 +00:00
Martijn Dekker
ab6b483b17 features/pty: restore build on AIX by reordering #includes 2021-01-28 07:19:07 +00:00
Martijn Dekker
674a0c3559 Another lexical fix for here-documents (re: 6e515f1d)
OpenSUSE patch from:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-heredoc.dif

src/cmd/ksh93/sh/lex.c: here_copy():
- Do not potentially seek back a zero or negative length.
2021-01-28 06:32:42 +00:00
Martijn Dekker
4604df9ada Stack robustness fixes from OpenSUSE
Three OpenSUSE patches from:
https://build.opensuse.org/package/show/shells/ksh

As usual, the relevant bug is not currently public:
https://bugzilla.opensuse.org/show_bug.cgi?id=844071

src/cmd/ksh93/sh/xec.c: sh_debug()/sh_exec():
- Fix stk restoration. [bnc#844071]

src/lib/libast/misc/stk.c:
- Fix stk aliasing code. [bnc#844071]
  (ksh93-stkalias.dif)
- Make a unknown location fatal in stkset() so that we get a core
  dump right away instead of later in an unrelated part of code.
  (ksh93-stkset-abort.dif)

src/lib/libast/man/stk.3,
src/lib/libast/man/stak.3:
- Update manual with new stkset() behaviour. (93u+m addition)
  (Note that stak is implemented as macros that translate to stk)
2021-01-28 06:18:44 +00:00
Martijn Dekker
c5bd6874ef test -p: fix bug due to wrong parentheses
Patch from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-test.dif

src/cmd/ksh93/bltins/test.c:
- Fix parentheses in the isapipe() macro.
- test_binop(): Initialise variables.
2021-01-28 05:16:49 +00:00
Martijn Dekker
288b6c6517 Fix various possible uses of uninitialised variables
Patch from OpenSUSE, slightly adapted for 93u+m. Source:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-uninitialized.dif
2021-01-28 04:54:41 +00:00
Martijn Dekker
c52cb93999 sh_funscope(): Fix possible dereference of null pointer
Patch from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-unset-f.dif
2021-01-28 04:38:48 +00:00
Martijn Dekker
129614b99f edit/vi.c: sanity checks from OpenSUSE
Source: https://build.opensuse.org/package/view_file/shells/ksh/ksh93-vi.dif
Patch from 2007, apparently never upstreamed.
2021-01-28 04:35:46 +00:00
Martijn Dekker
3ad4307054 name.c: fix possible crash in attstore()
From OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-env.dif
(the init.c fix there is already done differently in 3654ee73)

src/cmd/ksh93/sh/name.c: attstore():
- Check nv_mapchar() returns a non-null pointer before using it.
2021-01-28 04:01:49 +00:00
Martijn Dekker
cc4927529b libast: Update cdt(3): Allow empty strings in (dt)trees
This backports most of the Cdt (container data types) mechanism
from the ksh 93v- beta, based on ground work done by OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-dttree-crash.dif
plus adaptations to match ksh 93u+m and an updated manual page
(src/lib/libast/man/cdt.3) added directly from the 93v- sources.

| Thu Dec 20 12:48:02 UTC 2012 - werner@suse.de
|
| - Add ksh93-dttree-crash.dif - Allow empty strings in (dt)trees
|   (bnc#795324)
|
| Fri Oct 25 14:07:57 UTC 2013 - werner@suse.de
|
| - Rework patch ksh93-dttree-crash.dif

As usual, precious little information is available because the
OpenSUSE bug report is currently closed to the public:
https://bugzilla.opensuse.org/show_bug.cgi?id=795324

However, a cursory inspection suggests that this code contains
improvements to do with concurrent processing and related
robustness. The new cdt.3 manual page adds a lot about that.

This has been in production use on OpenSUSE for a long time,
so hopefully this will make ksh a little more stable again.
Only one way to find out: let's commit and test this...

BTW, to get a nice manual, use groff and ghostscript's ps2pdf:
$ groff -tman src/lib/libast/man/cdt.3 | ps2pdf - cdt.3.pdf
2021-01-28 02:44:52 +00:00
Martijn Dekker
aa2644ab84 build: add missing version.h dependencies (re: 7fdeadd4)
src/cmd/ksh93/Mamfile:
- parse.c and shcomp.c now depend on version.h; this makes sure
  they are rebuilt if version.h changes.
2021-01-28 00:47:35 +00:00
Martijn Dekker
77ab60a149 iffe: revert <stdio.h> removal, add different fix (re: 308696ec)
Commit 308696ec caused the build to fail on macOS Catalina.

src/cmd/INIT/iffe.sh:
- Fix a blatantly unportable practice of passing multiple
  "|"-separated 'case' patterns through a variable. This was a way
  of grepping for some headers including stdio.h, but it only works
  this way on ksh93 and possibly the original Bourne shell, and not
  on *any* other shell (not even pdksh or mksh) -- and the fact
  that it works on ksh93 is arguably a bug. Fix by eliminating the
  "noext" variable (which is init'ed once and never changes) and
  using the pattern in the relevant 'case' statement directly.

src/cmd/builtin/features/pty:
- No matter what I try, including <stdio.h> causes the build to
  fail on Gentoo Linux (i386) with mysterious "invalid identifier:
  off64_t" errors -- this is probably some AST preprocessor hackery
  gone awry, but I've no idea where to even begin with that. This
  works around the problem by using AST sfio instead, which is
  built and functional by the time this feature test is run.
- Remove explicit extern declaration for ptsname(2) that was never
  used because it depended on an npt_ptsname feature test that
  doesn't exist (or no longer exists).
- Add missing <fcntl.h>, <stdlib.h>, and <unistd.h> for open(2),
  ptsname(2) and close(2), respectively.

src/lib/libast/features/float,
src/lib/libast/features/sfio,
src/lib/libast/features/stdio:
- Re-include <stdio.h>.

Fixes: https://github.com/ksh93/ksh/issues/164 (I hope)
2021-01-27 15:30:16 +00:00
Martijn Dekker
399886daa9 **/Mamfile: iffe: rm irrelevant flags (re: 580ff616, 6cc2f6a0)
This fixes annoying warnings from feature tests that show up when
building with IFFEFLAGS=-d1 (show compiler output from iffe), e.g.:

| In file included from <built-in>:367:
| <command line>:3:26: warning: missing terminating '"' character [-Winvalid-pp-token]
| #define _AST_git_commit \"a5c53a59\"
|                          ^
| 1 warning generated.

This means the double quotes were incorrectly escaped, which is
probably a bug in mamake -- but they're done correctly for the .c
files that actually need these flags. I may or may not trace the
mamake bug sometime.

src/*/*/Mamfile:
- Remove ${KSH_SHOPTFLAGS} en ${KSH_RELFLAGS} from the iffe
  invocations; they are not relevant for feature tests, only when
  actually compiling .c files (the $CC commands).
2021-01-27 14:54:53 +00:00
Martijn Dekker
db5621dbf8 Fix editor prediction code garbling input
This applies a patch from OpenSUSE. Source:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-edpredict.dif

| Tue Jul  5 14:49:03 CEST 2016 - mls@suse.de
|
| - fix editor prediction code garbling input [bnc#964966]
|   new patch: ksh93-edpredict.dif

Unfortunately the bug report is not currently public:
https://bugzilla.opensuse.org/show_bug.cgi?id=964966
but this one seems sensible enough and is in production use,
so I'll take it on faith.
2021-01-27 05:56:12 +00:00
Martijn Dekker
9b5ff0f833 Fix leak in optimize processing
This applies a patch from OpenSUSE. Source:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-optimizeleak.dif

| Tue Jul  5 14:49:03 CEST 2016 - mls@suse.de
|
| - fix leak in optimize processing [bnc#982423]
|   new patch: ksh93-optimizeleak.dif

Unfortunately the bug report is not currently public:
https://bugzilla.opensuse.org/show_bug.cgi?id=982423
but this one seems sensible enough and is in production use,
so I'll take it on faith.
2021-01-27 05:51:47 +00:00
Martijn Dekker
6d1352699e Fix locking error in spawn implementation
This applies a patch from OpenSUSE. Source:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-spawnlock.dif

| Wed Oct 12 13:23:14 CEST 2016 - mls@suse.de
|
| - fix locking error in spawn implementation [bnc#988213]
|   new patch: ksh93-spawnlock.dif

Unfortunately the bug report is not currently public:
https://bugzilla.opensuse.org/show_bug.cgi?id=988213
but this one seems sensible enough and is in production use,
so I'll take it on faith.
2021-01-27 05:32:24 +00:00
Martijn Dekker
a5c53a59e1 pty: more tweaks (re: 206bba4f, 5a2e7dae)
src/cmd/builtin/pty.c:
- Add missing #include <signal.h>.
- No need to limit SIGTTOU handling to Linux only -- it is POSIX
  compliant. Change #ifdef __linux__ to #ifdef SIGTTOU.
- The ECHOKE flag is not POSIX, so protect it with an #ifdef.
- s/slave/minion/g because minions are way more fun.
2021-01-27 04:51:01 +00:00
Martijn Dekker
206bba4f2e pty.c: Restore build on systems without cfmakeraw(3) (re: 5a2e7dae)
The OpenSUSE patch uses cfmakeraw(3) which is on Linux, BSD and
macOS, but not portable. The build failed on Solaris and variants.

src/cmd/builtin/features/pty:
- Add simple test for the presence of cfmakeraw(3). I love iffe.

src/cmd/builtin/pty.c:
- Add POSIX compliant fallback flaggery for systems without it.
2021-01-27 02:54:25 +00:00
Martijn Dekker
8e45daeaf1 ksh93/README: we now build on Alpine, 0 regress fails (re: e245856f) 2021-01-27 01:14:13 +00:00
Martijn Dekker
eaacfbb929 tests/pty.sh: Re-disable the process group exercise test
It freezes the 'less' pager on OpenBSD, which is not a ksh bug.
2021-01-27 00:55:20 +00:00
Martijn Dekker
28f97ba85c Allow building on AIX
This makes ksh build at least on AIX 7.1 on RISC (PowerPC).

There are 4 regression test failures:

        leaks.sh[159]: memory leak on PATH reset before PATH search
        (leaked approx 220 KiB after 16384 iterations)

        pty.sh[351]: POSIX sh 104(C): line 364: expected
        "^done\r?\n$", got EOF

        signal.sh[280]: subshell ignoring signal does not send
        signal to parent (expected 'SIGUSR1', got 'done')

        signal.sh[282]: parent does not wait for child to complete
        before handling signal

src/cmd/INIT/iffe.sh:
- Unset LIBPATH on AIX. The features/pty output{ ... }end will fail
  to link to libiconv otherwise, causing a build failure. See:
  https://www.ibm.com/support/pages/member-libiconvso2-not-found-archive

src/cmd/builtin/pty.c:
- CMIN is not defined on AIX, so set it to 1 if it's not defined.

src/cmd/ksh93/README:
- Update list of tested OSs.
2021-01-27 00:44:26 +00:00
Martijn Dekker
308696ec95 feature tests: do not re-include <stdio.h>
iffe --man documents that stdio.h is automatically pre-included for
all feature tests. Including it in the test code is not needed.

You'd think it shouldn't do any harm, but on a Gentoo i386 system,
this include turned out to be the cause of a mysterious 'unknown
type: off64_t' error while compiling the output{ ... }end block in
features/pty. I'm not going to bother with further tracing the
cause of that -- there is some hackery with off64_t defines in the
AST headers that probably has something to do with it.

src/cmd/builtin/features/pty,
src/lib/libast/features/float,
src/lib/libast/features/sfio,
src/lib/libast/features/stdio:
- Remove '#include <stdio.h>' from output{ ... }end blocks.
2021-01-26 21:53:48 +00:00
Martijn Dekker
b6bd9815a4 **/Mamfile: Use IFFEFLAGS variable to add iffe flags like -d1
It was unreasonably hard to debug problems with iffe tests that
fail to compile where they should (particularly output{ ... }end
blocks that write esserntial headers).

In e72543a9 the problem was already somewhat mitigated by making
some of the failing output{ ... }end blocks emit #error directives
so that invalid/incomplete headers would cause an error at a
sensible point, and not a much harder to track error later.

This commit further mitigates the problem by making the Mamfiles
respect an IFFEFLAGS environmenet variable that is prefixed to
every iffe command's arguments. The typical use would be to export
IFFEFLAGS=-d1 to enable debug level 1: show compiler output for all
iffe tests. This now makes it reasonably feasible to detect
problems in the feature tests themselves.

src/**/Mamfile:
- Import IFFEFLAGS environment variable using setv.
- Prefix ${IFFEFLAGS} to every iffe command.

src/**/features/*:
- Amend the new fail error messages to recommend exporting
  IFFEFLAGS=-d1 to show the cause of the failure.

README.md, TODO:
- Updates.
2021-01-26 17:21:20 +00:00
Martijn Dekker
f033bb0351 alarm: don't save sh.ifstable (re: 18b3f4aa)
It is not correct to save sh.ifstable (a.k.a. shp->ifstable) before
calling a function and then restore it after; this can cause field
splitting to malfunction. See 70368c57.

The change to init.c in the Red Hat patch applied in 18b3f4aa
(shp->ifstable[0] = S_EOF) appears to be sufficient.

src/cmd/ksh93/bltins/alarm.c:
- Revert save/restore of sh.ifstable.

src/cmd/ksh93/tests/builtins.sh:
- Tweak the regression test to work correctly on a slower machine,
  i.e. a Raspberry Pi running FreeBSD 12.2 arm64 (thanks to hyenias
  for providing testing access).
2021-01-26 15:48:38 +00:00
Martijn Dekker
e72543a9fa Build system tweaks; fix use of brk(2)/sbrk(2) feature test
There is a feature test for brk(2)/sbrk(2), but it was not checked
for in one place in vmbest.c, causing libdll to fail to build on
FreeBSD aarch64 because the features/dll output{...}end block
failed to link. This commit allows libdll to build on that system,
though another mysterious build failure apparently remains.
https://github.com/ksh93/ksh/issues/154

src/lib/libast/include/vmalloc.h,
src/lib/libast/vmalloc/vmbest.c:
- Add missing '#if _mem_sbrk' directives to disable uses of sbrk(2)
  on systems that have removed this deprecated interface.

src/cmd/builtin/features/pty,
src/lib/libast/features/common,
src/lib/libast/features/float,
src/lib/libast/features/lib,
src/lib/libast/features/sfio,
src/lib/libast/features/sizeof:
- Add a fail clause to more 'tst - output{' blocks so they write an
  informative #error directive if they fail to compile and write
  required header identifiers. This should avoid much more obscure
  compile errors later on. (re: e20c0c6b)

.gitignore:
- Add pattern for emacs #backup# files.
2021-01-26 09:59:11 +00:00
Martijn Dekker
856a2bb253 **/Mamfile: add header comment pointing to MAM docs (re: 6cc2f6a0)
The only proper documentation of the MAM language is in Glenn
Fowler's paper, which is unfortunately copyrighted so we can't
include it. But we can at least provide a link to it.

src/**/Mamfile:
- Add header comment.

src/cmd/INIT/mamake.c:
- Re-enable clang warnings on unused values (there aren't any).
2021-01-25 14:38:58 +00:00
hyenias
19c427435b
typeset: Correct numeric attribute change for floating points (#163)
This commit resolves the following incorrect variable assignments:
$ unset a; typeset -uF a=2; typeset -p a
typeset -X a=0x1.0000000000p+1
$ unset a; typeset -Fu a=2; typeset -p a
typeset -X a=0x1.0000000000p+1
$ unset a; typeset -ulF a=2; typeset -p a
typeset -l -X a=0x1.0000000000p+1
$ unset a; typeset -Ful a=2; typeset -p a
typeset -l -X a=0x1.0000000000p+1
$ unset a; typeset -Eu a=2; typeset -p a
typeset -E -X a=2
$ unset a; typeset -Eul a=2; typeset -p a
typeset -l -E -X a=2

src/cmd/ksh93/bltins/typeset.c:
- If the unsigned option (-u) was provided in conjunction with a
  floating point (-F) then due to a flag collision with NV_UNSIGN
  and NV_HEXFLOAT both having the value of NV_LTOU caused the
  floating point to become a hexadecimal floating point (-X) in
  error. Also, if a -E option flag was followed with a -u option
  then the resulting variable would be both a scientific notation
  and a hexadecimal floating point at the same time.

src/cmd/ksh93/tests/attributes.sh:
- Add regression tests.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
2021-01-24 22:45:08 +00:00
Martijn Dekker
5a2e7dae67 pty: Fix signal handling (re: 1ca9286a)
This applies the OpenSUSE changes to pty.c from:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-builtin.dif

src/cmd/builtin/pty.c:
- Add a patch from OpenSUSE with a fix for signal handling.

src/cmd/ksh93/tests/pty.sh:
- Re-enable the process group exercise test.

Resolves: https://github.com/ksh93/ksh/issues/61
2021-01-24 18:57:27 +00:00
Martijn Dekker
70368c57d6 Fix field splitting bug triggered by DEBUG trap
An unquoted variable expansion evaluated in a DEBUG trap action
caused IFS field splitting to be deactivated in code executed after
the trap action. Thanks to Koichi Nakashima for the reproducer:

| v=''
| trap ': $v' DEBUG
| A="a b c"
| set -- $A
| printf '%s\n' "$@"
|
| Expected
|
| a
| b
| c
|
| Actual
|
| a b c

src/cmd/ksh93/sh/fault.c: sh_trap():
- Remove incorrect save/restore of sh.ifstable, the internal state
  table for field splitting. This reverts three lines added in ksh
  93t+ 2009-11-30. Analysis: As an expansion is split into fields
  (macro.c, lines 2367-2471), sh.ifstable is modified. If that
  happens within a DEBUG trap, any modifications in ifstable are
  undone by the restoring memccpy, leaving an inconsistent state.

src/cmd/ksh93/COMPATIBILITY:
- Document the DEBUG trap fixes, particularly the incorrect
  inheritance by subshells and functions that some scripts may now
  rely on because this bug is so longstanding. (re: 2a835a2d)

src/cmd/ksh93/tests/basic.sh:
- Add relevant tests.

Resolves: https://github.com/ksh93/ksh/issues/155

TODO: add a -T (-o functrace) option as in bash, which should allow
subshells and ksh-style functions to inherit DEBUG traps.

P.S.: The very handy multishell repo allows us to use 'git blame'
to trace the origin of the recently fixed DEBUG trap bugs.

The off-by-one error causing various bugs, reverted in 2a835a2d,
was introduced in ksh 93t 2008-07-25:
https://github.com/multishell/ksh93/commit/8e947ccf
(fault.c, line 321)

The incorrect check causing the exit status bug, reverted in
d00b4b39, was introduced in ksh 93t 2008-11-04:
https://github.com/multishell/ksh93/commit/b1ade268
(fault.c, line 459)

The ifstable save/restore causing the field splitting bug, reverted
in this commit, was introduced in ksh 93t+ 2009-11-30:
https://github.com/multishell/ksh93/commit/53d9f009
(fault.c, lines 440, 444, 482)

So all the bugs reported in #155 were fixed by simply reverting
these specific changes. I think that they are some experiments that
the developers simply forgot to remove. I've suspected such a thing
multiple times before. ksh93 was developed by researchers who were
genius innovators, but incredibly sloppy maintainers.
2021-01-24 16:09:02 +00:00
Martijn Dekker
e664b78f98 Add regress test for redirection in DEBUG trap action (re: 2a835a2d)
Turns out the previous commit also fixed the bug that disables the
DEBUG trap if a redirection is used in a DEBUG trap action -- in
other words, that's the same bug.

src/cmd/ksh93/tests/basic.sh:
- Add test from the reproducer in the bug report.

Makes progress on: https://github.com/ksh93/ksh/issues/155
2021-01-24 03:51:00 +00:00
Martijn Dekker
2a835a2d8a Fix restoring DEBUG trap upon exiting virtual subshell
This trap failed to be restored correctly when being trapped in
a subshell, causing corruption or a crash when restoring the
parent shell environment's trap upon leaving the subshell.

Thanks to Koichi Nakashima for the report and reproducer.

src/cmd/ksh93/sh/fault.c: sh_sigreset():
- Fix an off-by-one error in the loop that restores the
  pseudosignal traps.

src/cmd/ksh93/tests/basic.sh:
- Test overwriting the main shell trap in a subshell for all
  pseudosignals.

Makes progress on: https://github.com/ksh93/ksh/issues/155
2021-01-24 01:06:11 +00:00
Martijn Dekker
ac8e702ef2 sh.1: rm Solaris-specific SHOPT_PFSH info (re: f089d799)
The -P option only ever worked on Solaris so it's questionable it
should have been in the general-purpose manual to begin with. And
now it doesn't even work on Solaris as it disable SHOPT_PFSH with a
patch (that functionality is now provided by a wrapper that works
with all shells). So it's long past time to stop documenting it.

For the same reason, this also removes the info about invoking ksh
as pfksh, etc. -- this is still possible on Solaris with the new
method, but the functionality is no longer actually provided by
ksh. If the Solaris maintainers want it back in the man page, that
should be done by adding a patch to their build system.
2021-01-23 22:52:31 +00:00
Lev Kujawski
e73696fd87
Reenable the clobber method on UnixWare. (#160)
UnixWare's ps prefers to read psinfo (from the proc structure in
kernel memory) within /proc as an anti-Trojan horse measure.
Updates to argv[0] are still reflected within /proc/$pid/cmdline,
which is useful for diagnostic purposes.

src/cmd/ksh93/sh/main.c:
- Remove __USLC__ from the list of platforms excluded from the
  fixargs method.

src/cmd/ksh93/tests/basic.sh:
- Read /proc/$pid/cmdline instead of ps on UnixWare.
2021-01-23 21:31:47 +00:00
Martijn Dekker
d2cc520883 Disable SHOPT_KIA (ksh -R) by default
SHOPT_KIA enables the -R option that generates a cross-reference
database from a script. However, no tool to analyse this database
is shipped or seems to be available anywhere (in spite of multiple
people looking for one), and the format is very opaque. No usage
examples are known or findable on the internet. This seems like it
should not be compiled in by default, although we'll keep the code
in case some way to use it is found.

src/cmd/ksh93/SHOPT.sh:
- Disable SHOPT_KIA by default by removing the default 1 value.

src/cmd/ksh93/sh/args.c, src/cmd/ksh93/sh/parse.c:
- Fix a couple of preprocessor logic bugs that made it impossible
  to compile ksh without SHOPT_KIA.

src/cmd/ksh93/data/builtins.c:
- Fix typo in -R doc in ksh --man (in case SHOPT_KIA is enabled).

src/cmd/ksh93/sh.1:
- Since sh.1 is not generated dynamically, remove the -R doc.
2021-01-23 18:26:38 +00:00
Martijn Dekker
0a9c6fd771 Revert GNU __malloc_initialize_hook(3) change (re: e8b3274a)
This post-Korn AT&T commit from Feburary 2020 broke the build at
least on Slackware 14.2 with gcc 5.5.0 and glibc 2.23 if vmalloc
was disabled by defining _std_malloc or _AST_ksh_release (see
35672208). So building with vmalloc disabled has always been broken
on 93u+m on at least this version of Linux.

As usual, AT&T did not document the reason for applying this
change. It was also part of a commit that I already have little
trust in (I reverted another part of it in 16e4824c). So let's just
revert this and see what happens.

Hmm. The Linux __malloc_initialize_hook(3) manual page says it's
deprecated and was to be removed from glibc as of 2.24, whereas
Slackware 14.2 uses glibc 2.23. This would explain why this change
didn't break Linux with newer glibc versions, as the feature test
won't detect it and it won't be used at all.

src/lib/libast/features/vmalloc, src/lib/libast/vmalloc/malloc.c:
- Revert change in definition of __malloc_initialize_hook. It now
  conforms again with the spec in the Linux man page.

The build error caused by this change was:
| + cc -D_BLD_DLL -fPIC -D_BLD_ast '-D_AST_git_commit="e3f6d2d0"' -Os -g -D_std_malloc -I. -I/usr/local/src/ksh/src/lib/libast -Icomp -I/usr/local/src/ksh/src/lib/libast/comp -Ivmalloc -I/usr/local/src/ksh/src/lib/libast/vmalloc -Iinclude -I/usr/local/src/ksh/src/lib/libast/include -Istd -I/usr/local/src/ksh/src/lib/libast/std -D_PACKAGE_ast -c /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c: In function '_ast_mallopt':
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1089:58: warning: implicit declaration of function 'mallopt' [-Wimplicit-function-declaration]
|  extern int F2(_ast_mallopt, int,cmd, int,value) { return mallopt(cmd, value); }
|                                                           ^
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c: At top level:
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1093:22: error: return type is an incomplete type
|  extern Mallinfo_t F0(_ast_mallinfo, void) { return mallinfo(); }
|                       ^
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:72:19: note: in definition of macro 'F0'
|  #define F0(f,t0)  f(t0)
|                    ^
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c: In function '_ast_mallinfo':
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1093:52: warning: implicit declaration of function 'mallinfo' [-Wimplicit-function-declaration]
|  extern Mallinfo_t F0(_ast_mallinfo, void) { return mallinfo(); }
|                                                     ^
| /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1093:52: warning: 'return' with a value, in function returning void
| mamake [lib/libast]: *** exit code 1 making malloc.o
2021-01-23 15:44:55 +00:00
Martijn Dekker
c2108888df bin/package: reallow building old ksh versions (re: 6cc2f6a0)
When building old code for debugging purposes (e.g. when doing 'git
bisect' runs), it's best to use the current build system even with
the old code, because the old build system was very broken. E.g.:

	git checkout (some old commit)
	git checkout master bin src/cmd/INIT # use new build system
	bin/package make

However, that became impossible in 6cc2f6a0 because the new
SHOPT.sh script was unconditionally sourced. The error caused the
script to exit because '.' is a special builtin.

bin/package, src/cmd/INIT/package.sh:
- If src/cmd/ksh93/SHOPT.sh doesn't exist, issue a warning instasd
  of trying to source it.
2021-01-23 14:42:52 +00:00
Martijn Dekker
e3f6d2d0e6 Fix build on systems without O_CLOEXEC (re: 9f43f8d1)
A build failure on HP-UX B.11.11 was introduced when O_cloexec was
changed to O_CLOEXEC (which is POSIX standard) in the backported
93v- code. The lowercase variant is conditionally defined by libast
in src/lib/libast/features/fcntl.c precisely for compatibility with
systems that do not have O_CLOEXEC.

src/lib/libast/tm/tvtouch.c:
- Revert to using the AST O_cloexec flag when calling open(2).
2021-01-23 00:40:00 +00:00
Martijn Dekker
6cc2f6a0af Build system: make SHOPT_* editable again; allow indenting Mamfiles
The build system is adapted to make SHOPT_* compile-time options
editable without nmake. We can now easily change ksh's compile-time
options by editing src/cmd/ksh93/SHOPT.sh. The bin/package script
is adapted to turn these into compile flags. This resolves the most
important drawback of not using nmake.

Also, mamake now has support for indented Mam (Make Abstract
Machine) code. Only one type of block (make...done) is supported in
Mamfiles, so they are easy to indent automatically. A script to
(re)do this is included.

Since nmake is not going to be restored (it has too many problems
that no one is interested in fixing), this at least makes mamake
significantly easier to work with.

The Makefiles are deleted. They may still be handy for reference to
understand the Mamfiles, but they haven't actually matched the
Mamfiles for a while -- and you can still look in the git history.

Deleting them requires some adaptations to bin/package and mamake.c
because, even though they do not use those files, they still looked
for them to decide whether to build code in a directory.

Finally, this commit incorporates some #pragmas for clang to
suppress annoying warnings about the coding style used in this
historic code base. (gcc does not complain so much.)

src/cmd/ksh93/SHOPT.sh:
- Added.

bin/package, src/cmd/INIT/package.sh:
- cd into our own directory in case we were run from another dir.
- $makefiles: only look for Mamfiles.
- Add ksh compile-options via KSH_SHOPTFLAGS. Include SHOPT.sh.
- make_recurse(): Do not write a missing Makefile.
- finalize environment: Look for Mamfiles instead of Makefiles.

src/cmd/INIT/mamake.c:
- Tell clang to suppress annoying warnings about coding style.
- Update version string and self-documentation.
- input(): Add support for indented Mam code by skipping initial
  whitespace on each input line.
- files[]: Instead of looking for various of Makefiles to decide
  where to build, only look for Mamfiles.

src/Makefile, src/cmd/INIT/Makefile, src/cmd/Makefile,
src/cmd/builtin/Makefile, src/cmd/ksh93/Makefile, src/lib/Makefile,
src/lib/libast/Makefile, src/lib/libcmd/Makefile,
src/lib/libdll/Makefile, src/lib/libsum/Makefile:
- Removed.

src/Mamfile, src/cmd/INIT/Mamfile, src/cmd/Mamfile,
src/cmd/builtin/Mamfile, src/cmd/ksh93/Mamfile, src/lib/Mamfile,
src/lib/libast/Mamfile, src/lib/libcmd/Mamfile,
src/lib/libdll/Mamfile, src/lib/libsum/Mamfile:
- Indent the code with tabs.
- In ksh93/Mamfile, add ${KSH_SHOPT_FLAGS} to every $CC command.
- In ksh93/Mamfile, add "prev SHOPT.sh" for every *.o file
  so they are rebuilt whenever SHOPT.sh changes.

bin/Mamfile_indent:
- Added, in case someone wants to re-indent a Mamfile.

src/cmd/INIT/proto.c, src/cmd/INIT/ratz.c, src/cmd/INIT/release.c,
src/lib/libast/features/common, src/lib/libast/include/ast.h:
- Tell clang to suppress annoying warnings about coding style that
  it disapproves of (mainly concerning the use of parentheses).

src/cmd/INIT/cc.darwin, src/cmd/INIT/cc.freebsd,
src/cmd/INIT/cc.openbsd:
- Remove now-redundant clang warning suppression flags.

Resolves: https://github.com/ksh93/ksh/issues/60
2021-01-22 23:39:59 +00:00
Martijn Dekker
47468f56c2 main.c: fixargs(): add support for *BSD using setproctitle(3)
What is this for? See cefe087d

src/cmd/ksh93/Mamfile:
- Make iffe generate a test for the presence of setproctitle(3).

src/cmd/ksh93/sh/main.c:
- Include setproctitle test result.
- Re-enable fixargs() for FreeBSD and DragonFly BSD.
  Disable it for UnixWare.
- fixargs(): Add _lib_setproctitle version. Keep it simple with a
  128-character buffer array -- should be plenty for 'ps' output.
- fixargs(): Fix an off-by-one in zeroing the rest of the buffer.

src/cmd/ksh93/tests/basic.sh:
- Update the relevant regression test to run on FreeBSD/DragonFly
  and tolerate the "ksh: " prefix added by setproctitle(3).
2021-01-21 22:59:31 +01:00
Martijn Dekker
7fdeadd4f1 Increase shcomp bytecode header version; doc updates
src/cmd/ksh93/include/version.h:
- Centrally define the 93u+m copyright (SH_RELEASE_CPYR) for adding
  to the original AT&T copyright in 'ksh --man' and 'shcomp --man'.
- Centrally define the binary header version number for bytecode
  generated by shcomp: SHCOMP_HDR_VERSION.
- Bump SHCOMP_HDR_VERSION from 3 to 4. Converting all the preset
  aliases to builtin commands has caused new bytecode to be
  incompatible with old ksh. (However, old bytecode runs fine on
  93u+m, because shcomp pre-expands the preset aliases.)

src/cmd/ksh93/sh/shcomp.c:
- Instead of keeping its own version date (not changed since 2003),
  use the same version string as ksh itself (SH_RELEASE).
- Use SH_RELEASE_CPYR for the extra 93u+m copyright string.
- Use SHCOMP_HDR_VERSION for the bytecode header.

src/cmd/ksh93/sh/parse.c: sh_parse():
- Use SHCOMP_HDR_VERSION for the bytecode version check.

src/cmd/ksh93/data/builtins.c: opt_ksh[]:
- Use SH_RELEASE_CPYR for the extra 93u+m copyright string.

src/cmd/ksh93/COMPATIBILITY:
- Mention that 93u+m shcomp bytecode won't run on older ksh.
- Document changes in printf %T (re: 9526b3fa).

src/cmd/ksh93/README:
- Mention that we run on UnixWare (with major regressions).
  https://github.com/ksh93/ksh/pull/159#issuecomment-764667929
2021-01-21 17:04:14 +00:00
Martijn Dekker
9f43f8d10b Backport changes to AST time library from ksh 93v- beta
This incorporates the last changes in the tm library before AT&T
laid off the AST developers. It contains mostly time zone and
locale related changes/fixes.

I was hoping these would fix #52 (locale-based 'printf %T' output
is broken), but no such luck. This is probably good to have anyway.
2021-01-21 13:58:30 +00:00
Martijn Dekker
0a10e76ccc typeset: add error msgs for incompatible options; improve usage msg
This adds informative error messages if incompatible options are
given. It also documents the exclusive -m, -n and -T options on
separate usage lines, as was already done with -f. The usage
message for incompatible options now looks something like this:

| $ ksh -c 'typeset -L10 -F -f -i foo'
| ksh: typeset: -i/-F/-E/-X cannot be used with -L/-R/-Z
| ksh: typeset: -f cannot be used with other options
| Usage: typeset [-bflmnprstuxACHS] [-a[type]] [-i[base]] [-E[n]]
|                [-F[n]] [-L[n]] [-M[mapping]] [-R[n]] [-X[n]]
|                [-h string] [-T[tname]] [-Z[n]] [name[=value]...]
|    Or: typeset -f [name...]
|    Or: typeset -m [name=name...]
|    Or: typeset -n [name=name...]
|    Or: typeset -T [tname[=(type definition)]...]
|  Help: typeset [ --help | --man ] 2>&1

(see also the previous commit, e21a053e)

Unfortunately the first "Usage" line has some redundancies with the
"Or:" lines showing separate usages. It doesn't seem to be possible
to avoid this; it's a flaw in how libast generates everything
(usage, help, manual) from one huge getopt(3) string. I still think
the three added "Or:" lines are an improvement as it wasn't
previously shown that these options need to be used on their own.

src/cmd/ksh93/bltins/typeset.c: b_typeset():
- Instead of only showing a generic usage message, add an
  informative error message if incompatible options were given.
- Conflicting options detection was failing because NV_LJUST and
  NV_EXPNOTE have the same bitmask value. Use a new 'isadjust'
  flag for -L/-R/-Z to remember if one of these was set.
- Detect conflict between -L/-R/-Z and a float option, not just -i.

src/cmd/ksh93/include/name.h, src/cmd/ksh93/data/msg.c:
- Add the two new error messages for incompatible options.

src/cmd/ksh93/data/builtins.c: sh_opttypeset[]:
- Add a space after 'float' in in "[+float?\btypeset -lE\b]" as
  this makes 'float' appear on its own line, improving formatting.
- Show -m, -n, -T on separate usage lines like -f, as none of these
  can be combined with other options.
- Remove "cannot be combined with other options" from -m and -n
  descriptions, as that should now be clear from the separate usage
  lines -- and even if not, the error message is now informative.

src/cmd/ksh93/sh.1, src/cmd/ksh93/COMPATIBILITY:
- Update.

src/cmd/ksh93/tests/types.sh:
- Remove obsolete test: 'typeset -RF' is no longer accepted.
  (It crashed in 93u+, so this is not an incompatibility...)

Resolves: https://github.com/ksh93/ksh/issues/48
2021-01-21 09:36:10 +00:00
Martijn Dekker
e21a053e19 libast: optget: improve usage messages, adding help info line
For example, this changes 'typeset -Q' (a bad option) from:

| ksh: typeset: -Q: unknown option
| Usage: typeset [-bflmnprstuxACHS] [-a[type]] [-i[base]] [-E[n]]
|                [-F[n]] [-L[n]] [-M[mapping]] [-R[n]] [-X[n]]
|                [-h string] [-T[tname]] [-Z[n]] [name[=value]...]
|    Or: typeset [ options ] -f [name...]

to:

| ksh: typeset: -Q: unknown option
| Usage: typeset [-bflmnprstuxACHS] [-a[type]] [-i[base]] [-E[n]]
|                [-F[n]] [-L[n]] [-M[mapping]] [-R[n]] [-X[n]]
|                [-h string] [-T[tname]] [-Z[n]] [name[=value]...]
|    Or: typeset -f [name...]
|  Help: typeset [ --help | --man ] 2>&1

src/lib/libast/misc/optget.c: args():
- Revert the changes done in 6916a873 and ae92cd89. The --help and
  --man labels weren't added consistently (they did not show up in
  the example above) whereas they did show up unnecessarily in the
  manual page itself.
- In the usage section and usage messges, only show an [ options ]
  label on the first usage line; don't redundantly repeat on second
  and further ("Or:") lines.
- In usage and --help (but not --man), add a new "Help:" line
  telling the user about the --help and --man options. This
  replaces the reverted changes. Show the 2>&1 redirection as a
  reminder that you need to do this to pipe it into a pager, as
  everything is written to standard error!
- Add some comments clarifying what I think this code does...

src/cmd/ksh93/tests/builtins.sh:
- Update to match changes in getopts usage output.
2021-01-21 08:55:12 +00:00
Martijn Dekker
6445573d24 typeset: only alloc stack space if needed (re: ff70c27f)
src/cmd/ksh93/bltins/typeset.c:
- Don't call stakalloc(3) unless/until we actually need it to
  construct a new list of arguments.
2021-01-21 08:39:10 +00:00
Lev Kujawski
ff70c27f24
typeset: Fix stack fencepost error, ISO C90 compat (#159)
src/cmd/ksh93/bltins/typeset.c:
- The new_argv[] array was one item too short (should be argc+2).
- Use AST stakalloc(3) to allocate it instead of a dynamic array;
  this restores compatibility with ISO C90.

src/lib/libast/features/standards, src/cmd/INIT/cc.unixware.i386:
- Add support for UnixWare.
- Do not define any standards macros on this system, as on FreeBSD
  and DragonFly BSD.
2021-01-21 07:50:07 +00:00
Martijn Dekker
bb4d6a2ee5 cd: add missing "test.h" include (re: 5ee290c7)
Fixes: https://github.com/ksh93/ksh/issues/158
2021-01-20 22:13:32 +00:00
Martijn Dekker
8cd4bc1690 conf.sh: correct embarrassing typo (re: a75d0dfa) 2021-01-20 22:05:22 +00:00
Martijn Dekker
d00b4b39f6 Fix side effect to exit status of DEBUG trap in comsub
This fixes the following:

trap ':' DEBUG
r=$(exit 123)
echo $? # Expected 123, but actually 0.

Thanks to Koichi Nakashima for the report and reproducer.

src/cmd/ksh93/sh/fault.c: sh_trap():
- Restore the saved current exit status (exitval) for all traps.
  Do not except the DEBUG trap from doing that. I've no idea why
  this exception was made, but it's not correct.

src/cmd/ksh93/tests/basic.sh:
- Add tests.

Makes progress on: https://github.com/ksh93/ksh/issues/155
2021-01-20 17:48:09 +00:00
Martijn Dekker
5ee290c7a8 cd: Fork if $PWD exists but is not actually the PWD (re: d1483150)
Commit d1483150 did not fully fix #153.
Test case from Harald van Dijk that was still failing:

$ mkdir test
$ cd test
$ rmdir $PWD
$ mkdir $PWD
$ ksh -c "(cd /); pwd"
/

Forking a virtual subshell in that case is needed to avoid ending
up in a directory that replaced the PWD, because it will not be
possible for a process to change back to the original directory.

src/cmd/ksh93/bltins/cd_pwd.c:
- When deciding whether to fork, instead of attempting to opendir
  the PWD, compare the inodes $PWD and "." to determine if $PWD
  still actually refers to the current directory. This uses the
  test_inode() function which is also used by 'test foo -ef bar'.

src/cmd/ksh93/tests/subshell.sh:
- Add test based on the above.

Progresses: https://github.com/ksh93/ksh/issues/153
2021-01-20 05:56:38 +00:00
Martijn Dekker
ec0155ee65 tests/variables.sh: tweaks for special and locale variable tests
src/cmd/ksh93/tests/variables.sh:
- Fork the subshell with the test that includes unsetting LINENO
  and changing its type. Otherwise, some side effect of that leaks
  out of the subshell, messing up $LINENO. This is a bug, but it's
  low priority -- we may get to it someday. Marked with a TODO.
- Do the LC_* tests in their own subshell. Skip them if changing
  LANG to an invalid value does not produce a diagnostic message.
  This occurs on OpenBSD and Alpine Linux (with musl libc). It
  looks like their C libraries do not verify the locale, so
  failures here are not a ksh problem; skip the tests in that case.
2021-01-20 05:38:55 +00:00