[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 3/6] util/async-teardown: Fall back to close fds one by one
From: |
Bin Meng |
Subject: |
[PATCH v3 3/6] util/async-teardown: Fall back to close fds one by one |
Date: |
Sat, 17 Jun 2023 13:36:18 +0800 |
When opening /proc/self/fd fails, current codes just return directly,
but we can fall back to close fds one by one.
Signed-off-by: Bin Meng <bmeng@tinylab.org>
---
(no changes since v2)
Changes in v2:
- new patch: "util/async-teardown: Fall back to close fds one by one"
util/async-teardown.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/util/async-teardown.c b/util/async-teardown.c
index 3ab19c8740..7e0177a8da 100644
--- a/util/async-teardown.c
+++ b/util/async-teardown.c
@@ -48,7 +48,11 @@ static void close_all_open_fd(void)
dir = opendir("/proc/self/fd");
if (!dir) {
- /* If /proc is not mounted, there is nothing that can be done. */
+ /* If /proc is not mounted, close fds one by one. */
+ int open_max = sysconf(_SC_OPEN_MAX), i;
+ for (i = 0; i < open_max; i++) {
+ close(i);
+ }
return;
}
/* Avoid closing the directory. */
--
2.34.1
- [PATCH v3 0/6] net/tap: Fix QEMU frozen issue when the maximum number of file descriptors is very large, Bin Meng, 2023/06/17
- [PATCH v3 1/6] tests/tcg/cris: Fix the coding style, Bin Meng, 2023/06/17
- [PATCH v3 2/6] tests/tcg/cris: Correct the off-by-one error, Bin Meng, 2023/06/17
- [PATCH v3 6/6] net: tap: Use qemu_close_range() to close fds, Bin Meng, 2023/06/17
- [PATCH v3 3/6] util/async-teardown: Fall back to close fds one by one,
Bin Meng <=
- [PATCH v3 4/6] util/osdep: Introduce qemu_close_range(), Bin Meng, 2023/06/17
- [PATCH v3 5/6] util/async-teardown: Use qemu_close_range() to close fds, Bin Meng, 2023/06/17
- Re: [PATCH v3 0/6] net/tap: Fix QEMU frozen issue when the maximum number of file descriptors is very large, Richard Henderson, 2023/06/19