[libvirt PATCH v2 25/56] src: conditionalize use of F_DUPFD_CLOEXEC

Daniel P. Berrangé posted 56 patches 6 years ago
There is a newer version of this series
[libvirt PATCH v2 25/56] src: conditionalize use of F_DUPFD_CLOEXEC
Posted by Daniel P. Berrangé 6 years ago
The F_DUPFD_CLOEXEC functionality is not available on
some platformms. We must thus explicitly call the
virSetCloexec function once we remove GNULIB's equiv
fix for this.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/rpc/virnetsocket.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index b25c57d01e..a286f0ce02 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -1397,15 +1397,27 @@ int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec)
 {
     int fd;
 
+#ifdef F_DUPFD_CLOEXEC
     if (cloexec)
         fd = fcntl(sock->fd, F_DUPFD_CLOEXEC, 0);
     else
+#endif /* F_DUPFD_CLOEXEC */
         fd = dup(sock->fd);
     if (fd < 0) {
         virReportSystemError(errno, "%s",
                              _("Unable to copy socket file handle"));
         return -1;
     }
+#ifndef F_DUPFD_CLOEXEC
+    if (cloexec &&
+        virSetCloseExec(fd < 0)) {
+        int saveerr = errno;
+        closesocket(fd);
+        errno = saveerr;
+        return -1;
+    }
+#endif /* F_DUPFD_CLOEXEC */
+
     return fd;
 }
 
-- 
2.24.1

Re: [libvirt PATCH v2 25/56] src: conditionalize use of F_DUPFD_CLOEXEC
Posted by Pavel Hrdina 6 years ago
On Tue, Jan 28, 2020 at 01:11:06PM +0000, Daniel P. Berrangé wrote:
> The F_DUPFD_CLOEXEC functionality is not available on
> some platformms. We must thus explicitly call the
> virSetCloexec function once we remove GNULIB's equiv
> fix for this.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/rpc/virnetsocket.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>