summaryrefslogtreecommitdiff
path: root/bus/dir-watch-kqueue.c
diff options
context:
space:
mode:
authorPatrick Welche <prlw1@cam.ac.uk>2014-06-06 14:03:39 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-06-11 11:56:25 +0100
commit5d91f615d18629eaac074fbde2ee7e17b82e5472 (patch)
treef1dfa7bbc819c470c21849e10f6dca253b4373bd /bus/dir-watch-kqueue.c
parentd002a430cc84ff4a45589d7955ab2f9382f02745 (diff)
downloaddbus-5d91f615d18629eaac074fbde2ee7e17b82e5472.tar.gz
bus_set_watched_dirs: portability patch for systems which lack O_CLOEXEC
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77032 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Diffstat (limited to 'bus/dir-watch-kqueue.c')
-rw-r--r--bus/dir-watch-kqueue.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c
index 33d5e95d..c05a5997 100644
--- a/bus/dir-watch-kqueue.c
+++ b/bus/dir-watch-kqueue.c
@@ -202,6 +202,9 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
DBusList *link;
int i, j, fd;
struct kevent ev;
+#ifdef O_CLOEXEC
+ dbus_bool_t cloexec_done = 0;
+#endif
if (!_init_kqueue (context))
goto out;
@@ -259,7 +262,15 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
/* FIXME - less lame error handling for failing to add a watch;
* we may need to sleep.
*/
+#ifdef O_CLOEXEC
fd = open (new_dirs[i], O_RDONLY | O_CLOEXEC);
+ cloexec_done = (fd >= 0);
+
+ if (fd < 0 && errno == EINVAL)
+#endif
+ {
+ fd = open (new_dirs[i], O_RDONLY);
+ }
if (fd < 0)
{
if (errno != ENOENT)
@@ -274,6 +285,12 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
continue;
}
}
+#ifdef O_CLOEXEC
+ if (!cloexec_done)
+#endif
+ {
+ _dbus_fd_set_close_on_exec (fd);
+ }
EV_SET (&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_RENAME, 0, 0);