]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 29 Aug 2023 06:49:27 +0000 (08:49 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 13 Sep 2024 12:50:43 +0000 (14:50 +0200)
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>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/util/vircommand.c

index ea52acfbb8876ef51f5eea6207f282493e37b1c8..969d4c28efeef21db24fa7fe940fa037b920e807 100644 (file)
@@ -472,7 +472,7 @@ virExecCommon(virCommand *cmd, gid_t *groups, int ngroups)
     return 0;
 }
 
-# ifdef __linux__
+# if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
 static int
 virCommandMassCloseGetFDsDir(virBitmap *fds,
                              const char *dirName)
@@ -502,7 +502,7 @@ virCommandMassCloseGetFDsDir(virBitmap *fds,
 
     return 0;
 }
-# endif /* __linux__ */
+# endif /* defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) */
 
 static int
 virCommandMassCloseGetFDs(virBitmap *fds)
@@ -513,6 +513,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;