diff --git a/src/cmd/ksh93/include/shell.h b/src/cmd/ksh93/include/shell.h index a1084698f..5a6336f93 100644 --- a/src/cmd/ksh93/include/shell.h +++ b/src/cmd/ksh93/include/shell.h @@ -329,7 +329,6 @@ struct Shell_s char redir0; /* redirect of 0 */ char intrace; /* set when trace expands PS4 */ char *readscript; /* set before reading a script */ - int subdup; /* bitmask for dups of 1 */ int *inpipe; /* input pipe pointer */ int *outpipe; /* output pipe pointer */ int cpipe[3]; diff --git a/src/cmd/ksh93/sh/args.c b/src/cmd/ksh93/sh/args.c index 18c76efe6..faee9c45d 100644 --- a/src/cmd/ksh93/sh/args.c +++ b/src/cmd/ksh93/sh/args.c @@ -721,7 +721,7 @@ struct argnod *sh_argprocsub(struct argnod *argp) ap->argflag |= ARG_MAKE; ap->argflag &= ~ARG_RAW; fd = argp->argflag&ARG_RAW; - if(fd==0 && sh.subshell) + if(fd==0 && sh.comsub) sh_subtmpfile(); #if SHOPT_DEVFD sfwrite(sh.stk,e_devfdNN,8); diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index 602195bf6..0668026b9 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -1173,7 +1173,7 @@ int sh_redirect(struct ionod *iop, int flag) memset(ap, 0, ARGVAL); if(iof&IOPUT) ap->argflag = ARG_RAW; - else if(sh.subshell) + else if(sh.comsub) sh_subtmpfile(); ap->argchn.ap = (struct argnod*)fname; ap = sh_argprocsub(ap); @@ -1241,16 +1241,12 @@ int sh_redirect(struct ionod *iop, int flag) } if(sh.subshell && dupfd==1) { - if(sfset(sfstdout,0,0)&SF_STRING) + if(sh.comsub) sh_subtmpfile(); - if(sh.comsub==1) - sh.subdup |= 1<options = sh.options; sp->jobs = job_subsave(); - sp->subdup = sh.subdup; - sh.subdup = 0; /* make sure initialization has occurred */ if(!sh.pathlist) { @@ -872,7 +869,6 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) sh.exitval |= SH_EXITSIG; } sh.subshare = sp->subshare; - sh.subdup = sp->subdup; sh.subshell--; /* decrease level of virtual subshells */ sh.realsubshell--; /* decrease ${.sh.subshell} */ subshell_data = sp->prev; @@ -898,11 +894,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) if(nsig>0) kill(sh.current_pid,nsig); if(sp->subpid) - { job_wait(sp->subpid); - if(comsub) - sh_iounpipe(); - } sh.comsub = sp->comsub; if(comsub && iop && sp->pipefd<0) sfseek(iop,(off_t)0,SEEK_SET); diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index a344fe05b..70e0dba7d 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -166,43 +166,6 @@ static inline double timeval_to_double(struct timeval tv) } #endif -/* - * The following two functions allow command substitution for non-builtins - * to use a pipe and to wait for the pipe to close before restoring to a - * temp file. - */ -static int subpipe[3],subdup,tsetio,usepipe; - -static int iousepipe(void) -{ - if(usepipe) - { - usepipe++; - sh_iounpipe(); - } - if(sh_rpipe(subpipe) < 0) - return(0); - usepipe++; - subpipe[2] = sh_fcntl(subpipe[1],F_DUPFD,10); - sh_close(subpipe[1]); - return(1); -} - -void sh_iounpipe(void) -{ - char buff[SF_BUFSIZE]; - if(!usepipe) - return; - --usepipe; - sh_close(subpipe[2]); - while(read(subpipe[0],buff,sizeof(buff))>0) - ; - sh_close(subpipe[0]); - subpipe[0] = -1; - tsetio = 0; - usepipe = 0; -} - /* * print time in h:m:s format with precision

