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

Fix bugs related to --posix shell option (re: 921bbcae, f45a0f16)

This fixes the following:
1. 'set --posix' now works as an equivalent of 'set -o posix'.
2. The posix option turns off braceexpand and turns on letoctal.
   Any attempt to override that in a single command such as 'set -o
   posix +o letoctal' was quietly ignored. This now works as long
   as the overriding option follows the posix option in the command.
3. The --default option to 'set' now stops the 'posix' option, if
   set or unset in the same 'set' command, from changing other
   options. This allows the command output by 'set +o' to correctly
   restore the current options.

src/cmd/ksh93/data/builtins.c:
- To make 'set --posix' work, we must explicitly list it in
  sh_set[] as a supported option so that AST optget(3) recognises
  it and won't override it with its own default --posix option,
  which converts the optget(3) string to at POSIX getopt(3) string.
    This means it will appear as a separate entry in --man output,
  whether we want it to or not. So we might as well use it as an
  example to document how --optionname == -o optionname, replacing
  the original documentation that was part of the '-o' description.

src/cmd/ksh93/sh/args.c: sh_argopts():
- Add handling for explitit --posix option in data/builtins.c.
- Move SH_POSIX syncing SH_BRACEEXPAND and SH_LETOCTAL from
  sh_applyopts() into the option parsing loop here. This fixes
  the bug that letoctal was ignored in 'set -o posix +o letoctal'.
- Remember if --default was used in a flag, and do not sync options
  with SH_POSIX if the flag is set. This makes 'set +o' work.

src/cmd/ksh93/include/argnod.h,
src/cmd/ksh93/data/msg.c,
src/cmd/ksh93/sh/args.c: sh_printopts():
- Do not potentially translate the 'on' and 'off' labels in 'set
  -o' output. No other shell does, and some scripts parse these.

src/cmd/ksh93/sh/init.c: sh_init():
- Turn on SH_LETOCTAL early along with SH_POSIX if the shell was
  invoked as sh; this makes 'sh -o' and 'sh +o' show expected
  options (not that anyone does this, but correctness is good).

src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/include/shell.h:
- The state flags were in defs.h and most (but not all) of the
  shell options were in shell.h. Gather all the shell state and
  option flag definitions into one place in shell.h for clarity.
- Remove unused SH_NOPROFILE and SH_XARGS option flags.

src/cmd/ksh93/tests/options.sh:
- Add tests for these bugs.

src/lib/libast/misc/optget.c: styles[]:
- Edit default optget(3) option self-documentation for clarity.

Several changed files:
- Some SHOPT_PFSH fixes to avoid compiling dead code.
This commit is contained in:
Martijn Dekker 2021-02-14 23:51:19 +00:00
parent cd1cd9c5da
commit af5f7acf99
15 changed files with 123 additions and 83 deletions

View file

@ -196,14 +196,12 @@ const char sh_set[] =
"control.]"
"[n?The shell reads commands and checks for syntax errors, but does "
"not execute the command. Usually specified on command invocation.]"
"[o]:?[option?If \aoption\a is not specified, the list of options and "
"their current settings will be written to standard output. When "
"invoked with a \b+\b the options will be written in a format "
"that can be reinput to the shell to restore the settings. "
"Options \b-o\b \aname\a can also be specified with \b--\b\aname\a "
"and \b+o \aname\a can be specified with \b--no\b\aname\a except that "
"options names beginning with \bno\b are turned on by omitting \bno\b."
"This option can be repeated to enable/disable multiple options. "
"[o]:?[option?A \b-o\b with no \aoption\a will write the list of options and "
"their current settings to standard output. "
"A \b+o\b with no \aoption\a writes a command that the shell can run "
"to restore the current options state. "
"\b-o\b \aoption\a turns on \aoption\a and \b+o\b \aoption\a turns it "
"off. This can be repeated to enable/disable multiple options. "
"The value of \aoption\a must be one of the following:]{"
"[+allexport?Equivalent to \b-a\b.]"
"[+bgnice?Runs background jobs at lower priorities.]"
@ -258,6 +256,15 @@ const char sh_set[] =
#endif
"[+xtrace?Equivalent to \b-x\b.]"
"}"
/*
* --posix is an AST optget(3) default option, so for ksh to use it, it must be listed
* explicitly (and handled by sh_argopts() in sh/args.c) to stop optget(3) overriding it.
* Since it must appear here, use it as an example to document how --option == -o option.
*/
"[05:posix?For any \b-o\b option (such as \bposix\b), \b--posix\b is equivalent "
"to \b-o posix\b and \b--noposix\b is equivalent to \b+o posix\b. "
"However, option names with a \bno\b prefix "
"are turned on by omitting \bno\b.]"
"[p?Privileged mode. Disabling \b-p\b sets the effective user id to the "
"real user id, and the effective group id to the real group id. "
"Enabling \b-p\b restores the effective user and group ids to their "