diff mbox series

[1/2] qemu/osdep: fix current process fds path for other OSes

Message ID 20240830111451.3799490-2-cleger@rivosinc.com (mailing list archive)
State New
Headers show
Series oslib: fix OSes support for qemu_close_all_open_fd() | expand

Commit Message

Clément Léger Aug. 30, 2024, 11:14 a.m. UTC
While Linux and Solaris uses /proc/self/fd, other OSes (MacOS,
FreeBSD) uses /dev/fd. In order to support theses OSes, use /dev/fd as
a fallback.

Fixes: 4ec5ebea078e ("qemu/osdep: Move close_all_open_fds() to oslib-posix")
Reported-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Clément Léger <cleger@rivosinc.com>
---
 util/oslib-posix.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Daniel P. Berrangé Aug. 30, 2024, 11:16 a.m. UTC | #1
On Fri, Aug 30, 2024 at 01:14:49PM +0200, Clément Léger wrote:
> While Linux and Solaris uses /proc/self/fd, other OSes (MacOS,
> FreeBSD) uses /dev/fd. In order to support theses OSes, use /dev/fd as
> a fallback.
> 
> Fixes: 4ec5ebea078e ("qemu/osdep: Move close_all_open_fds() to oslib-posix")
> Reported-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> ---
>  util/oslib-posix.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
Michael Tokarev Aug. 30, 2024, 11:31 a.m. UTC | #2
30.08.2024 14:14, Clément Léger:
> While Linux and Solaris uses /proc/self/fd, other OSes (MacOS,
> FreeBSD) uses /dev/fd. In order to support theses OSes, use /dev/fd as
> a fallback.
> 
> Fixes: 4ec5ebea078e ("qemu/osdep: Move close_all_open_fds() to oslib-posix")
> Reported-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Clément Léger <cleger@rivosinc.com>

Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>

/mjt
diff mbox series

Patch

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 11b35e48fb..901dcccd73 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -814,8 +814,13 @@  static bool qemu_close_all_open_fd_proc(const int *skip, unsigned int nskip)
     int fd, dfd;
     DIR *dir;
     unsigned int skip_start = 0, skip_end = nskip;
+#if defined(CONFIG_LINUX) || defined(CONFIG_SOLARIS)
+    const char *self_fd = "/proc/self/fd";
+#else
+    const char *self_fd = "/dev/fd";
+#endif
 
-    dir = opendir("/proc/self/fd");
+    dir = opendir(self_fd);
     if (!dir) {
         /* If /proc is not mounted, there is nothing that can be done. */
         return false;