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

777 commits

Author SHA1 Message Date
Martijn Dekker
4645e6ad33 job_reset(): fix for resetting foreground process group
Patch from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-foreground-prgrp.dif

src/cmd/ksh93/sh/jobs.c: job_reset():
- Only reset the foreground process group associated with the
  current job if the current job's process ID is different from the
  terminal's foreground process group ID.
2021-02-02 12:49:00 +00:00
Martijn Dekker
9f980ba65a sh_setmatch(): fix node size calculation
This fixes the function that sets ${.sh.match}. Patch from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-limit-name-len.dif

src/cmd/ksh93/sh/init.c: sh_setmatch():
- Fix node size calculation, possibly preventing data corruption.

src/cmd/ksh93/include/ulimit.h: Limit_t:
- Defining the 'name' struct member as 'char name[16]' makes
  no sense as the name is being initialised statically in
  data/limits.c; just make it a 'char *name' pointer.
2021-02-02 11:52:54 +00:00
Martijn Dekker
3002c4113e vmalloc: better detect default region size on Linux
This is a Linux-specific fix for vmalloc from OpenSUSE, for what
that's still worth; we're not going to keep using vmalloc long term.
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-vm.dif
2021-02-02 11:32:37 +00:00
Martijn Dekker
e2c2753ee8 libast: Fix detection of GCC 4.1+ 64/32-bit atomic operations model
This fix to the atomic scalar operations feature tests is from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-aso.dif
2021-02-02 05:27:08 +00:00
Martijn Dekker
69e18de58f edit.c: Fix history generation if there are zero arguments
This applies a fix from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-reg.dif
2021-02-02 05:24:11 +00:00
Martijn Dekker
627df2b19a libast: optget(3): fix some uninitialised variables
This is a part of this OpenSUSE patch:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-gcc.dif
2021-02-02 05:17:52 +00:00
Martijn Dekker
0684806d47 feature tests: signbit detection fix for ia64
An Intel Itanium fix from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-ia64.dif
2021-02-02 04:40:09 +00:00
Martijn Dekker
7a6980a380 libast/comp/conf.sh: apply limits detection fixes for Linux
This is another patch from OpenSUSE:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-limits.dif
2021-02-02 04:35:54 +00:00
Martijn Dekker
fa3a3d7955 sh_ntfork(): handle SIGTSTP along with SIGTTIN and SIGTTOU
This applies a patch from OpenSUSE that makes SIGTSTP handling
consistent with that of SIGTTIN and SIGTTOU.
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-signals.dif
2021-02-02 04:25:46 +00:00
Martijn Dekker
8a58166bc4 Add OpenSUSE fixes for the uname builtin on Linux
Original patches:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-uname.dif
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-no-sysctl.dif
2021-02-02 03:31:21 +00:00
Martijn Dekker
0e4c4d619d Fix minor typeset attribute regressions (re: 95fe07d8, fdb9781e)
This fixes the following regressions marked TODO in attributes.sh:

$ typeset -L 13 bar; readonly bar; typeset -p bar
typeset -r -L 0 foo		# exp.: typeset -r -L 13 foo
$ typeset -R 13 bar; readonly bar; typeset -p bar
typeset -r -R 0 bar		# exp.: typeset -r -R 13 bar
$ typeset -Z 13 baz; readonly baz; typeset -p baz
typeset -r -Z 0 -R 0 baz	# exp.: typeset -r Z 13 -R 13 baz

I've discovered that these were briefly fixed between fdb9781e (Red
Hat patch for typeset -xu/-xl) and 95fe07d8 (reversal of patch,
different -xu/-xl fix, but reintroduced these regressions).

src/cmd/ksh93/sh/name.c: nv_newattr():
- Replace check from 95fe07d8 with a new one that combines its
  approach with that of fdb9781e: do not change size (and hence
  return early) if NV_RDONLY and/or NV_EXPORT are the only
  attributes that are changing.

