diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 00:32:53 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 04:44:48 +1000 |
commit | b638376c2e48beaad279b2a3e0b2a1062e20bb47 (patch) | |
tree | ca2d2be02c50769e0157f74f73d8de9f98552a2e | |
parent | 25803d323fe5b577cb7ad259ab1c107e694af7ce (diff) | |
download | busybox-w32-b638376c2e48beaad279b2a3e0b2a1062e20bb47.tar.gz busybox-w32-b638376c2e48beaad279b2a3e0b2a1062e20bb47.tar.bz2 busybox-w32-b638376c2e48beaad279b2a3e0b2a1062e20bb47.zip |
shell/ash: reimplement openhere()
-rw-r--r-- | shell/ash_mingw.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/shell/ash_mingw.c b/shell/ash_mingw.c index 431ae6ebb..57679e7ee 100644 --- a/shell/ash_mingw.c +++ b/shell/ash_mingw.c | |||
@@ -823,11 +823,24 @@ evalpipe_fp(union node *n,int flags) | |||
823 | evaltreenr(n, flags); | 823 | evaltreenr(n, flags); |
824 | } | 824 | } |
825 | 825 | ||
826 | static void | ||
827 | openhere_fp(union node *redir, int flags) | ||
828 | { | ||
829 | trace_printf("ash: subshell: %s\n",__PRETTY_FUNCTION__); | ||
830 | if (redir->type == NHERE) { | ||
831 | size_t len = strlen(redir->nhere.doc->narg.text); | ||
832 | full_write(1, redir->nhere.doc->narg.text, len); | ||
833 | } else | ||
834 | expandhere(redir->nhere.doc, 1); | ||
835 | _exit(0); | ||
836 | } | ||
837 | |||
826 | /* entry names should not be too long */ | 838 | /* entry names should not be too long */ |
827 | struct forkpoint forkpoints[] = { | 839 | struct forkpoint forkpoints[] = { |
828 | { "evalbackcmd", evalbackcmd_fp }, | 840 | { "evalbackcmd", evalbackcmd_fp }, |
829 | { "evalsubshell", evalsubshell_fp }, | 841 | { "evalsubshell", evalsubshell_fp }, |
830 | { "evalpipe", evalpipe_fp }, | 842 | { "evalpipe", evalpipe_fp }, |
843 | { "openhere", openhere_fp }, | ||
831 | { NULL, NULL }, | 844 | { NULL, NULL }, |
832 | }; | 845 | }; |
833 | 846 | ||
@@ -1220,3 +1233,33 @@ evalpipe(union node *n, int flags) | |||
1220 | } | 1233 | } |
1221 | INT_ON; | 1234 | INT_ON; |
1222 | } | 1235 | } |
1236 | |||
1237 | static int | ||
1238 | openhere(union node *redir) | ||
1239 | { | ||
1240 | struct forkshell fs; | ||
1241 | |||
1242 | if (redir->type == NHERE) { | ||
1243 | size_t len = strlen(redir->nhere.doc->narg.text); | ||
1244 | if (len <= PIPESIZE) { | ||
1245 | int pip[2]; | ||
1246 | if (_pipe(pip, 0, 0) < 0) | ||
1247 | ash_msg_and_raise_error("pipe call failed"); | ||
1248 | full_write(pip[1], redir->nhere.doc->narg.text, len); | ||
1249 | close(pip[1]); | ||
1250 | return pip[0]; | ||
1251 | } | ||
1252 | } | ||
1253 | memset(&fs, 0, sizeof(fs)); | ||
1254 | fs.fp = "openhere"; | ||
1255 | fs.flags = 0; | ||
1256 | fs.n = redir; | ||
1257 | fs.cmd.no_stdin = 1; | ||
1258 | fs.cmd.out = -1; | ||
1259 | forkshell_init(&fs); | ||
1260 | if (start_command(&fs.cmd)) | ||
1261 | ash_msg_and_raise_error("unable to spawn shell"); | ||
1262 | forkshell_transfer(&fs); | ||
1263 | forkshell_transfer_done(&fs); | ||
1264 | return fs.cmd.out; | ||
1265 | } | ||