aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 00:32:07 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 04:44:48 +1000
commit25803d323fe5b577cb7ad259ab1c107e694af7ce (patch)
treeaee9c9c81dbfb875f7083a184be35d66ca038273
parentba7cf21b047b493600e41c885c87d176b1af2ef5 (diff)
downloadbusybox-w32-25803d323fe5b577cb7ad259ab1c107e694af7ce.tar.gz
busybox-w32-25803d323fe5b577cb7ad259ab1c107e694af7ce.tar.bz2
busybox-w32-25803d323fe5b577cb7ad259ab1c107e694af7ce.zip
shell/ash: reimplement evalpipe()
-rw-r--r--shell/ash_mingw.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/shell/ash_mingw.c b/shell/ash_mingw.c
index d343b2885..431ae6ebb 100644
--- a/shell/ash_mingw.c
+++ b/shell/ash_mingw.c
@@ -814,10 +814,20 @@ evalsubshell_fp(union node *n, int flags)
814 redirect(n->nredir.redirect, 0); 814 redirect(n->nredir.redirect, 0);
815 evaltreenr(n->nredir.n, flags); 815 evaltreenr(n->nredir.n, flags);
816} 816}
817
818static void
819evalpipe_fp(union node *n,int flags)
820{
821 trace_printf("ash: subshell: %s\n",__PRETTY_FUNCTION__);
822 INT_ON;
823 evaltreenr(n, flags);
824}
825
817/* entry names should not be too long */ 826/* entry names should not be too long */
818struct forkpoint forkpoints[] = { 827struct forkpoint forkpoints[] = {
819 { "evalbackcmd", evalbackcmd_fp }, 828 { "evalbackcmd", evalbackcmd_fp },
820 { "evalsubshell", evalsubshell_fp }, 829 { "evalsubshell", evalsubshell_fp },
830 { "evalpipe", evalpipe_fp },
821 { NULL, NULL }, 831 { NULL, NULL },
822}; 832};
823 833
@@ -1158,3 +1168,55 @@ updatepwd(const char *dir)
1158 *new = 0; 1168 *new = 0;
1159 return stackblock(); 1169 return stackblock();
1160} 1170}
1171
1172static void
1173evalpipe(union node *n, int flags)
1174{
1175 struct forkshell fs;
1176 struct nodelist *lp;
1177 int pipelen;
1178 int prevfd;
1179 int pip[2];
1180
1181 TRACE(("evalpipe(0x%lx) called\n", (long)n));
1182 pipelen = 0;
1183 for (lp = n->npipe.cmdlist; lp; lp = lp->next)
1184 pipelen++;
1185 flags |= EV_EXIT;
1186 INT_OFF;
1187 prevfd = -1;
1188 for (lp = n->npipe.cmdlist; lp; lp = lp->next) {
1189 prehash(lp->n);
1190 pip[1] = -1;
1191 if (lp->next) {
1192 if (_pipe(pip, 0, O_NOINHERIT) < 0) {
1193 close(prevfd);
1194 ash_msg_and_raise_error("pipe call failed");
1195 }
1196 }
1197 if (prevfd != -1)
1198 forkshell_cleanup(&fs);
1199 memset(&fs, 0, sizeof(fs));
1200 fs.fp = "evalpipe";
1201 fs.flags = flags;
1202 fs.n = lp->n;
1203 if (prevfd > 0)
1204 fs.cmd.in = prevfd;
1205 if (pip[1] > 1)
1206 fs.cmd.out = pip[1];
1207 forkshell_init(&fs);
1208 if (start_command(&fs.cmd))
1209 ash_msg_and_raise_error("unable to spawn shell");
1210 forkshell_transfer(&fs);
1211 forkshell_transfer_done(&fs);
1212 if (prevfd >= 0)
1213 close(prevfd);
1214 prevfd = pip[0];
1215 if (pip[1] >= 0)
1216 close(pip[1]);
1217 }
1218 if (n->npipe.backgnd == 0) {
1219 set_exitstatus(finish_command(&fs.cmd), fs.cmd.argv, NULL); /* the last command in pipe */
1220 }
1221 INT_ON;
1222}