[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gfile-based file notifications are not immediate

From: Wolfgang Jenkner
Subject: Re: gfile-based file notifications are not immediate
Date: Thu, 30 Oct 2014 20:12:54 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (berkeley-unix)

On Wed, Oct 29 2014, Wolfgang Jenkner wrote:

> There's an active project to implement inotify for *BSD
> https://github.com/dmatveev/libinotify-kqueue

Below is an updated patch for using this library.

I tried it on FreeBSD 10-STABLE by configuring emacs (trunk HEAD at
c0696d2) like this

./configure --with-x-toolkit=no --without-gsettings --without-rsvg 

(which on my system is enough to make sure that emacs is not linked with

Previously, I had installed libinotify from the current HEAD on the
master branch (by adapting the existing devel/libinotify port, see

After building emacs, I found that "gmake check" barfed, so I just
loaded test/automated/inotify-test.el and
test/automated/file-notify-tests.el and used ert-run-tests-interactively
to run the tests in those files.

All those test succeeded with `Ran 1 tests, 1 results were as expected'
except that the first test for remote files gave `Ran 1 tests, 0 results
were as expected, 1 skipped', so I didn't try the rest of them.

I can also replicate the behaviour Dima described in bug#18880.

I've also randomly played with file notifications and so far there were
no adverse effects on this emacs instance in which I am writing this.

There are two patches here:

The first patch is meant for FreeBSD (and, perhaps, DFly) people who
want to build the current libinotify from ports (and it has to be
applied in the devel/libinotify subdirectory of the ports tree).

The second patch is for emacs.  As I said in the previous mail, it
contains a more or less bogus work-around for the currently missing

--8<---------------cut here---------------start------------->8---
Index: Makefile
--- Makefile    (revision 371635)
+++ Makefile    (working copy)
@@ -13,7 +13,8 @@
 USE_GITHUB=    yes
 GH_ACCOUNT=    dmatveev
 GH_PROJECT=    libinotify-kqueue
-GH_COMMIT=     d775062
+#GH_COMMIT=    d775062
+GH_COMMIT=     953b095
Index: distinfo
--- distinfo    (revision 371635)
+++ distinfo    (working copy)
@@ -1,2 +1,2 @@
-SHA256 (libinotify-20140622.tar.gz) = 
-SIZE (libinotify-20140622.tar.gz) = 33447
+SHA256 (libinotify-20140622.tar.gz) = 
+SIZE (libinotify-20140622.tar.gz) = 34586
--8<---------------cut here---------------end--------------->8---

--8<---------------cut here---------------start------------->8---
Subject: [PATCH] Tentative libinotify support.

 configure.ac    | 20 ++++++++++++++------
 src/Makefile.in |  4 +++-
 src/inotify.c   |  7 +++++++
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index cb42ed6..1665440 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2620,19 +2620,27 @@ case $with_file_notification,$NOTIFY_OBJ in
     fi ;;
-dnl inotify is only available on GNU/Linux.
+dnl inotify is available on GNU/Linux or, through libinotify, on *BSD.
 case $with_file_notification,$NOTIFY_OBJ in
   inotify, | yes,)
     if test "$ac_cv_header_sys_inotify_h" = yes ; then
-       AC_CHECK_FUNC(inotify_init1)
-       if test "$ac_cv_func_inotify_init1" = yes; then
-         AC_DEFINE(HAVE_INOTIFY, 1, [Define to 1 to use inotify.])
-         NOTIFY_OBJ=inotify.o
-         NOTIFY_SUMMARY="yes -lglibc (inotify)"
+       AC_SEARCH_LIBS(inotify_init, inotify)
+       if test "$ac_cv_search_inotify_init" != no; then
+         AC_CHECK_FUNCS(inotify_init1 inotify_init)
+         if test "$ac_cv_func_inotify_init" = yes; then
+            AC_DEFINE(HAVE_INOTIFY, 1, [Define to 1 to use inotify.])
+            NOTIFY_OBJ=inotify.o
+            if test "$ac_cv_search_inotify_init" != "none required"; then
+               LIB_INOTIFY="$ac_cv_search_inotify_init"
+            fi
+            NOTIFY_SUMMARY="yes $LIB_INOTIFY (inotify)"
+         fi
     fi ;;
 case $with_file_notification,$NOTIFY_OBJ in
   yes,* | no,* | *,?*) ;;
diff --git a/src/Makefile.in b/src/Makefile.in
index 270119e..34db667 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -153,6 +153,8 @@ DBUS_OBJ = @DBUS_OBJ@
@@ -429,7 +431,7 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) 
 all: emacs$(EXEEXT) $(OTHER_FILES)
 .PHONY: all
diff --git a/src/inotify.c b/src/inotify.c
index c55b130..e321a6d 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -333,7 +333,14 @@ is managed internally and there is no corresponding 
inotify_init.  Use
   if (inotifyfd < 0)
       inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC);
+#else /* I have no idea what I'm doing here. */
+      inotifyfd = inotify_init ();
+#include <fcntl.h>
+      fcntl (inotifyfd, F_SETFL, O_NONBLOCK);
+      fcntl (inotifyfd, F_SETFD, FD_CLOEXEC);
       if (inotifyfd < 0)

--8<---------------cut here---------------end--------------->8---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]