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

sh_parse(): don't turn on interactive state (re: 48ba6964)

Reproducer:

	$ (sleep 1& echo done)
	done
	$ (eval "echo hi"; sleep 1& echo done)
	hi
	[1]	30587
	done

No job control output should be printed for a background process
invoked from a subshell, not even after 'eval'.

The cause: sh_parse() turns on the shell's interactive state bit
(sh_state(SH_INTERACTIVE)) if the interactive shell option is on.

This is incorrect. The parser should have no involvement with shell
interactivity in principle because that's not its domain.

Not only that, the parser may need to run in a subshell, e.g. when
executing traps or 'eval' commands (as above). By definition, a
subshell can never be interactive.

We already fixed many bugs related to job control and the shell's
interactive state. Even if these two lines previously papered over
some breakage, I can't find any now after simply removing them. If
any is found later, then it'll need to be fixed properly instead.

Related: https://github.com/ksh93/ksh/issues/390
This commit is contained in:
Martijn Dekker 2021-12-22 03:10:11 +00:00
parent e6989853bc
commit 3525535e1f
3 changed files with 10 additions and 3 deletions

9
NEWS
View file

@ -3,6 +3,15 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs.
2021-12-21:
- Fixed a bug that caused subshells (such as code blocks in parentheses) to
partially behave like the interactive main shell after running anything
that invokes the parser. For example:
$ (eval :; sleep 1 & echo done)
[1] 30909 <--- incorrect job control output from subshell
done
2021-12-17:
- Release 1.0.0-beta.2.

View file

@ -21,7 +21,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2021-12-17" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2021-12-21" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -385,8 +385,6 @@ void *sh_parse(Shell_t *shp, Sfio_t *iop, int flag)
shp->nextprompt = 1;
loop_level = 0;
label_list = label_last = 0;
if(sh_isoption(SH_INTERACTIVE))
sh_onstate(SH_INTERACTIVE);
if(sh_isoption(SH_VERBOSE))
sh_onstate(SH_VERBOSE);
sh_lexopen(lexp,shp,0);