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