From: Michal Privoznik Date: Tue, 29 Aug 2023 06:49:27 +0000 (+0200) Subject: vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=308ec0fb2c77f4867179f00c628f05d1d784f370;p=libvirt.git vircommand: Parse /dev/fd on *BSD-like systems when looking for opened FDs 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 Reviewed-by: Martin Kletzander --- diff --git a/src/util/vircommand.c b/src/util/vircommand.c index ea52acfbb8..969d4c28ef 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -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;