From 7980f1359dd16e8ded20a80e934deaf269d85f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Mon, 29 Jun 2015 23:39:44 +0200 Subject: [PATCH] darwin: save a fd when FSEvents is used Refs: https://github.com/libuv/libuv/issues/387 PR-URL: https://github.com/libuv/libuv/pull/413 Reviewed-By: Fedor Indutny --- src/unix/kqueue.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index 424236a6ef5..495f20d285f 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -379,6 +379,10 @@ int uv_fs_event_start(uv_fs_event_t* handle, if (!(statbuf.st_mode & S_IFDIR)) goto fallback; + /* The fallback fd is no longer needed */ + uv__close(fd); + handle->event_watcher.fd = -1; + return uv__fsevents_init(handle); fallback: @@ -406,8 +410,12 @@ int uv_fs_event_stop(uv_fs_event_t* handle) { uv__free(handle->path); handle->path = NULL; - uv__close(handle->event_watcher.fd); - handle->event_watcher.fd = -1; + if (handle->event_watcher.fd != -1) { + /* When FSEvents is used, we don't use the event_watcher's fd under certain + * confitions. (see uv_fs_event_start) */ + uv__close(handle->event_watcher.fd); + handle->event_watcher.fd = -1; + } return 0; }