src/cmd/ksh93/tests/attributes.sh:
- Enable the TODO regression tests.
2021-02-02 02:20:37 +00:00
hyenias
fe05350f2d
typeset: fix short integer restriction (#166)
This commit corrects how shortint was being applied to various
possible typeset variables in error. The short integer option
modifier 'typeset -s' should only be able to be applied if the
the variable is also an integer. Several issues were resolved
with this fix:
- 'typeset -s': created a short integer having an invalid base
  of zero. 'typeset -s foo' created 'typeset -s -i 0 foo=0' and
  now will result in an empty string.
- 'typeset -sL': previously resulted in a segmentation fault.

The following are the various incorrect 'typeset' instances
that have been fixed:

$ 'export foo; typeset -s foo; readonly foo; typeset -p foo'
(before) typeset -x -r -s -i 0 foo=0
( after) typeset -x -r foo

$ 'typeset -sL foo=1*2; typeset -p foo'
(before) Segmentation fault (core dumped)
( after) typeset -L 3 foo='1*2'

$ 'typeset -sR foo=1*2; typeset -p foo'
(before) typeset -s -i foo=2
( after) typeset -R 3 foo='1*2'

$ 'typeset -sZ foo=1*2; typeset -p foo'
(before) typeset -F 0 foo=2
( after) typeset -Z 3 -R 3 foo='1*2'

src/cmd/ksh93/bltins/typeset.c: b_typeset():
- Add conditional check within the 's' option to only
  apply NV_SHORT as well as remove any NV_LONG flag
  if NV_INTEGER flag was set.
- Relocate shortint conditional logic to the 'i' option.

src/cmd/ksh93/tests/attributes.sh:
- Adjust regression tests for '-s' and add '-si' check.
2021-02-01 23:35:18 +00:00
Martijn Dekker
5491fe9724 Correctly block invalid values for arrays of an enum type
This fixes part of https://github.com/ksh93/ksh/issues/87:

Scalar arrays (-a) and associative arrays (-A) of a type created by
'enum' did not consistently block values not specified by the enum
type, yielding corrupted results.

An expansion of type "${array[@]}" yielded random numbers instead
of values for associative arrays of a type created by 'enum'.

This does not yet fix another problem: ${array[@]} does not yield
all values for associative enum arrays.

src/cmd/ksh93/bltins/enum.c: put_enum():
- Always throw an error if the value is not in the list of possible
  values for an enum type. Remove incorrect check for the NV_NOFREE
  flag. Whatever that was meant to accomplish, I've no idea.

src/cmd/ksh93/sh/array.c: nv_arraysettype():
- Instead of sh_eval()ing a shell assignment, use nv_putval()
  directly. Also use the stack (see src/lib/libast/man/stk.3)
  instead of malloc to save the value; it's faster and will be
  auto-freed at some point. This shortens the function and makes it
  faster by not entering into a whole new shell context -- which
  also fixes another problem: the error message from put_enum()
  didn't cause the shell to exit for indexed enum arrays.

src/cmd/ksh93/sh/name.c: nv_setlist():
- Apply a patch from David Korn that correctly sets the data type
  for associative arrays, fixing the ${array[@]} expansion yielding
  random numbers. Thanks to @JohnoKing for the pointer.
  https://github.com/ksh93/ksh/issues/87#issuecomment-662613887
  https://www.mail-archive.com/ast-developers@lists.research.att.com/msg00697.html

src/cmd/ksh93/tests/enum.sh:
- Add tests checking that invalid values are correctly blocked for
  indexed and associative arrays of an enum type.

Makes progress on: https://github.com/ksh93/ksh/issues/87
2021-02-01 16:57:43 +00:00
Martijn Dekker
6a0e9a1a75 Tweak and regress-test 'command -x' (re: 66e1d446)
Turns out the assumption I was operating on, that Linux and macOS
align arguments on 32 or 64 bit boundaries, is incorrect -- they
just need some extra bytes per argument. So we can use a bit more
of the arguments buffer on these systems than I thought.

src/cmd/ksh93/features/externs:
- Change the feature test to simply detect the # of extra bytes per
  argument needed. On *BSD and commercial Unices, ARG_EXTRA_BYTES
  shows as zero; on Linux and macOS (64-bit), this yields 8. On
  Linux (32-bit), this yields 4.

src/cmd/ksh93/sh/path.c: path_xargs():
- Do not try to calculate alignment, just add ARG_EXTRA_BYTES to
  each argument.
- Also add this when substracting the length of environment
  variables and leading and trailing static command arguments.

src/cmd/ksh93/tests/path.sh:
- Test command -v/-V with -x.
- Add a robust regression test for command -x.

src/cmd/ksh93/data/builtins.c, src/cmd/ksh93/sh.1:
- Tweak docs. Glob patterns also expand to multiple words.
2021-02-01 02:19:02 +00:00
Martijn Dekker
f37098f177 Build fix for Linux i386
iffe feature test that add a -D_LARGEFILE64_SOURCE compiler flag to
detect the presence of 64-bit types like off64_t are very
incorrect; they always find the type even if the rest of the source
is not compiled with that flag, causing an inconsistent compilation
environment. This was the cause of mysterious failures to compile
some feature tests on Linux i386 -- it tried to use an off64_t type
that was wrongly detected.

A flag like -D_LARGEFILE64_SOURCE needs to be added to the compiler
flags consistently so it is used for compiling all files and tests.

src/lib/libast/features/dirent,
src/lib/libast/features/fs,
src/lib/libast/features/lib,
src/lib/libast/features/mmap,
src/cmd/ksh93/features/rlimits:
- Remove the -D_LARGEFILE64_SOURCE flag from all the tests that
  used it.
- Fix some preprocessor directives for compiling without
  _LARGEFILE64_SOURCE. We cannot rely on the result of the _lib_*64
  tests because those functions are still found in glibc even if
  _LARGEFILE64_SOURCE is not defined; we have to check for the
  existence of the type definitions before using them.

src/cmd/INIT/cc.linux.i386,
src/cmd/INIT/cc.linux.i386-icc:
- Add/update compiler wrappers to hardcode -D_LARGEFILE64_SOURCE
  in the flags for the default compiler. If it is overriden with
  $CC, then it needs to be added manually if desired.
2021-01-31 23:47:43 +00:00
Martijn Dekker
a1f727749a tests/locale.sh: disable en_US.UTF-8 spaces test
This test depends on the correctness of the locale data provided
by the OS, and some installations are broken. Failures of this test
most likely do not represent a bug in ksh or libast.
2021-01-31 20:50:03 +00:00
Martijn Dekker
ede479967f resolve/remove USAGE_LICENSE macros; remove repetitive (c) strings
This takes another small step towards disentangling the build
system from the old AT&T environment. The USAGE_LICENSE macros with
author and copyright information, which was formerly generated
dynamically for each file from a database, are eliminated and the
copyright/author information is instead inserted into the AST
getopt usage strings directly.

Repetitive license/copyright information is also removed from the
getopt strings in the builtin commands (src/lib/libcmd/*.c and
src/cmd/ksh93/data/builtins.c). There's no need to include 55
identical license/copyright strings in the ksh binary; one (in the
main ksh getopt string, shown by ksh --man) ought to be enough!
This makes the ksh binary about 10k smaller.

It does mean that something like 'enum --author', 'typeset
--license' or 'shift --copyright' will now not show those notices
for those builtins, but I doubt anyone will care.
2021-01-31 11:00:49 +00:00
Martijn Dekker
66e1d44642 command -x: fix efficiency; always run external cmd (re: acf84e96)
This commit fixes 'command -x' to adapt to OS limitations with
regards to data alignment in the arguments list. A feature test is
added that detects if the OS aligns the argument on 32-bit or
64-bit boundaries or not at all, allowing 'command -x' to avoid
E2BIG errors while maximising efficiency.

Also, as of now, 'command -x' is a way to bypass built-ins and
run/query an external command. Built-ins do not limit the length of
their argument list, so '-x' never made sense to use for them. And
because '-x' hangs on Linux and macOS on every ksh93 release
version to date (see acf84e96), few use it, so there is little
reason not to make this change.

Finally, this fixes a longstanding bug that caused the minimum exit
status of 'command -x' to be 1 if a command with many arguments was
divided into several command invocations. This is done by replacing
broken flaggery with a new SH_XARG state flag bit.

src/cmd/ksh93/features/externs:
- Add new C feature test detecting byte alignment in args list.
  The test writes a #define ARG_ALIGN_BYTES with the amount of
  bytes the OS aligns arguments to, or zero for no alignment.

src/cmd/ksh93/include/defs.h:
- Add new SH_XARG state bit indicating 'command -x' is active.

src/cmd/ksh93/sh/path.c: path_xargs():
- Leave extra 2k in the args buffer instead of 1k, just to be sure;
  some commands add large environment variables these days.
- Fix a bug in subtracting the length of existing arguments and
  environment variables. 'size -= strlen(cp)-1;' subtracts one less
  than the size of cp, which makes no sense; what is necessary is
  to substract the length plus one to account for the terminating
  zero byte, i.e.: 'size -= strlen(cp)+1'.
- Use the ARG_ALIGN_BYTES feature test result to match the OS's
  data alignment requirements.
- path_spawn(): E2BIG: Change to checking SH_XARG state bit.

src/cmd/ksh93/bltins/whence.c: b_command():
- Allow combining -x with -p, -v and -V with the expected results
  by setting P_FLAG to act like 'whence -p'. E.g., as of now,
	command -xv printf
  is equivalent to
	whence -p printf
  but note that 'whence' has no equivalent of 'command -pvx printf'
  which searches $(getconf PATH) for a command.
- When -x will run a command, now set the new SH_XARG state flag.

src/cmd/ksh93/sh/xec.c: sh_exec():
- Change to using the new SH_XARG state bit.
- Skip the check for built-ins if SH_XARG is active, so that
  'command -x' now always runs an external command.

src/lib/libcmd/date.c, src/lib/libcmd/uname.c:
- These path-bound builtins sometimes need to run the external
  system command by the same name, but they did that by hardcoding
  an unportable direct path. Now that 'command -x' runs an external
  command, change this to using 'command -px' to guarantee using
  the known-good external system utility in the default PATH.
- In date.c, fix the format string passed to 'command -px date'
  when setting the date; it was only compatible with BSD systems.
  Use the POSIX variant on non-BSD systems.
2021-01-30 06:53:19 +00:00
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