diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-07-13 00:14:41 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-07-13 00:14:41 +0200 |
commit | 6c38d0e9da2d4a3defd2bff9f3e00f6229e9824b (patch) | |
tree | 69fa4d8060cc76c0c9cc5a6cbf725bfde752b0cc | |
parent | 08fb86726b508eb99502a6681da94395c4e4580c (diff) | |
download | busybox-w32-6c38d0e9da2d4a3defd2bff9f3e00f6229e9824b.tar.gz busybox-w32-6c38d0e9da2d4a3defd2bff9f3e00f6229e9824b.tar.bz2 busybox-w32-6c38d0e9da2d4a3defd2bff9f3e00f6229e9824b.zip |
hush: avoid duplicate fcntl(F_SETFD, FD_CLOEXEC) during init
function old new delta
hush_main 1149 1150 +1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/shell/hush.c b/shell/hush.c index 3e6a13b32..afbc3ebec 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1575,7 +1575,7 @@ static int dup_CLOEXEC(int fd, int avoid_fd) | |||
1575 | newfd = fcntl(fd, F_DUPFD_CLOEXEC, avoid_fd + 1); | 1575 | newfd = fcntl(fd, F_DUPFD_CLOEXEC, avoid_fd + 1); |
1576 | if (newfd >= 0) { | 1576 | if (newfd >= 0) { |
1577 | if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */ | 1577 | if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */ |
1578 | fcntl(newfd, F_SETFD, FD_CLOEXEC); | 1578 | close_on_exec_on(newfd); |
1579 | } else { /* newfd < 0 */ | 1579 | } else { /* newfd < 0 */ |
1580 | if (errno == EBUSY) | 1580 | if (errno == EBUSY) |
1581 | goto repeat; | 1581 | goto repeat; |
@@ -1601,7 +1601,7 @@ static int xdup_CLOEXEC_and_close(int fd, int avoid_fd) | |||
1601 | xfunc_die(); | 1601 | xfunc_die(); |
1602 | } | 1602 | } |
1603 | if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */ | 1603 | if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */ |
1604 | fcntl(newfd, F_SETFD, FD_CLOEXEC); | 1604 | close_on_exec_on(newfd); |
1605 | close(fd); | 1605 | close(fd); |
1606 | return newfd; | 1606 | return newfd; |
1607 | } | 1607 | } |
@@ -10710,7 +10710,7 @@ int hush_main(int argc, char **argv) | |||
10710 | G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, 254); | 10710 | G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, 254); |
10711 | if (G_interactive_fd < 0) { | 10711 | if (G_interactive_fd < 0) { |
10712 | /* try to dup to any fd */ | 10712 | /* try to dup to any fd */ |
10713 | G_interactive_fd = dup(STDIN_FILENO); | 10713 | G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, -1); |
10714 | if (G_interactive_fd < 0) { | 10714 | if (G_interactive_fd < 0) { |
10715 | /* give up */ | 10715 | /* give up */ |
10716 | G_interactive_fd = 0; | 10716 | G_interactive_fd = 0; |
@@ -10720,8 +10720,6 @@ int hush_main(int argc, char **argv) | |||
10720 | } | 10720 | } |
10721 | debug_printf("interactive_fd:%d\n", G_interactive_fd); | 10721 | debug_printf("interactive_fd:%d\n", G_interactive_fd); |
10722 | if (G_interactive_fd) { | 10722 | if (G_interactive_fd) { |
10723 | close_on_exec_on(G_interactive_fd); | ||
10724 | |||
10725 | if (G_saved_tty_pgrp) { | 10723 | if (G_saved_tty_pgrp) { |
10726 | /* If we were run as 'hush &', sleep until we are | 10724 | /* If we were run as 'hush &', sleep until we are |
10727 | * in the foreground (tty pgrp == our pgrp). | 10725 | * in the foreground (tty pgrp == our pgrp). |
@@ -10796,9 +10794,6 @@ int hush_main(int argc, char **argv) | |||
10796 | G_interactive_fd = 0; | 10794 | G_interactive_fd = 0; |
10797 | } | 10795 | } |
10798 | } | 10796 | } |
10799 | if (G_interactive_fd) { | ||
10800 | close_on_exec_on(G_interactive_fd); | ||
10801 | } | ||
10802 | install_special_sighandlers(); | 10797 | install_special_sighandlers(); |
10803 | #else | 10798 | #else |
10804 | /* We have interactiveness code disabled */ | 10799 | /* We have interactiveness code disabled */ |