aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorClément Léger <cleger@rivosinc.com>2024-08-02 16:54:17 +0200
committerRichard Henderson <richard.henderson@linaro.org>2024-08-05 08:06:08 +1000
commit4ec5ebea078ed3a16d6c7e612ff9c2e04ea73931 (patch)
treebb2880d8145b917eaaf7effc2df8ab2379feadc1 /system
parent5b0c2742c839376b7e03c4654914aaec6a8a7b09 (diff)
downloadqemu-4ec5ebea078ed3a16d6c7e612ff9c2e04ea73931.zip
qemu-4ec5ebea078ed3a16d6c7e612ff9c2e04ea73931.tar.gz
qemu-4ec5ebea078ed3a16d6c7e612ff9c2e04ea73931.tar.bz2
qemu/osdep: Move close_all_open_fds() to oslib-posix
Move close_all_open_fds() in oslib-posix, rename it qemu_close_all_open_fds() and export it. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20240802145423.3232974-2-cleger@rivosinc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'system')
-rw-r--r--system/async-teardown.c37
1 files changed, 1 insertions, 36 deletions
diff --git a/system/async-teardown.c b/system/async-teardown.c
index 396963c..edf49e1 100644
--- a/system/async-teardown.c
+++ b/system/async-teardown.c
@@ -26,40 +26,6 @@
static pid_t the_ppid;
-/*
- * Close all open file descriptors.
- */
-static void close_all_open_fd(void)
-{
- struct dirent *de;
- int fd, dfd;
- DIR *dir;
-
-#ifdef CONFIG_CLOSE_RANGE
- int r = close_range(0, ~0U, 0);
- if (!r) {
- /* Success, no need to try other ways. */
- return;
- }
-#endif
-
- dir = opendir("/proc/self/fd");
- if (!dir) {
- /* If /proc is not mounted, there is nothing that can be done. */
- return;
- }
- /* Avoid closing the directory. */
- dfd = dirfd(dir);
-
- for (de = readdir(dir); de; de = readdir(dir)) {
- fd = atoi(de->d_name);
- if (fd != dfd) {
- close(fd);
- }
- }
- closedir(dir);
-}
-
static void hup_handler(int signal)
{
/* Check every second if this process has been reparented. */
@@ -85,9 +51,8 @@ static int async_teardown_fn(void *arg)
/*
* Close all file descriptors that might have been inherited from the
* main qemu process when doing clone, needed to make libvirt happy.
- * Not using close_range for increased compatibility with older kernels.
*/
- close_all_open_fd();
+ qemu_close_all_open_fd();
/* Set up a handler for SIGHUP and unblock SIGHUP. */
sigaction(SIGHUP, &sa, NULL);