From 51c840935d442d0fc2aaddb956a010af6841ebb1 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Thu, 23 Apr 2009 00:28:44 +1000 Subject: shell/ash: reimplement evalbackcmd() and backquote --- shell/ash.c | 23 +++++++++++++++++++++++ shell/ash_mingw.c | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 7c97e72e2..2d2368bc8 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -5384,7 +5384,11 @@ evalbackcmd(union node *n, struct backcmd *result) result->fd = -1; result->buf = NULL; result->nleft = 0; +#ifdef __MINGW32__ + memset(&result->fs, 0, sizeof(result->fs)); +#else result->jp = NULL; +#endif if (n == NULL) { goto out; } @@ -5393,6 +5397,19 @@ evalbackcmd(union node *n, struct backcmd *result) herefd = -1; { +#ifdef __MINGW32__ + result->fs.fp = "evalbackcmd"; + result->fs.n = n; + result->fs.flags = EV_EXIT; + result->fs.cmd.no_stdin = 1; + result->fs.cmd.out = -1; + forkshell_init(&result->fs); + if (start_command(&result->fs.cmd)) + ash_msg_and_raise_error("unable to spawn shell"); + forkshell_transfer(&result->fs); + forkshell_transfer_done(&result->fs); + result->fd = result->fs.cmd.out; +#else int pip[2]; struct job *jp; @@ -5414,6 +5431,7 @@ evalbackcmd(union node *n, struct backcmd *result) close(pip[1]); result->fd = pip[0]; result->jp = jp; +#endif } herefd = saveherefd; out: @@ -5462,10 +5480,15 @@ expbackq(union node *cmd, int quoted, int quotes) if (in.buf) free(in.buf); +#ifdef __MINGW32__ + set_exitstatus(finish_command(&in.fs.cmd), in.fs.cmd.argv, &back_exitstatus); + forkshell_cleanup(&in.fs); +#else if (in.fd >= 0) { close(in.fd); back_exitstatus = waitforjob(in.jp); } +#endif INT_ON; /* Eat all trailing newlines */ diff --git a/shell/ash_mingw.c b/shell/ash_mingw.c index 42a9e41a7..7cf9c8213 100644 --- a/shell/ash_mingw.c +++ b/shell/ash_mingw.c @@ -788,8 +788,25 @@ struct forkpoint { void (*func)(union node *,int); }; +static void +evalbackcmd_fp(union node *n, int flags) +{ + trace_printf("ash: subshell: %s\n",__PRETTY_FUNCTION__); + FORCE_INT_ON; + /* + close(pip[0]); + if (pip[1] != 1) { + close(1); + copyfd(pip[1], 1); + close(pip[1]); + } + */ + eflag = 0; + evaltree(n, EV_EXIT); /* actually evaltreenr... */ +} /* entry names should not be too long */ struct forkpoint forkpoints[] = { + { "evalbackcmd", evalbackcmd_fp }, { NULL, NULL }, }; -- cgit v1.2.3-55-g6feb