From 3525535e1f67d883694ade5e5831a0f549395f29 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 22 Dec 2021 03:10:11 +0000 Subject: [PATCH] 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 --- NEWS | 9 +++++++++ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh/parse.c | 2 -- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 0ec3d6910..02c5cbd7c 100644 --- a/NEWS +++ b/NEWS @@ -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. diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 815ed0ac5..83838dcdd 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -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. */ diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index fe9a3f4c1..b37cf68d2 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -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);