summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-06-27 21:39:30 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-06-27 21:42:13 +0100
commit48b5ac11a0737f65de2e6290308bd37017cc29a9 (patch)
treec2eec1bf0a7ab0cbf66d39822d5b886742d04fd1
parent9b3e5c211451ac07bd96cd997ac714bcbe1809b0 (diff)
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@chris-wilson.co.uk>
-rw-r--r--src/intel_device.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/intel_device.c b/src/intel_device.c
index e1e79a00..5c49db03 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;