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