From b638376c2e48beaad279b2a3e0b2a1062e20bb47 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Thu, 23 Apr 2009 00:32:53 +1000 Subject: shell/ash: reimplement openhere() --- shell/ash_mingw.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'shell') 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) evaltreenr(n, flags); } +static void +openhere_fp(union node *redir, int flags) +{ + trace_printf("ash: subshell: %s\n",__PRETTY_FUNCTION__); + if (redir->type == NHERE) { + size_t len = strlen(redir->nhere.doc->narg.text); + full_write(1, redir->nhere.doc->narg.text, len); + } else + expandhere(redir->nhere.doc, 1); + _exit(0); +} + /* entry names should not be too long */ struct forkpoint forkpoints[] = { { "evalbackcmd", evalbackcmd_fp }, { "evalsubshell", evalsubshell_fp }, { "evalpipe", evalpipe_fp }, + { "openhere", openhere_fp }, { NULL, NULL }, }; @@ -1220,3 +1233,33 @@ evalpipe(union node *n, int flags) } INT_ON; } + +static int +openhere(union node *redir) +{ + struct forkshell fs; + + if (redir->type == NHERE) { + size_t len = strlen(redir->nhere.doc->narg.text); + if (len <= PIPESIZE) { + int pip[2]; + if (_pipe(pip, 0, 0) < 0) + ash_msg_and_raise_error("pipe call failed"); + full_write(pip[1], redir->nhere.doc->narg.text, len); + close(pip[1]); + return pip[0]; + } + } + memset(&fs, 0, sizeof(fs)); + fs.fp = "openhere"; + fs.flags = 0; + fs.n = redir; + fs.cmd.no_stdin = 1; + fs.cmd.out = -1; + forkshell_init(&fs); + if (start_command(&fs.cmd)) + ash_msg_and_raise_error("unable to spawn shell"); + forkshell_transfer(&fs); + forkshell_transfer_done(&fs); + return fs.cmd.out; +} -- cgit v1.2.3-55-g6feb