diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-30 16:51:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-31 04:05:51 +0200 |
commit | d07a15bd1ba99caa9386234cda1e8c83897c7553 (patch) | |
tree | aa2b930b5a2c313567fbab72427e3517624be764 | |
parent | 5f0a75f24b5afdedf5b67a7f42184ed196e1a5c9 (diff) | |
download | busybox-w32-d07a15bd1ba99caa9386234cda1e8c83897c7553.tar.gz busybox-w32-d07a15bd1ba99caa9386234cda1e8c83897c7553.tar.bz2 busybox-w32-d07a15bd1ba99caa9386234cda1e8c83897c7553.zip |
ash: remove REDIR_SAVEFD2
function old new delta
evalcommand 1364 1369 +5
redirect 1055 1014 -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-41) Total: -36 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/shell/ash.c b/shell/ash.c index 52fcc7944..1e720aec4 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2030,7 +2030,7 @@ struct redirtab; | |||
2030 | struct globals_var { | 2030 | struct globals_var { |
2031 | struct shparam shellparam; /* $@ current positional parameters */ | 2031 | struct shparam shellparam; /* $@ current positional parameters */ |
2032 | struct redirtab *redirlist; | 2032 | struct redirtab *redirlist; |
2033 | int preverrout_fd; /* save fd2 before print debug if xflag is set. */ | 2033 | int preverrout_fd; /* stderr fd: usually 2, unless redirect moved it */ |
2034 | struct var *vartab[VTABSIZE]; | 2034 | struct var *vartab[VTABSIZE]; |
2035 | struct var varinit[ARRAY_SIZE(varinit_data)]; | 2035 | struct var varinit[ARRAY_SIZE(varinit_data)]; |
2036 | }; | 2036 | }; |
@@ -5426,16 +5426,13 @@ is_hidden_fd(struct redirtab *rp, int fd) | |||
5426 | */ | 5426 | */ |
5427 | /* flags passed to redirect */ | 5427 | /* flags passed to redirect */ |
5428 | #define REDIR_PUSH 01 /* save previous values of file descriptors */ | 5428 | #define REDIR_PUSH 01 /* save previous values of file descriptors */ |
5429 | #define REDIR_SAVEFD2 03 /* set preverrout */ | ||
5430 | static void | 5429 | static void |
5431 | redirect(union node *redir, int flags) | 5430 | redirect(union node *redir, int flags) |
5432 | { | 5431 | { |
5433 | struct redirtab *sv; | 5432 | struct redirtab *sv; |
5434 | int sv_pos; | 5433 | int sv_pos; |
5435 | int i; | ||
5436 | int fd; | 5434 | int fd; |
5437 | int newfd; | 5435 | int newfd; |
5438 | int copied_fd2 = -1; | ||
5439 | 5436 | ||
5440 | if (!redir) | 5437 | if (!redir) |
5441 | return; | 5438 | return; |
@@ -5479,37 +5476,38 @@ redirect(union node *redir, int flags) | |||
5479 | * to the same fd as right side fd in N>&M */ | 5476 | * to the same fd as right side fd in N>&M */ |
5480 | int minfd = right_fd < 10 ? 10 : right_fd + 1; | 5477 | int minfd = right_fd < 10 ? 10 : right_fd + 1; |
5481 | #if defined(F_DUPFD_CLOEXEC) | 5478 | #if defined(F_DUPFD_CLOEXEC) |
5482 | i = fcntl(fd, F_DUPFD_CLOEXEC, minfd); | 5479 | int copy = fcntl(fd, F_DUPFD_CLOEXEC, minfd); |
5483 | #else | 5480 | #else |
5484 | i = fcntl(fd, F_DUPFD, minfd); | 5481 | int copy = fcntl(fd, F_DUPFD, minfd); |
5485 | #endif | 5482 | #endif |
5486 | if (i == -1) { | 5483 | if (copy == -1) { |
5487 | i = errno; | 5484 | int e = errno; |
5488 | if (i != EBADF) { | 5485 | if (e != EBADF) { |
5489 | /* Strange error (e.g. "too many files" EMFILE?) */ | 5486 | /* Strange error (e.g. "too many files" EMFILE?) */ |
5490 | if (newfd >= 0) | 5487 | if (newfd >= 0) |
5491 | close(newfd); | 5488 | close(newfd); |
5492 | errno = i; | 5489 | errno = e; |
5493 | ash_msg_and_raise_perror("%d", fd); | 5490 | ash_msg_and_raise_perror("%d", fd); |
5494 | /* NOTREACHED */ | 5491 | /* NOTREACHED */ |
5495 | } | 5492 | } |
5496 | /* EBADF: it is not open - good, remember to close it */ | 5493 | /* EBADF: it is not open - good, remember to close it */ |
5497 | remember_to_close: | 5494 | remember_to_close: |
5498 | i = CLOSED; | 5495 | copy = CLOSED; |
5499 | } else { /* fd is open, save its copy */ | 5496 | } else { /* fd is open, save its copy */ |
5500 | #if !defined(F_DUPFD_CLOEXEC) | 5497 | #if !defined(F_DUPFD_CLOEXEC) |
5501 | fcntl(i, F_SETFD, FD_CLOEXEC); | 5498 | fcntl(copy, F_SETFD, FD_CLOEXEC); |
5502 | #endif | 5499 | #endif |
5503 | /* "exec fd>&-" should not close fds | 5500 | /* "exec fd>&-" should not close fds |
5504 | * which point to script file(s). | 5501 | * which point to script file(s). |
5505 | * Force them to be restored afterwards */ | 5502 | * Force them to be restored afterwards */ |
5506 | if (is_hidden_fd(sv, fd)) | 5503 | if (is_hidden_fd(sv, fd)) |
5507 | i |= COPYFD_RESTORE; | 5504 | copy |= COPYFD_RESTORE; |
5508 | } | 5505 | } |
5509 | if (fd == 2) | 5506 | /* if we move stderr, let "set -x" code know */ |
5510 | copied_fd2 = i; | 5507 | if (fd == preverrout_fd) |
5508 | preverrout_fd = copy; | ||
5511 | sv->two_fd[sv_pos].orig = fd; | 5509 | sv->two_fd[sv_pos].orig = fd; |
5512 | sv->two_fd[sv_pos].copy = i; | 5510 | sv->two_fd[sv_pos].copy = copy; |
5513 | sv_pos++; | 5511 | sv_pos++; |
5514 | } | 5512 | } |
5515 | if (newfd < 0) { | 5513 | if (newfd < 0) { |
@@ -5537,10 +5535,16 @@ redirect(union node *redir, int flags) | |||
5537 | } | 5535 | } |
5538 | #endif | 5536 | #endif |
5539 | } while ((redir = redir->nfile.next) != NULL); | 5537 | } while ((redir = redir->nfile.next) != NULL); |
5540 | |||
5541 | INT_ON; | 5538 | INT_ON; |
5542 | if ((flags & REDIR_SAVEFD2) && copied_fd2 >= 0) | 5539 | |
5543 | preverrout_fd = copied_fd2; | 5540 | //dash:#define REDIR_SAVEFD2 03 /* set preverrout */ |
5541 | #define REDIR_SAVEFD2 0 | ||
5542 | // dash has a bug: since REDIR_SAVEFD2=3 and REDIR_PUSH=1, this test | ||
5543 | // triggers for pure REDIR_PUSH too. Thus, this is done almost always, | ||
5544 | // not only for calls with flags containing REDIR_SAVEFD2. | ||
5545 | // We do this unconditionally (see code above). | ||
5546 | //if ((flags & REDIR_SAVEFD2) && copied_fd2 >= 0) | ||
5547 | // preverrout_fd = copied_fd2; | ||
5544 | } | 5548 | } |
5545 | 5549 | ||
5546 | static int | 5550 | static int |
@@ -9655,9 +9659,7 @@ evalcommand(union node *cmd, int flags) | |||
9655 | int spclbltin; | 9659 | int spclbltin; |
9656 | int status; | 9660 | int status; |
9657 | char **nargv; | 9661 | char **nargv; |
9658 | struct builtincmd *bcmd; | ||
9659 | smallint cmd_is_exec; | 9662 | smallint cmd_is_exec; |
9660 | smallint pseudovarflag = 0; | ||
9661 | 9663 | ||
9662 | /* First expand the arguments. */ | 9664 | /* First expand the arguments. */ |
9663 | TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); | 9665 | TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); |
@@ -9674,21 +9676,24 @@ evalcommand(union node *cmd, int flags) | |||
9674 | 9676 | ||
9675 | argc = 0; | 9677 | argc = 0; |
9676 | if (cmd->ncmd.args) { | 9678 | if (cmd->ncmd.args) { |
9679 | struct builtincmd *bcmd; | ||
9680 | smallint pseudovarflag; | ||
9681 | |||
9677 | bcmd = find_builtin(cmd->ncmd.args->narg.text); | 9682 | bcmd = find_builtin(cmd->ncmd.args->narg.text); |
9678 | pseudovarflag = bcmd && IS_BUILTIN_ASSIGN(bcmd); | 9683 | pseudovarflag = bcmd && IS_BUILTIN_ASSIGN(bcmd); |
9679 | } | ||
9680 | 9684 | ||
9681 | for (argp = cmd->ncmd.args; argp; argp = argp->narg.next) { | 9685 | for (argp = cmd->ncmd.args; argp; argp = argp->narg.next) { |
9682 | struct strlist **spp; | 9686 | struct strlist **spp; |
9683 | 9687 | ||
9684 | spp = arglist.lastp; | 9688 | spp = arglist.lastp; |
9685 | if (pseudovarflag && isassignment(argp->narg.text)) | 9689 | if (pseudovarflag && isassignment(argp->narg.text)) |
9686 | expandarg(argp, &arglist, EXP_VARTILDE); | 9690 | expandarg(argp, &arglist, EXP_VARTILDE); |
9687 | else | 9691 | else |
9688 | expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); | 9692 | expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); |
9689 | 9693 | ||
9690 | for (sp = *spp; sp; sp = sp->next) | 9694 | for (sp = *spp; sp; sp = sp->next) |
9691 | argc++; | 9695 | argc++; |
9696 | } | ||
9692 | } | 9697 | } |
9693 | 9698 | ||
9694 | /* Reserve one extra spot at the front for shellexec. */ | 9699 | /* Reserve one extra spot at the front for shellexec. */ |
@@ -9704,9 +9709,9 @@ evalcommand(union node *cmd, int flags) | |||
9704 | if (iflag && funcnest == 0 && argc > 0) | 9709 | if (iflag && funcnest == 0 && argc > 0) |
9705 | lastarg = nargv[-1]; | 9710 | lastarg = nargv[-1]; |
9706 | 9711 | ||
9707 | preverrout_fd = 2; | ||
9708 | expredir(cmd->ncmd.redirect); | 9712 | expredir(cmd->ncmd.redirect); |
9709 | redir_stop = pushredir(cmd->ncmd.redirect); | 9713 | redir_stop = pushredir(cmd->ncmd.redirect); |
9714 | preverrout_fd = 2; | ||
9710 | status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2); | 9715 | status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2); |
9711 | 9716 | ||
9712 | path = vpath.var_text; | 9717 | path = vpath.var_text; |