[PATCH 4/4] vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs

Michal Privoznik posted 4 patches 2 months, 3 weeks ago
[PATCH 4/4] vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs
Posted by Michal Privoznik 2 months, 3 weeks ago
On BSD-like systems "/dev/fd" serves the same purpose as
"/proc/self/fd". And since procfs is usually not mounted, on such
systems we can use "/dev/fd" instead.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/518
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/vircommand.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index e48f361114..d48bf8122d 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -511,6 +511,8 @@ virCommandMassCloseGetFDs(virBitmap *fds)
      * onto child process (well, the one we will exec soon since this
      * is called from the child). */
     return virCommandMassCloseGetFDsDir(fds, "/proc/self/fd");
+# elif defined(__APPLE__) || defined(__FreeBSD__)
+    return virCommandMassCloseGetFDsDir(fds, "/dev/fd");
 # else
     virBitmapSetAll(fds);
     return 0;
-- 
2.44.2
Re: [PATCH 4/4] vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs
Posted by Martin Kletzander 2 months, 1 week ago
On Wed, Aug 28, 2024 at 02:16:17PM +0200, Michal Privoznik wrote:
>On BSD-like systems "/dev/fd" serves the same purpose as
>"/proc/self/fd". And since procfs is usually not mounted, on such
>systems we can use "/dev/fd" instead.
>
>Resolves: https://gitlab.com/libvirt/libvirt/-/issues/518
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/util/vircommand.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/src/util/vircommand.c b/src/util/vircommand.c
>index e48f361114..d48bf8122d 100644
>--- a/src/util/vircommand.c
>+++ b/src/util/vircommand.c
>@@ -511,6 +511,8 @@ virCommandMassCloseGetFDs(virBitmap *fds)
>      * onto child process (well, the one we will exec soon since this
>      * is called from the child). */
>     return virCommandMassCloseGetFDsDir(fds, "/proc/self/fd");
>+# elif defined(__APPLE__) || defined(__FreeBSD__)
>+    return virCommandMassCloseGetFDsDir(fds, "/dev/fd");

And in this patch the similar condition should be used for
virCommandMassCloseGetFDsDir() to avoid unneeded G_GNUC_UNUSED.

With that fixed:

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>


> # else
>     virBitmapSetAll(fds);
>     return 0;
>-- 
>2.44.2
>