--- src/cmd/ksh93/sh/io.c +++ src/cmd/ksh93/sh/io.c 2011-05-03 15:15:18.283926707 +0200 @@ -403,6 +403,7 @@ shp->sftable[2] = sfstderr; sfnotify(sftrack); sh_iostream(shp,0); + sh_iostream(shp,1); /* all write steams are in the same pool and share outbuff */ shp->outpool = sfopen(NIL(Sfio_t*),NIL(char*),"sw"); /* pool identifier */ shp->outbuff = (char*)malloc(IOBSIZE+4); @@ -608,7 +609,8 @@ } if(sp) shp->sftable[f1] = 0; - sh_close(f1); + if(shp->fdstatus[f1]!=IOCLOSE) + sh_close(f1); } return(f2); } @@ -1022,6 +1024,8 @@ memset(ap, 0, ARGVAL); if(iof&IOPUT) ap->argflag = ARG_RAW; + else if(shp->subshell) + sh_subtmpfile(shp); ap->argchn.ap = (struct argnod*)fname; ap = sh_argprocsub(shp,ap); fname = ap->argval; @@ -2148,13 +2152,18 @@ static ssize_t subread(Sfio_t* sp,void* buff,register size_t size,Sfdisc_t* handle) { register struct subfile *disp = (struct subfile*)handle; + ssize_t n; NOT_USED(sp); + sfseek(disp->oldsp,disp->offset,SEEK_SET); if(disp->left == 0) return(0); if(size > disp->left) size = disp->left; disp->left -= size; - return(sfread(disp->oldsp,buff,size)); + n = sfread(disp->oldsp,buff,size); + if(size>0) + disp->offset += size; + return(n); } /* --- src/cmd/ksh93/sh/subshell.c +++ src/cmd/ksh93/sh/subshell.c 2011-04-29 15:34:13.747926082 +0200 @@ -235,7 +235,7 @@ if(!sp->shpwd || np==SH_LEVELNOD || np==L_ARGNOD || np==SH_SUBSCRNOD || np==SH_NAMENOD) return(np); /* don't bother to save if in newer scope */ - if(sp->var!=shp->var_tree && sp->var!=shp->var_base && shp->last_root==shp->var_tree) + if(sp->var!=shp->var_tree && shp->last_root==shp->var_tree) return(np); if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np))) { --- src/cmd/ksh93/sh/xec.c +++ src/cmd/ksh93/sh/xec.c 2011-05-03 15:02:23.411926136 +0200 @@ -53,6 +53,7 @@ #define SH_NTFORK SH_TIMING #define NV_BLTPFSH NV_ARRAY +#define HERE_MEM 0x1000 #if _lib_nice extern int nice(int); @@ -2606,6 +2607,7 @@ pid_t sh_fork(int flags, int *jobid) { + Sfio_t* aux_heredocs = NIL(Sfio_t*); register pid_t parent; register int sig; #if SHOPT_FASTPIPE @@ -2625,7 +2627,23 @@ sh.trapnote &= ~SH_SIGTERM; job_fork(-1); sh.savesig = -1; + if (sh.heredocs) + { + aux_heredocs = sftmp(HERE_MEM); + if (aux_heredocs) + { + sfseek(sh.heredocs,(off_t)0,SEEK_SET); + sfmove(sh.heredocs,aux_heredocs,(Sfoff_t)(-1),-1); + sfsync(aux_heredocs); + } + } while(_sh_fork(parent=fork(),flags,jobid) < 0); + if (aux_heredocs) + { + if (!parent) + sfswap(aux_heredocs,sh.heredocs); + sfclose(aux_heredocs); + } sh_stats(STAT_FORKS); sig = sh.savesig; sh.savesig = 0;