|
|
1a53a7 |
diff -up ksh-20120801/src/cmd/ksh93/include/io.h.macro ksh-20120801/src/cmd/ksh93/include/io.h
|
|
|
1a53a7 |
--- ksh-20120801/src/cmd/ksh93/include/io.h.macro 2012-07-18 16:12:38.000000000 +0200
|
|
|
1a53a7 |
+++ ksh-20120801/src/cmd/ksh93/include/io.h 2013-07-04 16:14:05.809595966 +0200
|
|
|
1a53a7 |
@@ -81,6 +81,7 @@ extern void sh_iosave(Shell_t *, int,in
|
|
|
1a53a7 |
extern int sh_iovalidfd(Shell_t*, int);
|
|
|
1a53a7 |
extern int sh_inuse(Shell_t*, int);
|
|
|
1a53a7 |
extern void sh_iounsave(Shell_t*);
|
|
|
1a53a7 |
+extern void iounpipe(Shell_t*);
|
|
|
1a53a7 |
extern int sh_chkopen(const char*);
|
|
|
1a53a7 |
extern int sh_ioaccess(int,int);
|
|
|
1a53a7 |
extern int sh_devtofd(const char*);
|
|
|
1a53a7 |
diff -up ksh-20120801/src/cmd/ksh93/sh/subshell.c.macro ksh-20120801/src/cmd/ksh93/sh/subshell.c
|
|
|
1a53a7 |
--- ksh-20120801/src/cmd/ksh93/sh/subshell.c.macro 2013-07-04 16:14:05.783595751 +0200
|
|
|
1a53a7 |
+++ ksh-20120801/src/cmd/ksh93/sh/subshell.c 2013-07-04 16:15:46.673432991 +0200
|
|
|
1a53a7 |
@@ -171,7 +171,7 @@ void sh_subfork(void)
|
|
|
1a53a7 |
{
|
|
|
1a53a7 |
register struct subshell *sp = subshell_data;
|
|
|
1a53a7 |
Shell_t *shp = sp->shp;
|
|
|
1a53a7 |
- int curenv = shp->curenv;
|
|
|
1a53a7 |
+ int curenv = shp->curenv, comsub=shp->comsub;
|
|
|
1a53a7 |
pid_t pid;
|
|
|
1a53a7 |
char *trap = shp->st.trapcom[0];
|
|
|
1a53a7 |
if(trap)
|
|
|
1a53a7 |
@@ -204,7 +204,7 @@ void sh_subfork(void)
|
|
|
1a53a7 |
shp->comsub = 0;
|
|
|
1a53a7 |
SH_SUBSHELLNOD->nvalue.s = 0;
|
|
|
1a53a7 |
sp->subpid=0;
|
|
|
1a53a7 |
- shp->st.trapcom[0] = trap;
|
|
|
1a53a7 |
+ shp->st.trapcom[0] = (comsub==2?NULL:trap);
|
|
|
1a53a7 |
shp->savesig = 0;
|
|
|
1a53a7 |
}
|
|
|
1a53a7 |
}
|
|
|
1a53a7 |
@@ -743,7 +743,6 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
|
|
|
1a53a7 |
fchdir(shp->pwdfd);
|
|
|
1a53a7 |
}
|
|
|
1a53a7 |
shp->subshare = sp->subshare;
|
|
|
1a53a7 |
- shp->comsub = sp->comsub;
|
|
|
1a53a7 |
shp->subdup = sp->subdup;
|
|
|
1a53a7 |
#if SHOPT_COSHELL
|
|
|
1a53a7 |
shp->coshell = sp->coshell;
|
|
|
1a53a7 |
@@ -773,7 +772,12 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
|
|
|
1a53a7 |
if(nsig>0)
|
|
|
1a53a7 |
kill(getpid(),nsig);
|
|
|
1a53a7 |
if(sp->subpid)
|
|
|
1a53a7 |
+ {
|
|
|
1a53a7 |
job_wait(sp->subpid);
|
|
|
1a53a7 |
+ if(comsub>1)
|
|
|
1a53a7 |
+ iounpipe(shp);
|
|
|
1a53a7 |
+ }
|
|
|
1a53a7 |
+ shp->comsub = sp->comsub;
|
|
|
1a53a7 |
if(comsub && iop && sp->pipefd<0)
|
|
|
1a53a7 |
sfseek(iop,(off_t)0,SEEK_SET);
|
|
|
1a53a7 |
if(shp->trapnote)
|
|
|
1a53a7 |
diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.macro ksh-20120801/src/cmd/ksh93/sh/xec.c
|
|
|
1a53a7 |
--- ksh-20120801/src/cmd/ksh93/sh/xec.c.macro 2013-07-04 16:14:05.800595891 +0200
|
|
|
1a53a7 |
+++ ksh-20120801/src/cmd/ksh93/sh/xec.c 2013-07-04 16:14:05.810595975 +0200
|
|
|
1a53a7 |
@@ -102,11 +102,11 @@ struct funenv
|
|
|
1a53a7 |
* temp file.
|
|
|
1a53a7 |
*/
|
|
|
1a53a7 |
static int subpipe[3],subdup,tsetio,usepipe;
|
|
|
1a53a7 |
-static void iounpipe(Shell_t*);
|
|
|
1a53a7 |
+void iounpipe(Shell_t*);
|
|
|
1a53a7 |
|
|
|
1a53a7 |
-static int iousepipe(Shell_t *shp)
|
|
|
1a53a7 |
+int iousepipe(Shell_t *shp)
|
|
|
1a53a7 |
{
|
|
|
1a53a7 |
- int i;
|
|
|
1a53a7 |
+ int fd=sffileno(sfstdout),i,err=errno;
|
|
|
1a53a7 |
if(usepipe)
|
|
|
1a53a7 |
{
|
|
|
1a53a7 |
usepipe++;
|
|
|
1a53a7 |
@@ -115,13 +115,18 @@ static int iousepipe(Shell_t *shp)
|
|
|
1a53a7 |
if(sh_rpipe(subpipe) < 0)
|
|
|
1a53a7 |
return(0);
|
|
|
1a53a7 |
usepipe++;
|
|
|
1a53a7 |
- fcntl(subpipe[0],F_SETFD,FD_CLOEXEC);
|
|
|
1a53a7 |
- subpipe[2] = sh_fcntl(1,F_DUPFD,10);
|
|
|
1a53a7 |
- fcntl(subpipe[2],F_SETFD,FD_CLOEXEC);
|
|
|
1a53a7 |
+ if(shp->comsub!=1)
|
|
|
1a53a7 |
+ {
|
|
|
1a53a7 |
+ subpipe[2] = sh_fcntl(subpipe[1],F_DUPFD,10);
|
|
|
1a53a7 |
+ sh_close(subpipe[1]);
|
|
|
1a53a7 |
+ return(1);
|
|
|
1a53a7 |
+ }
|
|
|
1a53a7 |
+ subpipe[2] = sh_fcntl(fd,F_dupfd_cloexec,10);
|
|
|
1a53a7 |
shp->fdstatus[subpipe[2]] = shp->fdstatus[1];
|
|
|
1a53a7 |
- close(1);
|
|
|
1a53a7 |
- fcntl(subpipe[1],F_DUPFD,1);
|
|
|
1a53a7 |
- shp->fdstatus[1] = shp->fdstatus[subpipe[1]];
|
|
|
1a53a7 |
+ while(close(fd)<0 && errno==EINTR)
|
|
|
1a53a7 |
+ errno = err;
|
|
|
1a53a7 |
+ fcntl(subpipe[1],F_DUPFD,fd);
|
|
|
1a53a7 |
+ shp->fdstatus[1] = shp->fdstatus[subpipe[1]]&~IOCLEX;
|
|
|
1a53a7 |
sh_close(subpipe[1]);
|
|
|
1a53a7 |
if(subdup=shp->subdup) for(i=0; i < 10; i++)
|
|
|
1a53a7 |
{
|
|
|
1a53a7 |
@@ -135,14 +140,23 @@ static int iousepipe(Shell_t *shp)
|
|
|
1a53a7 |
return(1);
|
|
|
1a53a7 |
}
|
|
|
1a53a7 |
|
|
|
1a53a7 |
-static void iounpipe(Shell_t *shp)
|
|
|
1a53a7 |
+void iounpipe(Shell_t *shp)
|
|
|
1a53a7 |
{
|
|
|
1a53a7 |
- int n;
|
|
|
1a53a7 |
+ int fd=sffileno(sfstdout),n,err=errno;
|
|
|
1a53a7 |
char buff[SF_BUFSIZE];
|
|
|
1a53a7 |
- close(1);
|
|
|
1a53a7 |
- fcntl(subpipe[2], F_DUPFD, 1);
|
|
|
1a53a7 |
- shp->fdstatus[1] = shp->fdstatus[subpipe[2]];
|
|
|
1a53a7 |
+ if(!usepipe)
|
|
|
1a53a7 |
+ return;
|
|
|
1a53a7 |
--usepipe;
|
|
|
1a53a7 |
+ if(shp->comsub>1)
|
|
|
1a53a7 |
+ {
|
|
|
1a53a7 |
+ sh_close(subpipe[2]);
|
|
|
1a53a7 |
+ while(read(subpipe[0],buff,sizeof(buff))>0);
|
|
|
1a53a7 |
+ goto done;
|
|
|
1a53a7 |
+ }
|
|
|
1a53a7 |
+ while(close(fd)<0 && errno==EINTR)
|
|
|
1a53a7 |
+ errno = err;
|
|
|
1a53a7 |
+ fcntl(subpipe[2], F_DUPFD, fd);
|
|
|
1a53a7 |
+ shp->fdstatus[1] = shp->fdstatus[subpipe[2]];
|
|
|
1a53a7 |
if(subdup) for(n=0; n < 10; n++)
|
|
|
1a53a7 |
{
|
|
|
1a53a7 |
if(subdup&(1<
|
|
|
1a53a7 |
@@ -174,6 +188,7 @@ static void iounpipe(Shell_t *shp)
|
|
|
1a53a7 |
else if(errno!=EINTR)
|
|
|
1a53a7 |
break;
|
|
|
1a53a7 |
}
|
|
|
1a53a7 |
+done:
|
|
|
1a53a7 |
sh_close(subpipe[0]);
|
|
|
1a53a7 |
subpipe[0] = -1;
|
|
|
1a53a7 |
tsetio = 0;
|
|
|
1a53a7 |
@@ -725,7 +740,7 @@ static void unset_instance(Namval_t *nq,
|
|
|
1a53a7 |
}
|
|
|
1a53a7 |
|
|
|
1a53a7 |
#if SHOPT_COSHELL
|
|
|
1a53a7 |
-uintmax_t coused;
|
|
|
1a53a7 |
+static uintmax_t coused;
|
|
|
1a53a7 |
/*
|
|
|
1a53a7 |
* print out function definition
|
|
|
1a53a7 |
*/
|
|
|
1a53a7 |
@@ -1619,10 +1634,14 @@ int sh_exec(register const Shnode_t *t,
|
|
|
1a53a7 |
if(shp->subshell)
|
|
|
1a53a7 |
{
|
|
|
1a53a7 |
sh_subtmpfile(shp);
|
|
|
1a53a7 |
- if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK))
|
|
|
1a53a7 |
- unpipe=iousepipe(shp);
|
|
|
1a53a7 |
if((type&(FAMP|TFORK))==(FAMP|TFORK))
|
|
|
1a53a7 |
- sh_subfork();
|
|
|
1a53a7 |
+ {
|
|
|
1a53a7 |
+ if(shp->comsub && !(shp->fdstatus[1]&IONOSEEK))
|
|
|
1a53a7 |
+ {
|
|
|
1a53a7 |
+ unpipe = iousepipe(shp);
|
|
|
1a53a7 |
+ sh_subfork();
|
|
|
1a53a7 |
+ }
|
|
|
1a53a7 |
+ }
|
|
|
1a53a7 |
}
|
|
|
1a53a7 |
no_fork = !ntflag && !(type&(FAMP|FPOU)) && !shp->subshell &&
|
|
|
1a53a7 |
!(shp->st.trapcom[SIGINT] && *shp->st.trapcom[SIGINT]) &&
|
|
|
1a53a7 |
@@ -3495,8 +3514,7 @@ static void sh_funct(Shell_t *shp,Namval
|
|
|
1a53a7 |
struct funenv fun;
|
|
|
1a53a7 |
char *fname = nv_getval(SH_FUNNAMENOD);
|
|
|
1a53a7 |
struct Level *lp =(struct Level*)(SH_LEVELNOD->nvfun);
|
|
|
1a53a7 |
- int level, pipepid=shp->pipepid, comsub=shp->comsub;
|
|
|
1a53a7 |
- shp->comsub = 0;
|
|
|
1a53a7 |
+ int level, pipepid=shp->pipepid;
|
|
|
1a53a7 |
shp->pipepid = 0;
|
|
|
1a53a7 |
sh_stats(STAT_FUNCT);
|
|
|
1a53a7 |
if(!lp->hdr.disc)
|
|
|
1a53a7 |
@@ -3539,7 +3557,6 @@ static void sh_funct(Shell_t *shp,Namval
|
|
|
1a53a7 |
lp->maxlevel = level;
|
|
|
1a53a7 |
SH_LEVELNOD->nvalue.s = lp->maxlevel;
|
|
|
1a53a7 |
shp->last_root = nv_dict(DOTSHNOD);
|
|
|
1a53a7 |
- shp->comsub = comsub;
|
|
|
1a53a7 |
#if 0
|
|
|
1a53a7 |
nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE);
|
|
|
1a53a7 |
#else
|