]> xenbits.xensource.com Git - libvirt.git/commitdiff
src: conditionalize use of F_DUPFD_CLOEXEC
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 22 Jan 2020 11:45:55 +0000 (11:45 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 29 Jan 2020 14:51:40 +0000 (14:51 +0000)
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.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/rpc/virnetsocket.c

index b25c57d01e68b9596ad30b1ebc493b0ee4460d6c..a286f0ce02ff427565ae729043f7298f98a1eafc 100644 (file)
@@ -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;
 }