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