emacs-diffs
[Top][All Lists]
Advanced

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

master 39a84232700: Enable inotify on systems with inotify_init yet no i


From: Po Lu
Subject: master 39a84232700: Enable inotify on systems with inotify_init yet no init1 variant
Date: Wed, 21 Feb 2024 20:54:47 -0500 (EST)

branch: master
commit 39a84232700c40fa74305970dd16cd5cb8b8bea0
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Enable inotify on systems with inotify_init yet no init1 variant
    
    * configure.ac (HAVE_INOTIFY): Check for the presence of
    inotify_init in addition to inotify_init1.
    
    * src/inotify.c (Finotify_add_watch): Implement with
    inotify_init if inotify_init1 is absent.
---
 configure.ac  |  8 ++++----
 src/inotify.c | 10 ++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 847fdbd54d2..71a899f5f40 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4088,16 +4088,16 @@ case $with_file_notification,$opsys in
     fi ;;
 esac
 
-dnl inotify is available only on GNU/Linux.
+dnl inotify is available only on Linux-kernel based systems.
 case $with_file_notification,$NOTIFY_OBJ in
   inotify, | yes,)
     AC_CHECK_HEADER([sys/inotify.h])
     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_CHECK_FUNCS([inotify_init inotify_init1])
+       if test "$ac_cv_func_inotify_init" = yes; then
          AC_DEFINE([HAVE_INOTIFY], [1], [Define to 1 to use inotify.])
          NOTIFY_OBJ=inotify.o
-         NOTIFY_SUMMARY="yes -lglibc (inotify)"
+         NOTIFY_SUMMARY="yes (inotify)"
        fi
     fi ;;
 esac
diff --git a/src/inotify.c b/src/inotify.c
index 2ee874530cc..7140568f1b6 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -26,6 +26,8 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "termhooks.h"
 
 #include <errno.h>
+#include <fcntl.h>
+
 #include <sys/inotify.h>
 #include <sys/ioctl.h>
 
@@ -434,7 +436,15 @@ IN_ONESHOT  */)
 
   if (inotifyfd < 0)
     {
+#ifdef HAVE_INOTIFY_INIT1
       inotifyfd = inotify_init1 (IN_NONBLOCK | IN_CLOEXEC);
+#else /* !HAVE_INOTIFY_INIT1 */
+      /* This is prey to race conditions with other threads calling
+        exec.  */
+      inotifyfd = inotify_init ();
+      fcntl (inotifyfd, F_SETFL, O_NONBLOCK);
+      fcntl (inotifyfd, F_SETFD, O_CLOEXEC);
+#endif /* HAVE_INOTIFY_INIT1 */
       if (inotifyfd < 0)
        report_file_notify_error ("File watching is not available", Qnil);
       watch_list = Qnil;



reply via email to

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