d679af8
diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.hokaido ksh-20120801/src/cmd/ksh93/sh/xec.c
d679af8
--- ksh-20120801/src/cmd/ksh93/sh/xec.c.hokaido	2014-09-18 14:41:57.696756230 +0200
d679af8
+++ ksh-20120801/src/cmd/ksh93/sh/xec.c	2014-09-18 14:43:55.439205247 +0200
d679af8
@@ -1633,12 +1633,20 @@ int sh_exec(register const Shnode_t *t,
ebf9b31
 #endif /* SHOPT_COSHELL */
ebf9b31
 			if(shp->subshell)
ebf9b31
 			{
ebf9b31
+				int comsubsave = shp->comsub;
ebf9b31
+				if(comsubsave==1)
ebf9b31
+					shp->comsub = 2;
ebf9b31
 				sh_subtmpfile(shp);
ebf9b31
+				shp->comsub = comsubsave;
d679af8
+				if(shp->comsub==1 && (!(shp->fdstatus[1]&IONOSEEK)))
ebf9b31
+					unpipe = iousepipe(shp);
ebf9b31
+
ebf9b31
 				if((type&(FAMP|TFORK))==(FAMP|TFORK))
ebf9b31
 				{
ebf9b31
 					if(shp->comsub && !(shp->fdstatus[1]&IONOSEEK))
ebf9b31
 					{
ebf9b31
-						unpipe = iousepipe(shp);
ebf9b31
+						if (!unpipe)
ebf9b31
+							unpipe = iousepipe(shp);
ebf9b31
 						sh_subfork();
ebf9b31
 					}
ebf9b31
 				}
d679af8
@@ -2107,7 +2115,11 @@ int sh_exec(register const Shnode_t *t,
d679af8
 			job.curjobid = 0;
d679af8
 			if(shp->subshell)
d679af8
 			{
d679af8
+				int comsubsave = shp->comsub;
d679af8
+				if(comsubsave==1)
d679af8
+					shp->comsub = 2;
d679af8
 				sh_subtmpfile(shp);
d679af8
+				shp->comsub = comsubsave;
d679af8
 				if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK))
d679af8
 					iousepipe(shp);
d679af8
 			}