← Commit list

6c38d0e9d

Denys Vlasenko
Denys Vlasenko
2024-07-13
SUCCESS Duration: 156s

Subject

hush: avoid duplicate fcntl(F_SETFD, FD_CLOEXEC) during init

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

shell/hush.c+3 -8
@@ -1575,7 +1575,7 @@ static int dup_CLOEXEC(int fd, int avoid_fd)
newfd = fcntl(fd, F_DUPFD_CLOEXEC, avoid_fd + 1);
if (newfd >= 0) {
if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */
- fcntl(newfd, F_SETFD, FD_CLOEXEC);
+ close_on_exec_on(newfd);
} else { /* newfd < 0 */
if (errno == EBUSY)
goto repeat;
@@ -1601,7 +1601,7 @@ static int xdup_CLOEXEC_and_close(int fd, int avoid_fd)
xfunc_die();
}
if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */
- fcntl(newfd, F_SETFD, FD_CLOEXEC);
+ close_on_exec_on(newfd);
close(fd);
return newfd;
}
@@ -10710,7 +10710,7 @@ int hush_main(int argc, char **argv)
G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, 254);
if (G_interactive_fd < 0) {
/* try to dup to any fd */
- G_interactive_fd = dup(STDIN_FILENO);
+ G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, -1);
if (G_interactive_fd < 0) {
/* give up */
G_interactive_fd = 0;
@@ -10720,8 +10720,6 @@ int hush_main(int argc, char **argv)
}
debug_printf("interactive_fd:%d\n", G_interactive_fd);
if (G_interactive_fd) {
- close_on_exec_on(G_interactive_fd);
-
if (G_saved_tty_pgrp) {
/* If we were run as 'hush &', sleep until we are
* in the foreground (tty pgrp == our pgrp).
@@ -10796,9 +10794,6 @@ int hush_main(int argc, char **argv)
G_interactive_fd = 0;
}
}
- if (G_interactive_fd) {
- close_on_exec_on(G_interactive_fd);
- }
install_special_sighandlers();
#else
/* We have interactiveness code disabled */