xf86-video-intel: src/intel_device.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Jun 27 13:43:21 PDT 2013


 src/intel_device.c |   26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

New commits:
commit 48b5ac11a0737f65de2e6290308bd37017cc29a9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jun 27 21:39:30 2013 +0100

    intel: Use fcntl to try and set CLOEXEC if the open(O_CLOEXEC) fails
    
    As suggested by Arkadiusz Miskiewicz.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/intel_device.c b/src/intel_device.c
index e1e79a0..5c49db0 100644
--- a/src/intel_device.c
+++ b/src/intel_device.c
@@ -62,6 +62,24 @@ static inline void intel_set_device(ScrnInfoPtr scrn, struct intel_device *dev)
 	xf86GetEntityPrivate(scrn->entityList[0], intel_device_key)->ptr = dev;
 }
 
+static int fd_set_cloexec(int fd)
+{
+	int flags;
+
+	if (fd == -1)
+		return fd;
+
+#ifdef FD_CLOEXEC
+	flags = fcntl(fd, F_GETFD);
+	if (flags != -1) {
+		flags |= FD_CLOEXEC;
+		fcntl(fd, F_SETFD, flags);
+	}
+#endif
+
+	return fd;
+}
+
 static int __intel_open_device(const struct pci_device *pci, const char *path)
 {
 	int fd;
@@ -86,13 +104,13 @@ static int __intel_open_device(const struct pci_device *pci, const char *path)
 
 		fd = drmOpen(NULL, id);
 	} else {
-		fd = open(path, O_RDWR |
 #ifdef O_CLOEXEC
-			  O_CLOEXEC |
+		fd = open(path, O_RDWR | O_CLOEXEC);
+#else
+		fd = -1;
 #endif
-			  0);
 		if (fd == -1)
-			fd = open(path, O_RDWR);
+			fd = fd_set_cloexec(open(path, O_RDWR));
 	}
 
 	return fd;


More information about the xorg-commit mailing list