1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Make 'redirect' a regular builtin instead of an alias of 'exec'

This commit converts the redirect='command exec' alias to a regular
'redirect' builtin command that only accepts I/O redirections, which
persist as in 'exec'. This means that:
* 'unlias -a' no longer removes the 'redirect' command;
* users no longer accidentally get logged out of their shells if
  they type something intuitive but wrong, like 'redirect ls >file'.

This should not introduce any legitimate change in behaviour. If
someone did accidentally pass non-redirection arguments to
'redirect', unexpected behaviour would occur; this now produces
an 'incorrect syntax' error.

src/cmd/ksh93/bltins/misc.c: b_exec():
- Recognise 'redirect' when parsing options.
- If invoked as 'redirect', produce error if there are arguments.

src/cmd/ksh93/data/aliases.c:
- Remove redirect='command exec' alias.

src/cmd/ksh93/data/builtins.c:
- Update/improve comments re ordering.
- Add 'redirect' builtin entry.
- sh_optexec[]: Abbreviate redirection-related documentation;
  refer to redirect(1) instead.
- sh_optredirect[]: Add documentation.

src/cmd/ksh93/include/builtins.h:
- Add SYSREDIR parser ID, renumbering those following it.
- Improve comments.
- Add extern sh_optredirect[].

src/cmd/ksh93/sh.1:
- exec: Abbreviate redirection-related documentation; refer to
  'redirect' instead.
- redirect: Add documentation.

src/cmd/ksh93/sh/xec.c:
- Recognise SYSREDIR parser ID in addition to SYSEXEC when
  determining whether to make redirections persistent.

src/cmd/ksh93/tests/io.sh:
- To regress-test the new builtin, change most 'command exec' uses
  to 'redirect'.
- Add tests verifying the exit behaviour of 'exec', 'command exec',
  'redirect' on redirections.
This commit is contained in:
Martijn Dekker 2020-06-12 04:17:14 +02:00
parent 936802f92a
commit 7b82c338da
9 changed files with 134 additions and 75 deletions

8
TODO
View file

@ -20,14 +20,6 @@ Fix build system:
______
Fix or remove broken or misguided default aliases:
- Make a proper builtin out of the redirect='command exec' alias. It should
really only parse redirections. Currently, if an unwitting user notices this
alias and tries out something like 'redirect ls >file', it does 'exec ls
>file', so 'ls' replaces their shell and they get logged out. That is so
misdesigned I'm calling it a bug.
Alternatively, maybe just get rid? Who uses this anyway? 'redirect >&2'
takes four more keystrokes to type than 'exec >&2'.
- Make proper builtins out of the following scripting-related aliases, so
that 'unalias -a' does not eliminate them. If done correctly, this causes
no other change in behaviour. It would be good practice to 'unalias -a' in