*/ @@ -1282,7 +1245,7 @@ int sh_exec(register const Shnode_t *t, int flags) bp->sigset = 0; bp->notify = 0; bp->flags = (OPTIMIZE!=0); - if(sh.subshell && nv_isattr(np,BLT_NOSFIO)) + if(sh.comsub && nv_isattr(np,BLT_NOSFIO)) sh_subtmpfile(); if(argn) sh.exitval = (*sh.bltinfun)(argn,com,(void*)bp); @@ -1482,7 +1445,7 @@ int sh_exec(register const Shnode_t *t, int flags) register pid_t parent; int no_fork,jobid; int pipes[3]; - if(sh.subshell) + if(sh.comsub) sh_subtmpfile(); if(no_fork = check_exec_optimization(type,execflg,execflg2,t->fork.forkio)) job.parent=parent=0; @@ -1860,7 +1823,7 @@ int sh_exec(register const Shnode_t *t, int flags) echeck = 1; job.exitval = 0; job.curjobid = 0; - if(sh.subshell) + if(sh.comsub) sh_subtmpfile(); sh.inpipe = pvo; sh.outpipe = pvn; @@ -2938,7 +2901,6 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid) if(sig>0) kill(sh.current_pid,sig); sh_sigcheck(); - usepipe=0; return(0); } diff --git a/src/cmd/ksh93/tests/basic.sh b/src/cmd/ksh93/tests/basic.sh index 59449651d..b00bdf6c1 100755 --- a/src/cmd/ksh93/tests/basic.sh +++ b/src/cmd/ksh93/tests/basic.sh @@ -413,13 +413,13 @@ unset foo unset foo foo=$(false) > /dev/null && err_exit 'failed command substitution with redirection not returning false' expected=foreback -got=`print -n fore; (sleep 2;print back)&` +got=`print -n fore; (sleep .01; print back)&` [[ $got == $expected ]] || err_exit "\`\` command substitution background process output error (expected '$expected', got '$got')" -got=$(print -n fore; (sleep .2;print back)&) +got=$(print -n fore; (sleep .01; print back)&) [[ $got == $expected ]] || err_exit "\$() command substitution background process output error (expected '$expected', got '$got')" -got=${ print -n fore; (sleep 2;print back)& } +got=${ print -n fore; (sleep .01; print back)& } [[ $got == $expected ]] || err_exit "\${} shared-state command substitution background process output error (expected '$expected', got '$got')" -function abc { sleep 2; print back; } +function abc { sleep .01; print back; } function abcd { abc & } got=$(print -n fore;abcd) [[ $got == $expected ]] || err_exit "\$() command substitution background with function process output error (expected '$expected', got '$got')" diff --git a/src/cmd/ksh93/tests/heredoc.sh b/src/cmd/ksh93/tests/heredoc.sh index e60280d2b..ebab1cd4b 100755 --- a/src/cmd/ksh93/tests/heredoc.sh +++ b/src/cmd/ksh93/tests/heredoc.sh @@ -121,11 +121,15 @@ $0 $SHELL -c 'x=$( cat << EOF EOF)' 2> /dev/null || err_exit 'here-doc cannot be terminated by )' -if [[ $( IFS=:;cat <<-! + +got=$( IFS=:; cat <<-! $IFS$(print hi)$IFS - !) != :hi: ]] -then err_exit '$IFS unset by command substitution in here docs' -fi + ! +) +exp=:hi: +[[ $got == "$exp" ]] || err_exit '$IFS unset by command substitution in here docs' \ + "(expected $(printf %q "$exp"), got $(printf %q "$got"))" + if x=$($SHELL -c 'cat <<< "hello world"' 2> /dev/null) then [[ $x == 'hello world' ]] || err_exit '<<< documents not working' x=$($SHELL -c 'v="hello world";cat <<< $v' 2> /dev/null)