diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 00:28:44 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-23 04:44:47 +1000 |
commit | 51c840935d442d0fc2aaddb956a010af6841ebb1 (patch) | |
tree | 50fb6404a803ee34f573ec8c2bbb9cffca7f1c6d /shell | |
parent | 4b6faf7807ca7fb77ec07b474aac4fa6edf6bfff (diff) | |
download | busybox-w32-51c840935d442d0fc2aaddb956a010af6841ebb1.tar.gz busybox-w32-51c840935d442d0fc2aaddb956a010af6841ebb1.tar.bz2 busybox-w32-51c840935d442d0fc2aaddb956a010af6841ebb1.zip |
shell/ash: reimplement evalbackcmd() and backquote
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 23 | ||||
-rw-r--r-- | shell/ash_mingw.c | 17 |
2 files changed, 40 insertions, 0 deletions
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) | |||
5384 | result->fd = -1; | 5384 | result->fd = -1; |
5385 | result->buf = NULL; | 5385 | result->buf = NULL; |
5386 | result->nleft = 0; | 5386 | result->nleft = 0; |
5387 | #ifdef __MINGW32__ | ||
5388 | memset(&result->fs, 0, sizeof(result->fs)); | ||
5389 | #else | ||
5387 | result->jp = NULL; | 5390 | result->jp = NULL; |
5391 | #endif | ||
5388 | if (n == NULL) { | 5392 | if (n == NULL) { |
5389 | goto out; | 5393 | goto out; |
5390 | } | 5394 | } |
@@ -5393,6 +5397,19 @@ evalbackcmd(union node *n, struct backcmd *result) | |||
5393 | herefd = -1; | 5397 | herefd = -1; |
5394 | 5398 | ||
5395 | { | 5399 | { |
5400 | #ifdef __MINGW32__ | ||
5401 | result->fs.fp = "evalbackcmd"; | ||
5402 | result->fs.n = n; | ||
5403 | result->fs.flags = EV_EXIT; | ||
5404 | result->fs.cmd.no_stdin = 1; | ||
5405 | result->fs.cmd.out = -1; | ||
5406 | forkshell_init(&result->fs); | ||
5407 | if (start_command(&result->fs.cmd)) | ||
5408 | ash_msg_and_raise_error("unable to spawn shell"); | ||
5409 | forkshell_transfer(&result->fs); | ||
5410 | forkshell_transfer_done(&result->fs); | ||
5411 | result->fd = result->fs.cmd.out; | ||
5412 | #else | ||
5396 | int pip[2]; | 5413 | int pip[2]; |
5397 | struct job *jp; | 5414 | struct job *jp; |
5398 | 5415 | ||
@@ -5414,6 +5431,7 @@ evalbackcmd(union node *n, struct backcmd *result) | |||
5414 | close(pip[1]); | 5431 | close(pip[1]); |
5415 | result->fd = pip[0]; | 5432 | result->fd = pip[0]; |
5416 | result->jp = jp; | 5433 | result->jp = jp; |
5434 | #endif | ||
5417 | } | 5435 | } |
5418 | herefd = saveherefd; | 5436 | herefd = saveherefd; |
5419 | out: | 5437 | out: |
@@ -5462,10 +5480,15 @@ expbackq(union node *cmd, int quoted, int quotes) | |||
5462 | 5480 | ||
5463 | if (in.buf) | 5481 | if (in.buf) |
5464 | free(in.buf); | 5482 | free(in.buf); |
5483 | #ifdef __MINGW32__ | ||
5484 | set_exitstatus(finish_command(&in.fs.cmd), in.fs.cmd.argv, &back_exitstatus); | ||
5485 | forkshell_cleanup(&in.fs); | ||
5486 | #else | ||
5465 | if (in.fd >= 0) { | 5487 | if (in.fd >= 0) { |
5466 | close(in.fd); | 5488 | close(in.fd); |
5467 | back_exitstatus = waitforjob(in.jp); | 5489 | back_exitstatus = waitforjob(in.jp); |
5468 | } | 5490 | } |
5491 | #endif | ||
5469 | INT_ON; | 5492 | INT_ON; |
5470 | 5493 | ||
5471 | /* Eat all trailing newlines */ | 5494 | /* 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 { | |||
788 | void (*func)(union node *,int); | 788 | void (*func)(union node *,int); |
789 | }; | 789 | }; |
790 | 790 | ||
791 | static void | ||
792 | evalbackcmd_fp(union node *n, int flags) | ||
793 | { | ||
794 | trace_printf("ash: subshell: %s\n",__PRETTY_FUNCTION__); | ||
795 | FORCE_INT_ON; | ||
796 | /* | ||
797 | close(pip[0]); | ||
798 | if (pip[1] != 1) { | ||
799 | close(1); | ||
800 | copyfd(pip[1], 1); | ||
801 | close(pip[1]); | ||
802 | } | ||
803 | */ | ||
804 | eflag = 0; | ||
805 | evaltree(n, EV_EXIT); /* actually evaltreenr... */ | ||
806 | } | ||
791 | /* entry names should not be too long */ | 807 | /* entry names should not be too long */ |
792 | struct forkpoint forkpoints[] = { | 808 | struct forkpoint forkpoints[] = { |
809 | { "evalbackcmd", evalbackcmd_fp }, | ||
793 | { NULL, NULL }, | 810 | { NULL, NULL }, |
794 | }; | 811 | }; |
795 | 812 | ||