From 48ba6964ada0d8041c20f1d5173ede4cffd8b1db Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 2 Oct 2020 08:07:28 +0200 Subject: [PATCH] Turn off SH_INTERACTIVE state flag in subshells By definition, subshells are never interactive, so they should disable behaviour associated with interactive shells even if the main shell is interactive. Most visibly, running a background job from a subshell like ( some_command & ) now no longer prints a job ID that you cannot use in the main shell. This behaviour change matches pdksh/mksh, bash, zsh, dash, et al. Prior discussion: https://www.mail-archive.com/austin-group-l@opengroup.org/msg06456.html (plus the preceding thread) src/cmd/ksh93/sh/subshell.c: sh_subshell(): - Before running the command(s) in the subshell using sh_exec(), turn off the SH_INTERACTIVE shell state flag. (No need to add code to restore it as this function already saves and restores the entire shell state.) src/cmd/ksh93/bltins/misc.c: b_bg(): - If there is no job control when using 'bg', 'fg' or 'disown', always print the "no job control" error message and not only if the shell is in the interactive state. This is also what pdksh/mksh, bash and zsh do. --- src/cmd/ksh93/bltins/misc.c | 3 +-- src/cmd/ksh93/sh/subshell.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/ksh93/bltins/misc.c b/src/cmd/ksh93/bltins/misc.c index 0f86a1831..9d299d9a3 100644 --- a/src/cmd/ksh93/bltins/misc.c +++ b/src/cmd/ksh93/bltins/misc.c @@ -418,8 +418,7 @@ int b_bg(register int n,register char *argv[],Shbltin_t *context) argv += opt_info.index; if(!sh_isoption(SH_MONITOR) || !job.jobcontrol) { - if(sh_isstate(SH_INTERACTIVE)) - errormsg(SH_DICT,ERROR_exit(1),e_no_jctl); + errormsg(SH_DICT,ERROR_exit(1),e_no_jctl); return(1); } if(flag=='d' && *argv==0) diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index 51bc5aa16..0de8fe914 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -633,6 +633,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub) if(shp->savesig < 0) { shp->savesig = 0; + sh_offstate(SH_INTERACTIVE); sh_exec(t,flags); } }