[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 6/6] net/tap: Use qemu_close_all_open_fd()
|
From: |
Richard Henderson |
|
Subject: |
[PULL 6/6] net/tap: Use qemu_close_all_open_fd() |
|
Date: |
Mon, 5 Aug 2024 10:31:29 +1000 |
From: Clément Léger <cleger@rivosinc.com>
Instead of using a slow implementation to close all open fd after
forking, use qemu_close_all_open_fd().
Signed-off-by: Clément Léger <cleger@rivosinc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20240802145423.3232974-6-cleger@rivosinc.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
net/tap.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index 7b2d5d5703..3f90022c0b 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -387,13 +387,20 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
static void close_all_fds_after_fork(int excluded_fd)
{
- int open_max = sysconf(_SC_OPEN_MAX), i;
+ const int skip_fd[] = {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO,
+ excluded_fd};
+ unsigned int nskip = ARRAY_SIZE(skip_fd);
- for (i = 3; i < open_max; i++) {
- if (i != excluded_fd) {
- close(i);
- }
+ /*
+ * skip_fd must be an ordered array of distinct fds, exclude
+ * excluded_fd if already included in the [STDIN_FILENO - STDERR_FILENO]
+ * range
+ */
+ if (excluded_fd <= STDERR_FILENO) {
+ nskip--;
}
+
+ qemu_close_all_open_fd(skip_fd, nskip);
}
static void launch_script(const char *setup_script, const char *ifname,
--
2.43.0
- [PULL 0/6] misc patch queue, Richard Henderson, 2024/08/04
- [PULL 1/6] linux-user/elfload: Fix pr_pid values in core files, Richard Henderson, 2024/08/04
- [PATCH for-9.1] target/i386: Fix VSIB decode, Richard Henderson, 2024/08/04
- [PULL 2/6] qemu/osdep: Move close_all_open_fds() to oslib-posix, Richard Henderson, 2024/08/04
- [PULL 3/6] qemu/osdep: Split qemu_close_all_open_fd() and add fallback, Richard Henderson, 2024/08/04
- [PULL 4/6] net/tap: Factorize fd closing after forking, Richard Henderson, 2024/08/04
- [PULL 5/6] qemu/osdep: Add excluded fd parameter to qemu_close_all_open_fd(), Richard Henderson, 2024/08/04
- [PULL 6/6] net/tap: Use qemu_close_all_open_fd(),
Richard Henderson <=
- Re: [PULL 0/6] misc patch queue, Richard Henderson, 2024/08/05