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

Clément Léger posted 2 patches 2 months, 3 weeks ago
[PATCH 1/2] qemu/osdep: fix current process fds path for other OSes
Posted by Clément Léger 2 months, 3 weeks ago
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(-)

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;
-- 
2.45.2


Re: [PATCH 1/2] qemu/osdep: fix current process fds path for other OSes
Posted by Michael Tokarev 2 months, 3 weeks ago
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

Re: [PATCH 1/2] qemu/osdep: fix current process fds path for other OSes
Posted by Daniel P. Berrangé 2 months, 3 weeks ago
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
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|